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 Index_KeyHashIsWrong_RedirectedToError() { // 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); // act var result = controller.Index("email", "this_is_wrong_hash") as RedirectToRouteResult; // assert var action = result.RouteValues["action"] as string; action.Should().Be("error"); }