Implemented the APIServiceKey dependency key and integrated it to the DependencyStore in the DependencyStore+Keys extension.

This commit is contained in:
Javier Cicchelli 2022-12-11 19:57:13 +01:00
parent cd4147ba75
commit e1eb8435bc
5 changed files with 101 additions and 9 deletions

View File

@ -53,6 +53,18 @@
ReferencedContainer = "container:"> ReferencedContainer = "container:">
</BuildableReference> </BuildableReference>
</TestableReference> </TestableReference>
<TestableReference
skipped = "NO"
parallelizable = "YES"
testExecutionOrdering = "random">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DependenciesTests"
BuildableName = "DependenciesTests"
BlueprintName = "DependenciesTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables> </Testables>
</TestAction> </TestAction>
<LaunchAction <LaunchAction

View File

@ -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 }
}
}

View 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()
}

View File

@ -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
}

View File

@ -14,13 +14,15 @@ final class KeychainStorageInitTests: XCTestCase {
// MARK: Properties // MARK: Properties
private var keychainStorage: TestKeychyainStorage!
private var value: TestModel? private var value: TestModel?
// MARK: Test cases // MARK: Test cases
func testValue_whenNoDefaultValue_andEmptyStorage() throws { func testValue_whenNoDefaultValue_andEmptyStorage() throws {
// GIVEN // GIVEN
let keychainStorage = TestKeychainStorage_withNoDefaultValue_andEmptyStorage() keychainStorage = TestKeychainStorage_withNoDefaultValue_andEmptyStorage()
// WHEN // WHEN
value = keychainStorage.keychainValue value = keychainStorage.keychainValue
@ -31,7 +33,7 @@ final class KeychainStorageInitTests: XCTestCase {
func testValue_whenDefaultValue_andEmptyStorage() throws { func testValue_whenDefaultValue_andEmptyStorage() throws {
// GIVEN // GIVEN
let keychainStorage = TestKeychainStorage_withDefaultValue_andEmptyStorage() keychainStorage = TestKeychainStorage_withDefaultValue_andEmptyStorage()
// WHEN // WHEN
value = keychainStorage.keychainValue value = keychainStorage.keychainValue
@ -42,7 +44,7 @@ final class KeychainStorageInitTests: XCTestCase {
func testValue_whenNoDefaultValue_andValueInStorage() throws { func testValue_whenNoDefaultValue_andValueInStorage() throws {
// GIVEN // GIVEN
let keychainStorage = TestKeychainStorage_withNoDefaultValue_andValueInStorage() keychainStorage = TestKeychainStorage_withNoDefaultValue_andValueInStorage()
// WHEN // WHEN
value = keychainStorage.keychainValue value = keychainStorage.keychainValue
@ -53,7 +55,7 @@ final class KeychainStorageInitTests: XCTestCase {
func testValue_whenNoDefaultValue_andNoValueInStorage() throws { func testValue_whenNoDefaultValue_andNoValueInStorage() throws {
// GIVEN // GIVEN
let keychainStorage = TestKeychainStorage_withNoDefaultValue_andNoValueInStorage() keychainStorage = TestKeychainStorage_withNoDefaultValue_andNoValueInStorage()
// WHEN // WHEN
value = keychainStorage.keychainValue 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( @KeychainStorage(
key: .Keys.someKey, key: .Keys.someKey,
keychain: KeychainStorageMock() 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( @KeychainStorage(
key: .Keys.someKey, key: .Keys.someKey,
defaultValue: TestModel(), defaultValue: TestModel(),
@ -84,7 +92,7 @@ private final class TestKeychainStorage_withDefaultValue_andEmptyStorage {
var keychainValue: TestModel? var keychainValue: TestModel?
} }
private final class TestKeychainStorage_withNoDefaultValue_andValueInStorage { private struct TestKeychainStorage_withNoDefaultValue_andValueInStorage: TestKeychyainStorage {
@KeychainStorage( @KeychainStorage(
key: .Keys.someKey, key: .Keys.someKey,
keychain: KeychainStorageMock(storage: [ keychain: KeychainStorageMock(storage: [
@ -94,7 +102,7 @@ private final class TestKeychainStorage_withNoDefaultValue_andValueInStorage {
var keychainValue: TestModel? var keychainValue: TestModel?
} }
private final class TestKeychainStorage_withNoDefaultValue_andNoValueInStorage { private struct TestKeychainStorage_withNoDefaultValue_andNoValueInStorage: TestKeychyainStorage {
@KeychainStorage( @KeychainStorage(
key: .Keys.someKey, key: .Keys.someKey,
keychain: KeychainStorageMock(storage: [ keychain: KeychainStorageMock(storage: [