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); }
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)); }
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); }
private bool IsPasswordCorrect(LogInEntity userLogInData) { return(this._userService.GetUserByUserName(userLogInData.UserName).Password == userLogInData.Password); }
private bool DoesUserExist(LogInEntity userLogInData) { return(this._userService.GetUserByUserName(userLogInData.UserName) != null); }