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);

        }
Esempio n. 2
0
        public void CreateShareLink_CreatedLinkAndToken()
        {
            // arrange
            var pathHelper = new Mock<IPathHelper>();
            var hashService = new HashService();
            var shareService = new ShareService(pathHelper.Object, hashService);

            pathHelper.SetReturnsDefault("/user/share");

            // act
            var link = shareService.CreateShareLink("*****@*****.**");

            // assert
            link.Should().Contain("/user/share/[email protected]?key=");
        }
Esempio n. 3
0
        public void ValidateShareKey_WrongKey()
        {
            var pathHelper = new Mock<IPathHelper>();
            var hashService = new HashService();
            var shareService = new ShareService(pathHelper.Object, hashService);

            pathHelper.SetReturnsDefault("/user/share");

            var key = "dd12113dcb92ffeb0d7afaf0261fAAAA";

            // act
            var result = shareService.ValidateShareKey("*****@*****.**", key);

            // assert
            result.Should().Be.False();
        }
        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");
        }