Ejemplo n.º 1
0
        public void GetApiToken_TokenForUser_ReturnedToken()
        {
            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);

                // assert
                Assert.That(result, Is.EqualTo(apiToken));
            }
        }
Ejemplo n.º 2
0
        public void GetApiToken_Success()
        {
            // arrange
            var hash = new Mock<IHashService>();
            var repository = new Mock<IUsersRepository>();

            var users = new List<User> { 
                new User { 
                    Id = 1, 
                    Email = "*****@*****.**", 
                    PasswordHash = "passhash", 
                    ApiToken = "12345" }, 
                new User { 
                    Id = 2, 
                    Email = "*****@*****.**", 
                    PasswordHash = "passhash2", 
                    ApiToken = "23211" 
                } };
            
            repository.Setup(r => r.Users).Returns(users.AsQueryable());

            hash.Setup(h => h.ValidateMD5Hash("pass", "passhash2")).Returns(true);

            var service = new ApiService(repository.Object, hash.Object);

            // act
            var token = service.GetApiToken("*****@*****.**", "pass");

            // post
            Assert.That(token, Is.Not.Null);
            Assert.That(token, Is.EqualTo("23211"));
        }