public void LogoutSuccessful() { var id = 1; var profile = new ProfileDbModel { Id = 1 }; var account = new AccountDbModel { Id = 1, Login = "******", Password = "******", Profile = profile }; var statistic = new StatisticDbModel() { AccountId = 2, AccountDbModel = account, DateLogIn = DateTime.Now, DateLogOut = null }; var statistics = new List <StatisticDbModel> { statistic }; _validator.Setup(v => v.Validate(It.IsAny <RegisterUserDto>()).IsValid).Returns(true); _emailService.Setup(x => x.SendConfirmation(It.IsAny <AccountConfirmationDto>())); _factoryRepository.Setup(x => x.Statistics.Find(It.IsAny <Expression <Func <StatisticDbModel, bool> > >())) .Returns(statistics); _factoryRepository.Setup(x => x.Statistics.Update(It.IsAny <StatisticDbModel>())).Returns(statistic); var userService = new AccountService(_factoryRepository.Object, _emailService.Object, this._validator.Object, _tokenValidatorMock.Object); Assert.IsNotNull(userService.Logout(1)); }
public async Task <Account> LoginAsync(LoginDto data) { var user = _factoryRepository.Accounts.GetByLogin(data.Login) ?? throw new NotFoundUserException(); if (user.Password != data.Password) { throw new IncorrectPasswordException(); } var statistic = new StatisticDbModel() { AccountId = user.Id }; var result = await this._factoryRepository.Statistics.AddAsync(statistic); result = result ?? throw new AddStatisticException(); return(Mapper.Map <Account>(result.AccountDbModel)); }
/// <summary> /// Login user /// </summary> /// <param name="data">Login data</param> /// <returns><c>Authorised user</c></returns> public Account Login(LoginDto data) { if (data == null || string.IsNullOrWhiteSpace(data.Login) || string.IsNullOrWhiteSpace(data.Password)) { throw new ArgumentNullException(Resources.NullOrEmptyValue, nameof(data)); } var user = _factoryRepository.Accounts.GetByLogin(data.Login) ?? throw new NotFoundUserException(); if (user.Password != data.Password) { throw new IncorrectPasswordException(); } var statistic = new StatisticDbModel() { AccountId = user.Id }; var result = this._factoryRepository.Statistics.Add(statistic); result = result ?? throw new AddStatisticException(); return(Mapper.Map <Account>(result.AccountDbModel)); }