added dependency injection and functional testing

pull/7/head
Emre KARTAL 2 years ago
parent ca1f4a9814
commit 236e4d0a88

@ -28,6 +28,8 @@
EC4163512AE126B3001E620D /* DropDownMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC4163502AE126B3001E620D /* DropDownMenuView.swift */; }; EC4163512AE126B3001E620D /* DropDownMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC4163502AE126B3001E620D /* DropDownMenuView.swift */; };
EC46D7DD2ABCCC270030AC04 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC46D7DC2ABCCC270030AC04 /* MenuView.swift */; }; EC46D7DD2ABCCC270030AC04 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC46D7DC2ABCCC270030AC04 /* MenuView.swift */; };
EC46D7DF2ABCE0A20030AC04 /* ParameterMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC46D7DE2ABCE0A20030AC04 /* ParameterMenuView.swift */; }; EC46D7DF2ABCE0A20030AC04 /* ParameterMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC46D7DE2ABCE0A20030AC04 /* ParameterMenuView.swift */; };
EC508A9F2AED3C2A000FA2FB /* DependencyInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC508A9E2AED3C2A000FA2FB /* DependencyInjection.swift */; };
EC508AA12AED3D89000FA2FB /* IAuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC508AA02AED3D89000FA2FB /* IAuthService.swift */; };
EC50BF962ABF4D3300197685 /* SplashScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC50BF952ABF4D3300197685 /* SplashScreen.swift */; }; EC50BF962ABF4D3300197685 /* SplashScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC50BF952ABF4D3300197685 /* SplashScreen.swift */; };
EC50BF982ABF541B00197685 /* WelcomeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC50BF972ABF541B00197685 /* WelcomeScreen.swift */; }; EC50BF982ABF541B00197685 /* WelcomeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC50BF972ABF541B00197685 /* WelcomeScreen.swift */; };
EC55565D2AD6E5B900E5CA3F /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC55565C2AD6E5B900E5CA3F /* AuthService.swift */; }; EC55565D2AD6E5B900E5CA3F /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC55565C2AD6E5B900E5CA3F /* AuthService.swift */; };
@ -40,7 +42,6 @@
ECA7010B2AC4003400532444 /* RankingRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA7010A2AC4003400532444 /* RankingRowView.swift */; }; ECA7010B2AC4003400532444 /* RankingRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA7010A2AC4003400532444 /* RankingRowView.swift */; };
ECA7010D2AC4948600532444 /* FriendsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA7010C2AC4948600532444 /* FriendsScreen.swift */; }; ECA7010D2AC4948600532444 /* FriendsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA7010C2AC4948600532444 /* FriendsScreen.swift */; };
ECA7010F2AC4949D00532444 /* FriendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA7010E2AC4949D00532444 /* FriendView.swift */; }; ECA7010F2AC4949D00532444 /* FriendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA7010E2AC4949D00532444 /* FriendView.swift */; };
ECCD6DD92AD7228B00F947C4 /* Singleton.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECCD6DD82AD7228B00F947C4 /* Singleton.swift */; };
ECCD6DDB2AD7233F00F947C4 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECCD6DDA2AD7233F00F947C4 /* User.swift */; }; ECCD6DDB2AD7233F00F947C4 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECCD6DDA2AD7233F00F947C4 /* User.swift */; };
ECDF624A2AC1CAFD00BA8213 /* RegisterScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECDF62492AC1CAFD00BA8213 /* RegisterScreen.swift */; }; ECDF624A2AC1CAFD00BA8213 /* RegisterScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECDF62492AC1CAFD00BA8213 /* RegisterScreen.swift */; };
ECFC54442AC0C39E00195760 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECFC54432AC0C39E00195760 /* LoginScreen.swift */; }; ECFC54442AC0C39E00195760 /* LoginScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECFC54432AC0C39E00195760 /* LoginScreen.swift */; };
@ -89,6 +90,8 @@
EC4163502AE126B3001E620D /* DropDownMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DropDownMenuView.swift; path = allin/Views/DropDownMenuView.swift; sourceTree = SOURCE_ROOT; }; EC4163502AE126B3001E620D /* DropDownMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DropDownMenuView.swift; path = allin/Views/DropDownMenuView.swift; sourceTree = SOURCE_ROOT; };
EC46D7DC2ABCCC270030AC04 /* MenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuView.swift; path = allin/Views/MenuView.swift; sourceTree = SOURCE_ROOT; }; EC46D7DC2ABCCC270030AC04 /* MenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MenuView.swift; path = allin/Views/MenuView.swift; sourceTree = SOURCE_ROOT; };
EC46D7DE2ABCE0A20030AC04 /* ParameterMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ParameterMenuView.swift; path = allin/Views/ParameterMenuView.swift; sourceTree = SOURCE_ROOT; }; EC46D7DE2ABCE0A20030AC04 /* ParameterMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ParameterMenuView.swift; path = allin/Views/ParameterMenuView.swift; sourceTree = SOURCE_ROOT; };
EC508A9E2AED3C2A000FA2FB /* DependencyInjection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DependencyInjection.swift; path = allin/Models/DependencyInjection.swift; sourceTree = SOURCE_ROOT; };
EC508AA02AED3D89000FA2FB /* IAuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = IAuthService.swift; path = allin/Services/IAuthService.swift; sourceTree = SOURCE_ROOT; };
EC50BF952ABF4D3300197685 /* SplashScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SplashScreen.swift; path = allin/Screens/SplashScreen.swift; sourceTree = SOURCE_ROOT; }; EC50BF952ABF4D3300197685 /* SplashScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SplashScreen.swift; path = allin/Screens/SplashScreen.swift; sourceTree = SOURCE_ROOT; };
EC50BF972ABF541B00197685 /* WelcomeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = WelcomeScreen.swift; path = allin/Screens/WelcomeScreen.swift; sourceTree = SOURCE_ROOT; }; EC50BF972ABF541B00197685 /* WelcomeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = WelcomeScreen.swift; path = allin/Screens/WelcomeScreen.swift; sourceTree = SOURCE_ROOT; };
EC55565C2AD6E5B900E5CA3F /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AuthService.swift; path = allin/Services/AuthService.swift; sourceTree = SOURCE_ROOT; }; EC55565C2AD6E5B900E5CA3F /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AuthService.swift; path = allin/Services/AuthService.swift; sourceTree = SOURCE_ROOT; };
@ -101,7 +104,6 @@
ECA7010A2AC4003400532444 /* RankingRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RankingRowView.swift; path = allin/Views/RankingRowView.swift; sourceTree = SOURCE_ROOT; }; ECA7010A2AC4003400532444 /* RankingRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RankingRowView.swift; path = allin/Views/RankingRowView.swift; sourceTree = SOURCE_ROOT; };
ECA7010C2AC4948600532444 /* FriendsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FriendsScreen.swift; path = allin/Screens/FriendsScreen.swift; sourceTree = SOURCE_ROOT; }; ECA7010C2AC4948600532444 /* FriendsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FriendsScreen.swift; path = allin/Screens/FriendsScreen.swift; sourceTree = SOURCE_ROOT; };
ECA7010E2AC4949D00532444 /* FriendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FriendView.swift; path = allin/Views/FriendView.swift; sourceTree = SOURCE_ROOT; }; ECA7010E2AC4949D00532444 /* FriendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FriendView.swift; path = allin/Views/FriendView.swift; sourceTree = SOURCE_ROOT; };
ECCD6DD82AD7228B00F947C4 /* Singleton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Singleton.swift; path = allin/Models/Singleton.swift; sourceTree = SOURCE_ROOT; };
ECCD6DDA2AD7233F00F947C4 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = User.swift; path = allin/Models/User.swift; sourceTree = SOURCE_ROOT; }; ECCD6DDA2AD7233F00F947C4 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = User.swift; path = allin/Models/User.swift; sourceTree = SOURCE_ROOT; };
ECDF62492AC1CAFD00BA8213 /* RegisterScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RegisterScreen.swift; path = allin/Screens/RegisterScreen.swift; sourceTree = SOURCE_ROOT; }; ECDF62492AC1CAFD00BA8213 /* RegisterScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RegisterScreen.swift; path = allin/Screens/RegisterScreen.swift; sourceTree = SOURCE_ROOT; };
ECFC54432AC0C39E00195760 /* LoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LoginScreen.swift; path = allin/Screens/LoginScreen.swift; sourceTree = SOURCE_ROOT; }; ECFC54432AC0C39E00195760 /* LoginScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LoginScreen.swift; path = allin/Screens/LoginScreen.swift; sourceTree = SOURCE_ROOT; };
@ -229,6 +231,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
EC55565C2AD6E5B900E5CA3F /* AuthService.swift */, EC55565C2AD6E5B900E5CA3F /* AuthService.swift */,
EC508AA02AED3D89000FA2FB /* IAuthService.swift */,
); );
path = Services; path = Services;
sourceTree = "<group>"; sourceTree = "<group>";
@ -261,8 +264,8 @@
ECCD6DD72AD7227500F947C4 /* Models */ = { ECCD6DD72AD7227500F947C4 /* Models */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
ECCD6DD82AD7228B00F947C4 /* Singleton.swift */,
ECCD6DDA2AD7233F00F947C4 /* User.swift */, ECCD6DDA2AD7233F00F947C4 /* User.swift */,
EC508A9E2AED3C2A000FA2FB /* DependencyInjection.swift */,
); );
path = Models; path = Models;
sourceTree = "<group>"; sourceTree = "<group>";
@ -346,6 +349,7 @@
}; };
D98C4D6F2AB9D019007A6B4D = { D98C4D6F2AB9D019007A6B4D = {
CreatedOnToolsVersion = 14.2; CreatedOnToolsVersion = 14.2;
LastSwiftMigration = 1430;
TestTargetID = D98C4D5F2AB9D017007A6B4D; TestTargetID = D98C4D5F2AB9D017007A6B4D;
}; };
D98C4D792AB9D019007A6B4D = { D98C4D792AB9D019007A6B4D = {
@ -406,6 +410,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
ECA7010B2AC4003400532444 /* RankingRowView.swift in Sources */, ECA7010B2AC4003400532444 /* RankingRowView.swift in Sources */,
EC508AA12AED3D89000FA2FB /* IAuthService.swift in Sources */,
EC31955E2ACD3B8E00D0A4DC /* ConfidentialityView.swift in Sources */, EC31955E2ACD3B8E00D0A4DC /* ConfidentialityView.swift in Sources */,
ECA701092AC3FE3300532444 /* RankingScreen.swift in Sources */, ECA701092AC3FE3300532444 /* RankingScreen.swift in Sources */,
ECFC54442AC0C39E00195760 /* LoginScreen.swift in Sources */, ECFC54442AC0C39E00195760 /* LoginScreen.swift in Sources */,
@ -420,7 +425,6 @@
EC55565D2AD6E5B900E5CA3F /* AuthService.swift in Sources */, EC55565D2AD6E5B900E5CA3F /* AuthService.swift in Sources */,
D98C4D662AB9D017007A6B4D /* ContentView.swift in Sources */, D98C4D662AB9D017007A6B4D /* ContentView.swift in Sources */,
EC4163512AE126B3001E620D /* DropDownMenuView.swift in Sources */, EC4163512AE126B3001E620D /* DropDownMenuView.swift in Sources */,
ECCD6DD92AD7228B00F947C4 /* Singleton.swift in Sources */,
D92EC57C2ABADA2800CCD30E /* CoinCounterView.swift in Sources */, D92EC57C2ABADA2800CCD30E /* CoinCounterView.swift in Sources */,
EC3737E42AC2F5FB00E6BDB5 /* ChoiceCapsule.swift in Sources */, EC3737E42AC2F5FB00E6BDB5 /* ChoiceCapsule.swift in Sources */,
EC3737E62AC41DB000E6BDB5 /* WinModal.swift in Sources */, EC3737E62AC41DB000E6BDB5 /* WinModal.swift in Sources */,
@ -437,6 +441,7 @@
EC2C1EEF2AC098D30091D57C /* UsersPreview.swift in Sources */, EC2C1EEF2AC098D30091D57C /* UsersPreview.swift in Sources */,
EC87FCDB2ABBA6AC00363986 /* TrendingBetCard.swift in Sources */, EC87FCDB2ABBA6AC00363986 /* TrendingBetCard.swift in Sources */,
EC000A7B2AC7450200A8BE26 /* CreationBetScreen.swift in Sources */, EC000A7B2AC7450200A8BE26 /* CreationBetScreen.swift in Sources */,
EC508A9F2AED3C2A000FA2FB /* DependencyInjection.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -595,7 +600,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"AllIn/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"AllIn/Preview Content\"";
DEVELOPMENT_TEAM = 35KQ5BDC64; DEVELOPMENT_TEAM = P39ZK4GA2T;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AllIn/Info.plist; INFOPLIST_FILE = AllIn/Info.plist;
@ -625,7 +630,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"AllIn/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"AllIn/Preview Content\"";
DEVELOPMENT_TEAM = 35KQ5BDC64; DEVELOPMENT_TEAM = P39ZK4GA2T;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = AllIn/Info.plist; INFOPLIST_FILE = AllIn/Info.plist;
@ -652,6 +657,7 @@
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
@ -660,6 +666,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.alldev.AllInTests; PRODUCT_BUNDLE_IDENTIFIER = com.alldev.AllInTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AllIn.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/AllIn"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AllIn.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/AllIn";
@ -671,6 +678,7 @@
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)"; BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;

@ -11,7 +11,7 @@ struct ContentView: View {
var body: some View { var body: some View {
NavigationView { NavigationView {
Home(page: "CreationBet") Welcome()
} }
} }
} }

@ -0,0 +1,52 @@
//
// DependencyInjection.swift
// AllIn
//
// Created by étudiant on 28/10/2023.
//
import Foundation
class DependencyInjection {
static var shared = DependencyInjection()
private var singletons = [String: Any]()
@discardableResult
func addSingleton<T>(_ type: T.Type, _ instance: T) -> DependencyInjection {
let key = String(describing: T.self)
singletons[key] = instance
return self
}
func resolve<T>(_ type: T.Type) -> T? {
let key = String(describing: T.self)
return singletons[key] as? T
}
}
@propertyWrapper
struct Inject<T> {
private var value: T?
init() {
self.value = DependencyInjection.shared.resolve(T.self)
}
var wrappedValue: T {
get {
if let value = value {
return value
} else {
if let resolvedValue = DependencyInjection.shared.resolve(T.self) {
return resolvedValue
} else {
fatalError("Dependency not registered in DependencyInjection.")
}
}
}
set {
value = newValue
}
}
}

@ -1,19 +0,0 @@
//
// Singleton.swift
// AllIn
//
// Created by étudiant on 11/10/2023.
//
import Foundation
class Singleton {
static let singleton = Singleton()
var user: User?
var auth: AuthService = AuthService()
private init() { }
}

@ -9,6 +9,7 @@ import SwiftUI
struct Login: View { struct Login: View {
@Inject private var authService: IAuthService
@State private var isPasswordVisible = true @State private var isPasswordVisible = true
@State private var username: String = "" @State private var username: String = ""
@State private var password: String = "" @State private var password: String = ""
@ -111,9 +112,8 @@ struct Login: View {
} }
func login(email: String, password: String) { func login(email: String, password: String) {
let api = AuthService()
api.login(email: email, password: password) { statusCode in authService.login(email: email, password: password) { statusCode in
DispatchQueue.main.async { DispatchQueue.main.async {
if statusCode == 200 { if statusCode == 200 {
isLoginSuccessful = true isLoginSuccessful = true

@ -7,7 +7,7 @@
import Foundation import Foundation
class AuthService { class AuthService: IAuthService {
let baseURL : String = "https://codefirst.iut.uca.fr/containers/AllDev-api/" let baseURL : String = "https://codefirst.iut.uca.fr/containers/AllDev-api/"

@ -0,0 +1,13 @@
//
// IAuthService.swift
// AllIn
//
// Created by étudiant on 28/10/2023.
//
import Foundation
protocol IAuthService {
func login(email : String, password : String, completion : @escaping (Int)-> ())
func register(email : String, password : String, username : String, completion : @escaping (Int)-> ())
}

@ -9,6 +9,11 @@ import SwiftUI
@main @main
struct AllInApp: App { struct AllInApp: App {
let DI = DependencyInjection.shared
init() {
DI.addSingleton(IAuthService.self, AuthService())
}
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ContentView() ContentView()

@ -33,4 +33,43 @@ final class AllInTests: XCTestCase {
} }
} }
func testInstance() {
DependencyInjection.shared.addSingleton(UserTest.self, UserTest(age: 10))
let view1 = View1()
let view2 = View2()
XCTAssertEqual(view1.getAge(), view2.getAge())
view1.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
view2.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
}
class UserTest {
public var age:Int
init(age:Int) {
self.age = age
}
}
class View1 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 20
}
}
class View2 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 40
}
}
} }

Loading…
Cancel
Save