public async Task <AuthenticationDto> VerifyUser(UserDto userDto)
        {
            var authenticationDto = new AuthenticationDto();
            ISpecification <UserDto> specification = new UserNameSpecification();

            if (!specification.IsSatisfiedBy(userDto))
            {
                authenticationDto.AddRule("userDto", "UserName is empty.");
            }

            var userLogin = await this.loginRepository.GetLogin(userDto.UserName);

            if (userLogin == null)
            {
                authenticationDto.AddRule("userDto", "Invalid UserName.");
            }

            if (!ECWRNGRfcSaltedHashManager.VerifyPassword(userDto.Password, userLogin.PasswordHash, userLogin.PasswordSalt))
            {
                authenticationDto.AddRule("userDto", "UserName or password is incorrect.");
            }
            else
            {
                authenticationDto.IsAuthenticated = true;
                authenticationDto.AddRule("Success", "Authentication is successfull.");
            }
            return(authenticationDto);
        }
        public async Task <ResponseDto> CreateUserLogin(UserDto userDto)
        {
            var authenticationDto = new AuthenticationDto();
            ISpecification <UserDto> specification = new UserNameSpecification()
                                                     .And(new PasswordSpecification());

            if (specification.IsSatisfiedBy(userDto))
            {
                var user = new Users();
                user.UserName = userDto.UserName;


                string passwordHash = ""; string passwordSalt = "";
                ECWRNGRfcSaltedHashManager.GenrateSaltedHash(userDto.Password, out passwordHash, out passwordSalt);

                user.Logins.Add(new Logins {
                    UserName = userDto.UserName, PasswordHash = passwordHash, PasswordSalt = passwordSalt
                });
                var userId = await this.loginRepository.CreateLogin(user);

                if (userId <= 0)
                {
                    authenticationDto.AddRule("userDto", "Server Error.");
                }
            }

            return(authenticationDto);
        }
        public async Task FindOne_FindOneElementBySpecAsync_ElementFound(string name)
        {
            var user = new UserBuilder()
                       .WithTestValues()
                       .Name(name)
                       .Build();

            this.Repository.Add(user);
            await SaveChangesAsync();

            ISpecification <User> userNameSpec = new UserNameSpecification(name);

            var newItem = await this.Repository.FindOneAsync <User>(userNameSpec);

            Assert.True(newItem != null);
            await ClearMemoryAsync();
        }
        public void FindOne_FindOneElementBySpec_ElementFound(string name)
        {
            var user = new UserBuilder()
                       .WithTestValues()
                       .Name(name)
                       .Build();

            this.Repository.Add(user);
            SaveChanges();

            ISpecification <User> userNameSpec = new UserNameSpecification(name);

            var newItem = this.Repository.FindOne <User>(userNameSpec);

            Assert.True(newItem != null);
            ClearMemory();
        }
        public async Task Find_FindElementsBySpecAsync_ListContainsOneElement(string name)
        {
            var user = new UserBuilder()
                       .WithTestValues()
                       .Name(name)
                       .Build();

            this.Repository.Add(user);
            await SaveChangesAsync();

            ISpecification <User> userNameSpec = new UserNameSpecification(name);

            var newItem = await this.Repository.FindAsync <User>(userNameSpec);

            Assert.True(newItem.Count() == 1);
            await ClearMemoryAsync();
        }
        public void Find_FindElementsBySpec_ListContainsOneElement(string name)
        {
            var user = new UserBuilder()
                       .WithTestValues()
                       .Name(name)
                       .Build();

            this.Repository.Add(user);
            SaveChanges();

            ISpecification <User> userNameSpec = new UserNameSpecification(name);

            var newItem = this.Repository.Find <User>(userNameSpec);

            Assert.True(newItem.Count() == 1);
            ClearMemory();
        }