public void Sha256HashGenerator_Hash_ThrowsForEmptyString()
        {
            // Arrange
            string value         = string.Empty;
            var    hashGenerator = new Sha256HashGenerator();

            // Act
            Assert.Catch <ArgumentException>(() => Sha256HashGenerator_Hash_ThrowsForEmptyStringAct(hashGenerator, value));
        }
Ejemplo n.º 2
0
        public void Sha256HashGenerator_Hash_ThrowsForEmptyString()
        {
            // Arrange
            string value         = string.Empty;
            var    hashGenerator = new Sha256HashGenerator();

            // Act
            var valueHash = hashGenerator.Hash(value);
        }
        public void Sha256HashGenerator_Hash_IsConsistent()
        {
            // Arrange
            var value         = "value";
            var hashGenerator = new Sha256HashGenerator();

            // Act
            var valueHash1 = hashGenerator.Hash(value);
            var valueHash2 = hashGenerator.Hash(value);

            // Assert
            Assert.AreEqual(valueHash1, valueHash2);
        }
        public void Sha256HashGenerator_Hash_IsDifferent()
        {
            // Arrange
            var value1        = "value1";
            var value2        = "value2";
            var hashGenerator = new Sha256HashGenerator();

            // Act
            var valueHash1 = hashGenerator.Hash(value1);
            var valueHash2 = hashGenerator.Hash(value2);

            // Assert
            Assert.AreNotEqual(valueHash1, valueHash2);
        }
Ejemplo n.º 5
0
        public void UpdatePassword(UserPasswordViewModel model)
        {
            var mapper = CustomMapperConfiguration.ConfigCreateMapper <UserPasswordViewModel, User>();
            //var config = new MapperConfiguration(c =>
            //{
            //    c.CreateMap<UserPasswordViewModel, User>();
            //    c.IgnoreUnmapped();
            //});
            //var mapper = config.CreateMapper();
            var user = mapper.Map <UserPasswordViewModel, User>(model);

            user.Password = Sha256HashGenerator.GenerateHash(model.Password);
            _usersRepository.UpdatePassword(user);
        }
Ejemplo n.º 6
0
        public int Insert(RegisterViewModel model)
        {
            var mapper = CustomMapperConfiguration.ConfigCreateMapper <RegisterViewModel, User>();
            //var config = new MapperConfiguration(c =>
            //{
            //    c.CreateMap<RegisterViewModel, User>();
            //    c.IgnoreUnmapped();
            //});
            //var mapper = config.CreateMapper();
            var user = mapper.Map <RegisterViewModel, User>(model);

            user.Password = Sha256HashGenerator.GenerateHash(model.Password);
            _usersRepository.Insert(user);
            return(_usersRepository.GetRecentUser());
        }
Ejemplo n.º 7
0
        public void TestInit()
        {
            // Setup routingTableMockHash
            var hashGenerator = new Mock <IConsistentHashGenerator>();

            hashGenerator
            .Setup(x => x.Hash(It.IsAny <string>()))
            .Returns(() => { return((UInt32)random.Next()); });

            this.routingTableMockHash = new RoutingTable(hashGenerator.Object);

            // Setup routingTableRealHash
            var realHashGenerator = new Sha256HashGenerator();

            this.routingTableRealHash = new RoutingTable(realHashGenerator);
        }
Ejemplo n.º 8
0
        public UserViewModel GetByEmailPassword(string email, string password)
        {
            var user = _usersRepository.GetByEmailPassword(email, Sha256HashGenerator.GenerateHash(password));

            if (user == null)
            {
                return(null);
            }

            var mapper = CustomMapperConfiguration.ConfigCreateMapper <User, UserViewModel>();

            //var config = new MapperConfiguration(c =>
            //{
            //    c.CreateMap<User, UserViewModel>();
            //    c.IgnoreUnmapped();
            //});
            //var mapper = config.CreateMapper();

            return(mapper.Map <User, UserViewModel>(user));
        }
 private void Sha256HashGenerator_Hash_ThrowsForEmptyStringAct(Sha256HashGenerator hashGenerator, string value)
 {
     var valueHash = hashGenerator.Hash(value);
 }