public void GetApiToken_WrongPassword_ReturnedTokenWillBeNull() { using (var fixture = new FixtureInit("http://localhost")) { // arrange var userRepository = new UsersRepository(fixture.Setup.Context); var hashService = new HashService(); var service = new ApiService(userRepository, hashService); var email = "*****@*****.**"; var password = "******"; var passwordHash = hashService.CreateMD5Hash(password); var apiToken = hashService.CreateApiToken(email, password); userRepository.Save( new User { Email = email, PasswordHash = passwordHash, ApiToken = apiToken, Temp = false } ); // act var result = service.GetApiToken(email, password + "xx"); // assert Assert.That(result, Is.Null); } }
public void Index_ViewBagContainsUserEmail() { // arrange var tasksRepository = new Mock<ITasksRepository>(); var usersRepository = new Mock<IUsersRepository>(); var pathHelper = new Mock<IPathHelper>(); var hashService = new HashService(); var shareService = new ShareService(pathHelper.Object, hashService); var controller = new ShareController(shareService, tasksRepository.Object, usersRepository.Object); var tasks = new List<Task> { new Task { Id = 0, UserId = 11, Description = "Task 0" }, new Task { Id = 1, UserId = 11, Description = "Task 1" }, new Task { Id = 2, UserId = 11, Description = "Task 2" } }; tasksRepository.Setup(r => r.Tasks).Returns(tasks.AsQueryable()); var users = new List<User> { new User { Email = "*****@*****.**", Id = 11 } }; usersRepository.Setup(u => u.Users).Returns(users.AsQueryable()); // act var email = "*****@*****.**"; var correctHash = hashService.CreateMD5Hash(email + "shared_tasks"); var result = controller.Index(email, correctHash) as ViewResult; // assert var emailResult = result.ViewBag.Email as string; emailResult.Should().Be(email); }
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)); }
public void GetUserId() { // 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 id = service.GetUserIdByEmail("*****@*****.**"); // assert Assert.That(id, Is.EqualTo(1)); }