Example #1
0
        public void SetUp()
        {
            _user = new RegisterUserEntity
            {
                Email    = _email,
                UserName = _userName,
                Password = _password
            };

            _userLogin = new LogInEntity
            {
                Email    = _email,
                Password = _password
            };

            var mockUserList = new List <User>
            {
                new User
                {
                    Id        = _userId,
                    Email     = _email,
                    Username  = _userName,
                    Password  = _password,
                    CreatedAt = _createdAt
                },
                new User
                {
                    Id        = _userId1,
                    Email     = _email1,
                    Username  = _userName1,
                    Password  = _password1,
                    CreatedAt = _createdAt1
                }
            };


            _userRepositoryMock = new Mock <IBaseRepository <User> >();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new ModelToEntityProfile());
                cfg.AddProfile(new EntityToViewModelProfile());
            });

            _mapper = config.CreateMapper();

            _userRepositoryMock.Setup(repo => repo.All())
            .Returns(mockUserList);

            _userRepositoryMock.Setup(repo => repo.Where(It.IsAny <Expression <Func <User, bool> > >()))
            .Returns((Expression <Func <User, bool> > expression) => mockUserList.AsQueryable().Where(expression));

            _userService = new UserService(_userRepositoryMock.Object,
                                           _mapper);
        }
Example #2
0
        public UserEntity LogInAsync(LogInEntity logInEntity)
        {
            var user = _userRepository.Where(u => u.Email == logInEntity.Email &&
                                             u.Password == logInEntity.Password)
                       .FirstOrDefault();

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

            return(_mapper.Map <UserEntity>(user));
        }
Example #3
0
        public void LogInUser(LogInEntity userLogInData)
        {
            if (string.IsNullOrEmpty(userLogInData.UserName) || string.IsNullOrEmpty(userLogInData.Password))
            {
                throw new ArgumentException("Korisnicko ime i password su neophodni da bi se ulogovali.");
            }
            if (!this.DoesUserExist(userLogInData))
            {
                throw new ArgumentException("Korisnik ne postoji u bazi.");
            }
            if (!this.IsPasswordCorrect(userLogInData))
            {
                throw new ArgumentException("Pogresno korisnicko ime.");
            }

            User user = this._userService.GetUserByUserName(userLogInData.UserName);

            this.AddUserToCache(user);
        }
Example #4
0
 private bool IsPasswordCorrect(LogInEntity userLogInData)
 {
     return(this._userService.GetUserByUserName(userLogInData.UserName).Password == userLogInData.Password);
 }
Example #5
0
 private bool DoesUserExist(LogInEntity userLogInData)
 {
     return(this._userService.GetUserByUserName(userLogInData.UserName) != null);
 }