Skip to content

Commit

Permalink
Add demo use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Haitec committed Oct 8, 2022
1 parent 6f2596d commit 2c85c96
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 17 deletions.
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>
6 changes: 0 additions & 6 deletions CleanApp/Modules/DomainLayer/Sources/DomainLayer.swift

This file was deleted.

20 changes: 20 additions & 0 deletions CleanApp/Modules/DomainLayer/Sources/Entities/Todo.swift
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
}
}
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>
}
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)
}
}
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()
}
}
11 changes: 0 additions & 11 deletions CleanApp/Modules/DomainLayer/Tests/DomainTests.swift

This file was deleted.

18 changes: 18 additions & 0 deletions CleanApp/Modules/DomainLayer/Tests/Mocks/Entities/Todo+Mock.swift
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)")
}
}
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
}
}
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)
}
}
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)
}
}

0 comments on commit 2c85c96

Please sign in to comment.