-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
239 additions
and
17 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
CleanApp/Modules/DomainLayer/.swiftpm/xcode/xcshareddata/xcschemes/DomainLayer.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1400" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "DomainLayer" | ||
BuildableName = "DomainLayer" | ||
BlueprintName = "DomainLayer" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
codeCoverageEnabled = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "DomainLayerTests" | ||
BuildableName = "DomainLayerTests" | ||
BlueprintName = "DomainLayerTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "DomainLayer" | ||
BuildableName = "DomainLayer" | ||
BlueprintName = "DomainLayer" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Todo.swift | ||
// DomainLayer | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct Todo: Equatable { | ||
public var id: Int? | ||
public var title: String | ||
public var completed: Bool | ||
|
||
public init(id: Int? = nil, title: String, completed: Bool = false) { | ||
self.id = id | ||
self.title = title | ||
self.completed = completed | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
CleanApp/Modules/DomainLayer/Sources/Protocols/Repositories/TodoRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// TodoRepository.swift | ||
// DomainLayer | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol TodoRepository { | ||
func todos() async -> Result<[Todo], Error> | ||
func complete(id: Int) async -> Result<Todo, Error> | ||
} |
20 changes: 20 additions & 0 deletions
20
CleanApp/Modules/DomainLayer/Sources/UseCases/CompleteTodoUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// CompleteTodoUseCase.swift | ||
// DomainLayer | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import Foundation | ||
|
||
public class CompleteTodoUseCase { | ||
private let repository: TodoRepository | ||
|
||
public init(repository: TodoRepository) { | ||
self.repository = repository | ||
} | ||
|
||
public func execute(id: Int) async -> Result<Todo, Error> { | ||
await repository.complete(id: id) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
CleanApp/Modules/DomainLayer/Sources/UseCases/GetAllTodosUseCase.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// GetAllTodosUseCase.swift | ||
// DomainLayer | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import Foundation | ||
|
||
public class GetAllTodosUseCase { | ||
private let repository: TodoRepository | ||
|
||
public init(repository: TodoRepository) { | ||
self.repository = repository | ||
} | ||
|
||
public func execute() async -> Result<[Todo], Error> { | ||
await repository.todos() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
CleanApp/Modules/DomainLayer/Tests/Mocks/Entities/Todo+Mock.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Todo+Mock.swift | ||
// DomainLayerTests | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import DomainLayer | ||
import Foundation | ||
|
||
private var todos = [Todo]() | ||
|
||
extension Todo { | ||
static func mock() -> Todo { | ||
let id = todos.count + 1 | ||
return .init(id: id, title: "Mock #\(id)") | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
CleanApp/Modules/DomainLayer/Tests/Mocks/Repositories/MockTodayRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// MockTodoRepository.swift | ||
// DomainLayerTests | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import Foundation | ||
import DomainLayer | ||
|
||
struct MockTodoRepository: TodoRepository { | ||
var todosResult: Result<[Todo], Error>! | ||
var completeResult: Result<Todo, Error>! | ||
|
||
func todos() async -> Result<[Todo], Error> { | ||
todosResult | ||
} | ||
|
||
func complete(id: Int) async -> Result<Todo, Error> { | ||
completeResult | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
CleanApp/Modules/DomainLayer/Tests/UseCases/GetAllTodosUseCaseTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// GetAllTodosUseCaseTests.swift | ||
// DomainLayerTests | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import DomainLayer | ||
import XCTest | ||
|
||
final class GetAllTodosUseCaseTests: XCTestCase { | ||
func testExecute() async throws { | ||
// Arrange | ||
let expected = [Todo.mock()] | ||
let repository = MockTodoRepository(todosResult: .success(expected)) | ||
let sut = GetAllTodosUseCase(repository: repository) | ||
|
||
// Act | ||
let result = try await sut.execute().get() | ||
|
||
// Assert | ||
XCTAssertEqual(result, expected) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
CleanApp/Modules/DomainLayer/Tests/UseCases/GetTodayUseCaseTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// CompleteTodoUseCaseTests.swift | ||
// DomainLayerTests | ||
// | ||
// Created by Miguel Dönicke on 08.10.22. | ||
// | ||
|
||
import DomainLayer | ||
import XCTest | ||
|
||
final class CompleteTodoUseCaseTests: XCTestCase { | ||
func testExecute() async throws { | ||
// Arrange | ||
let expected = Todo.mock() | ||
let repository = MockTodoRepository(completeResult: .success(expected)) | ||
let sut = CompleteTodoUseCase(repository: repository) | ||
|
||
// Act | ||
let result = try await sut.execute(id: expected.id!).get() | ||
|
||
// Assert | ||
XCTAssertEqual(result, expected) | ||
} | ||
} |