Created
July 25, 2018 16:24
-
-
Save andru255/8e16de158831dfa6e79919ecfe75b94c to your computer and use it in GitHub Desktop.
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
class MockUserActions: UserActionProtocol { | |
private var totalLogin: Int = 0 | |
private var totalRegister: Int = 0 | |
func login(nick: String, password: String) { | |
self.totalLogin += 1 | |
} | |
func register(email: String, nick: String, password: String) { | |
self.totalRegister += 1 | |
} | |
// Lo que un mock debe cumplir, contar las veces que fué invocado un método | |
func getTotalLogins() -> Int { | |
return totalLogin | |
} | |
func getTotalRegister() -> Int { | |
return totalRegister | |
} | |
} | |
//Haciendo uso de nuestra clase mock | |
let mock = MockUserActions() | |
mock.login(nick: "foo", password: "bar") | |
mock.login(nick: "foo2", password: "bar2") | |
mock.register(email: "foo", nick: "foo", password: "bar") | |
print("total Login:", mock.getTotalLogins()) // nos retornará que usamos el método login 2 veces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment