Merge pull request #9 from rock-n-code/feature/dependencies
Feature: Dependencies
This commit is contained in:
commit
7b191f4c39
@ -1,6 +1,6 @@
|
||||
//
|
||||
// Dependency.swift
|
||||
// DependencyService
|
||||
// DependencyInjection
|
||||
//
|
||||
// Created by Javier Cicchelli on 05/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// DependencyKey.swift
|
||||
// DependencyService
|
||||
// DependencyInjection
|
||||
//
|
||||
// Created by Javier Cicchelli on 05/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// DependencyStore.swift
|
||||
// DependencyService
|
||||
// DependencyInjection
|
||||
//
|
||||
// Created by Javier Cicchelli on 05/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
|
@ -53,6 +53,18 @@
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
<TestableReference
|
||||
skipped = "NO"
|
||||
parallelizable = "YES"
|
||||
testExecutionOrdering = "random">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "DependenciesTests"
|
||||
BuildableName = "DependenciesTests"
|
||||
BlueprintName = "DependenciesTests"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
|
@ -15,6 +15,7 @@ let package = Package(
|
||||
),
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../Cores"),
|
||||
.package(
|
||||
url: "https://github.com/kishikawakatsumi/KeychainAccess.git",
|
||||
from: "4.0.0"
|
||||
@ -22,6 +23,13 @@ let package = Package(
|
||||
],
|
||||
targets: [
|
||||
.target(name: "APIService"),
|
||||
.target(
|
||||
name: "Dependencies",
|
||||
dependencies: [
|
||||
"Cores",
|
||||
"APIService"
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "KeychainStorage",
|
||||
dependencies: [
|
||||
@ -32,6 +40,10 @@ let package = Package(
|
||||
name: "APIServiceTests",
|
||||
dependencies: ["APIService"]
|
||||
),
|
||||
.testTarget(
|
||||
name: "DependenciesTests",
|
||||
dependencies: ["Dependencies"]
|
||||
),
|
||||
.testTarget(
|
||||
name: "KeychainStorageTests",
|
||||
dependencies: ["KeychainStorage"]
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// DependencyStore+Keys.swift
|
||||
// Dependencies
|
||||
//
|
||||
// Created by Javier Cicchelli on 11/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import APIService
|
||||
import DependencyInjection
|
||||
|
||||
public extension DependencyStore {
|
||||
var apiService: APIService {
|
||||
get { Self[APIServiceKey.self] }
|
||||
set { Self[APIServiceKey.self] = newValue }
|
||||
}
|
||||
}
|
14
Libraries/Sources/Dependencies/Keys/APIServiceKey.swift
Normal file
14
Libraries/Sources/Dependencies/Keys/APIServiceKey.swift
Normal file
@ -0,0 +1,14 @@
|
||||
//
|
||||
// APIServiceKey.swift
|
||||
// Dependencies
|
||||
//
|
||||
// Created by Javier Cicchelli on 11/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import APIService
|
||||
import DependencyInjection
|
||||
|
||||
struct APIServiceKey: DependencyKey {
|
||||
static var currentValue = APIService()
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
//
|
||||
// Dependencies+APIServiceTests.swift
|
||||
// DependenciesTests
|
||||
//
|
||||
// Created by Javier Cicchelli on 11/12/2022.
|
||||
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import APIService
|
||||
import DependencyInjection
|
||||
import Dependencies
|
||||
import XCTest
|
||||
|
||||
final class DependenciesAPIServiceTests: XCTestCase {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private var testDependency: DependencyTest!
|
||||
|
||||
private var apiService: APIService!
|
||||
|
||||
// MARK: Test cases
|
||||
|
||||
func test_apiService() throws {
|
||||
// GIVEN
|
||||
testDependency = .init()
|
||||
|
||||
// WHEN
|
||||
apiService = testDependency.apiService
|
||||
|
||||
// THEN
|
||||
XCTAssertNotNil(apiService)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Test structs
|
||||
|
||||
private struct DependencyTest {
|
||||
@Dependency(\.apiService) var apiService
|
||||
}
|
@ -14,13 +14,15 @@ final class KeychainStorageInitTests: XCTestCase {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private var keychainStorage: TestKeychyainStorage!
|
||||
|
||||
private var value: TestModel?
|
||||
|
||||
// MARK: Test cases
|
||||
|
||||
func testValue_whenNoDefaultValue_andEmptyStorage() throws {
|
||||
// GIVEN
|
||||
let keychainStorage = TestKeychainStorage_withNoDefaultValue_andEmptyStorage()
|
||||
keychainStorage = TestKeychainStorage_withNoDefaultValue_andEmptyStorage()
|
||||
|
||||
// WHEN
|
||||
value = keychainStorage.keychainValue
|
||||
@ -31,7 +33,7 @@ final class KeychainStorageInitTests: XCTestCase {
|
||||
|
||||
func testValue_whenDefaultValue_andEmptyStorage() throws {
|
||||
// GIVEN
|
||||
let keychainStorage = TestKeychainStorage_withDefaultValue_andEmptyStorage()
|
||||
keychainStorage = TestKeychainStorage_withDefaultValue_andEmptyStorage()
|
||||
|
||||
// WHEN
|
||||
value = keychainStorage.keychainValue
|
||||
@ -42,7 +44,7 @@ final class KeychainStorageInitTests: XCTestCase {
|
||||
|
||||
func testValue_whenNoDefaultValue_andValueInStorage() throws {
|
||||
// GIVEN
|
||||
let keychainStorage = TestKeychainStorage_withNoDefaultValue_andValueInStorage()
|
||||
keychainStorage = TestKeychainStorage_withNoDefaultValue_andValueInStorage()
|
||||
|
||||
// WHEN
|
||||
value = keychainStorage.keychainValue
|
||||
@ -53,7 +55,7 @@ final class KeychainStorageInitTests: XCTestCase {
|
||||
|
||||
func testValue_whenNoDefaultValue_andNoValueInStorage() throws {
|
||||
// GIVEN
|
||||
let keychainStorage = TestKeychainStorage_withNoDefaultValue_andNoValueInStorage()
|
||||
keychainStorage = TestKeychainStorage_withNoDefaultValue_andNoValueInStorage()
|
||||
|
||||
// WHEN
|
||||
value = keychainStorage.keychainValue
|
||||
@ -64,9 +66,15 @@ final class KeychainStorageInitTests: XCTestCase {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Test classes
|
||||
// MARK: - Test protocols
|
||||
|
||||
private final class TestKeychainStorage_withNoDefaultValue_andEmptyStorage {
|
||||
private protocol TestKeychyainStorage {
|
||||
var keychainValue: TestModel? { get set }
|
||||
}
|
||||
|
||||
// MARK: - Test structs
|
||||
|
||||
private struct TestKeychainStorage_withNoDefaultValue_andEmptyStorage: TestKeychyainStorage {
|
||||
@KeychainStorage(
|
||||
key: .Keys.someKey,
|
||||
keychain: KeychainStorageMock()
|
||||
@ -75,7 +83,7 @@ private final class TestKeychainStorage_withNoDefaultValue_andEmptyStorage {
|
||||
}
|
||||
|
||||
|
||||
private final class TestKeychainStorage_withDefaultValue_andEmptyStorage {
|
||||
private struct TestKeychainStorage_withDefaultValue_andEmptyStorage: TestKeychyainStorage {
|
||||
@KeychainStorage(
|
||||
key: .Keys.someKey,
|
||||
defaultValue: TestModel(),
|
||||
@ -84,7 +92,7 @@ private final class TestKeychainStorage_withDefaultValue_andEmptyStorage {
|
||||
var keychainValue: TestModel?
|
||||
}
|
||||
|
||||
private final class TestKeychainStorage_withNoDefaultValue_andValueInStorage {
|
||||
private struct TestKeychainStorage_withNoDefaultValue_andValueInStorage: TestKeychyainStorage {
|
||||
@KeychainStorage(
|
||||
key: .Keys.someKey,
|
||||
keychain: KeychainStorageMock(storage: [
|
||||
@ -94,7 +102,7 @@ private final class TestKeychainStorage_withNoDefaultValue_andValueInStorage {
|
||||
var keychainValue: TestModel?
|
||||
}
|
||||
|
||||
private final class TestKeychainStorage_withNoDefaultValue_andNoValueInStorage {
|
||||
private struct TestKeychainStorage_withNoDefaultValue_andNoValueInStorage: TestKeychyainStorage {
|
||||
@KeychainStorage(
|
||||
key: .Keys.someKey,
|
||||
keychain: KeychainStorageMock(storage: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user