public void IsValidTest() { var target = new AuthenticationService(); var actual = target.IsValid("joey", "91000000"); //always failed Assert.IsTrue(actual); }
public void IsValidTest() { var target = new AuthenticationService(); target.profile = new StubProfileDao(); target.rsaToken = new StubRsaTokenDao(); var actual = target.IsValid("joey", "91000000"); //always failed Assert.IsTrue(actual); }
public void IsValidTest() { var stubProfile = new StubProfileDao(); var stubToken = new StubTokenDao(); var target = new AuthenticationService(stubProfile, stubToken); var actual = target.IsValid("joey", "91000000"); Assert.IsTrue(actual); }
private static AuthenticationService GetAuthenticationService() { var profile = new ProfileDao(); var token = new RsaTokenDao(); // 你可以隨時抽換 log 的紀錄方式,只需要實作 ILog var log = GetLog(); var result = new AuthenticationService(profile, token, log); return result; }
public void IsValidTest() { var stubProfileDao = Substitute.For<IProfileDao>(); stubProfileDao.GetPassword("joey").Returns("91"); var stubTokenDao = Substitute.For<ITokenDao>(); stubTokenDao.GetRandom("joey").Returns("000000"); var target = new AuthenticationService(stubProfileDao, stubTokenDao); var actual = target.IsValid("joey", "91000000"); //always failed Assert.IsTrue(actual); }
public void IsValidTest() { IProfileDao profile = Substitute.For<IProfileDao>(); profile.GetPassword("joey").Returns("91"); IRsaTokenDao rsaToken = Substitute.For<IRsaTokenDao>(); rsaToken.GetRandom("").ReturnsForAnyArgs("000000"); var target = new AuthenticationService(profile, rsaToken); var actual = target.IsValid("joey", "91000000"); //always failed Assert.IsTrue(actual); }
public void IsValidTest() { //var stubProfile = new StubProfileDao(); IProfileDao stubProfile = Substitute.For<IProfileDao>(); stubProfile.GetPassword("joey").Returns("91"); //var stubToken = new StubTokenDao(); IRsaToken stubToken = Substitute.For<IRsaToken>(); stubToken.GetRandom("").ReturnsForAnyArgs("000000"); var target = new AuthenticationService(stubProfile, stubToken); var actual = target.IsValid("joey", "91000000"); Assert.IsTrue(actual); }
public void IsValidTest_如何驗證當非法登入時有正確紀錄log() { // 試著使用 stub object 的 ReturnsForAnyArgs() 方法 //例如:profile.GetPassword("").ReturnsForAnyArgs("91"); // 不管GetPassword()傳入任何參數,都要回傳 "91" IProfile profile = Substitute.For<IProfile>(); profile.GetPassword("").ReturnsForAnyArgs("91"); IToken token = Substitute.For<IToken>(); token.GetRandom("").ReturnsForAnyArgs("abc"); // step 1: arrange, 建立 mock object ILog log = Substitute.For<ILog>(); AuthenticationService target = new AuthenticationService(profile, token, log); string account = "Joey"; string password = "******"; // step 2: act bool actual; actual = target.IsValid(account, password); // step 3: assert, mock object 是否有正確互動 //log.Received().Save("account:Joey try to login failed"); //Received(1) 可以簡化成 Received() //log.Received().Save(Arg.Is<string>(x => x.Contains("login failed") && x.Contains("Joey"))); log.ReceivedWithAnyArgs().Save(""); }
public void IsValidTest_只有驗證Authentication合法或非法() { //arrange IProfile profile = Substitute.For<IProfile>(); profile.GetPassword("Joey").Returns("91"); IToken token = Substitute.For<IToken>(); token.GetRandom("Joey").Returns("abc"); ILog log = Substitute.For<ILog>(); AuthenticationService target = new AuthenticationService(profile, token, log); string account = "Joey"; string password = "******"; // 正確的 password 應為 "91abc" //act bool actual; actual = target.IsValid(account, password); // assert Assert.IsFalse(actual); }