Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        public void Smoke()
        {
            // arrange
            var hash = new Mock<IHashService>();
            var repository = new Mock<IUsersRepository>();
            var service = new ApiService(repository.Object, hash.Object);

            // act / post
            Assert.That(service, Is.Not.Null);
        }
Esempio n. 3
0
        public void Smoke()
        {
            using (var fixture = new FixtureInit("http://localhost"))
            {
                // arrange
                var userRepository = new UsersRepository(fixture.Setup.Context);
                var hashService = new HashService();

                // act / post
                var service = new ApiService(userRepository, hashService);
                Assert.That(service, Is.Not.Null);
            }
        }
Esempio n. 4
0
        public void Authenticate_Fail()
        {
            // arrange
            var hash = new Mock<IHashService>();
            var repository = new Mock<IUsersRepository>();

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

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

            // act
            var result = service.GetUserByApiToken("12346");

            // assert
        }
Esempio n. 5
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"));
        }