public void FailedAuthentication_WrongPassword() { // arrange var users = new Mock<IUsersRepository>(); var forms = new Mock<IFormsAuthentication>(); var hash = new HashService(); var service = new AuthenticationService(users.Object, forms.Object, hash); users.Setup(u => u.Users).Returns(new List<User> { new User { Email = "*****@*****.**", PasswordHash = hash.CreateMD5Hash("111"), Id = 1, Temp = false } }.AsQueryable()); forms.Setup(f => f.SetAuthCookie("", false)).Throws(new Exception("SetAuthCookie must not be called for failed authentication")); // act var auth = service.Authenticate("*****@*****.**", "1111"); // post Assert.That(auth, Is.False); }
public void SuccessAuthentication() { // arrange var users = new Mock<IUsersRepository>(); var forms = new Mock<IFormsAuthentication>(); var hash = new HashService(); var service = new AuthenticationService(users.Object, forms.Object, hash); users.Setup(u => u.Users).Returns(new List<User> { new User { Email = "*****@*****.**", PasswordHash = hash.CreateMD5Hash("111"), Id = 1, Temp = false } }.AsQueryable()); // act var auth = service.Authenticate("*****@*****.**", "111"); // post Assert.That(auth, Is.True); forms.Verify(f => f.SetAuthCookie("*****@*****.**", false)); }