public async Task ThenTheRespostioryWontBeUpdatedIfTheAccountIsNotLocked() { //Arrange _userRepositry.Setup(x => x.GetByEmailAddress(ExpectedEmail)) .ReturnsAsync(new User { Email = ExpectedEmail, IsLocked = false, SecurityCodes = new[] { new SecurityCode { Code = AccessCode, CodeType = SecurityCodeType.AccessCode, ExpiryTime = DateTime.MaxValue } } }); var unlockUserCommand = new UnlockUserCommand { UnlockCode = "ASDASDASD", Email = ExpectedEmail }; //Act await _unlockUserCommand.Handle(unlockUserCommand); //Assert _userRepositry.Verify(x => x.Update(It.IsAny <User>()), Times.Never); }
public void ThenAnAccountLockedEventIsRaisedIfTheValidationFailsAndTheUserIsNotNull() { //Arrange var expectedReturnUrl = "http://local.test"; _unlockUserCommandValidator.Setup(x => x.ValidateAsync(It.IsAny <UnlockUserCommand>())).ReturnsAsync(new ValidationResult { ValidationDictionary = { { "", "" } } }); var unlockUserCommand = new UnlockUserCommand { UnlockCode = AccessCode, Email = ExpectedEmail, User = new User { Email = ExpectedEmail }, ReturnUrl = expectedReturnUrl }; //Act Assert.ThrowsAsync <InvalidRequestException>(async() => await _unlockUserCommand.Handle(unlockUserCommand)); //Assert _mediator.Verify(x => x.PublishAsync(It.Is <AccountLockedEvent>(c => c.User.Email.Equals(ExpectedEmail) && c.ReturnUrl.Equals(expectedReturnUrl))), Times.Once); }
private void UnlockAccount() { if (user.Unlock()) { OnPropertyChanged("IsAccountLocked"); UnlockUserCommand.UpdateCanExecuteState(); } }
public async Task ThenTheUserRespositoryIsCalledIfTheCommandIsValid() { //Arrange var unlockUserCommand = new UnlockUserCommand { Email = ExpectedEmail }; //Act await _unlockUserCommand.Handle(unlockUserCommand); //Assert _userRepositry.Verify(x => x.Update(It.IsAny <User>()), Times.Once); }
public async Task ThenTheCommandIsCheckedToSeeIfItIsValid() { //Arrange var unlockUserCommand = new UnlockUserCommand { Email = ExpectedEmail }; //Act await _unlockUserCommand.Handle(unlockUserCommand); //Assert _unlockUserCommandValidator.Verify(x => x.ValidateAsync(unlockUserCommand), Times.Once); }
public async Task ThenTheUserIsRetrievedFromTheUserRepository() { //Arrange var unlockUserCommand = new UnlockUserCommand { Email = ExpectedEmail }; //Act await _unlockUserCommand.Handle(unlockUserCommand); //Assert _userRepositry.Verify(x => x.GetByEmailAddress(ExpectedEmail), Times.Once); }
public void ThenAnAccountLockedEventIsNotRaisedIfTheValidationFailsAndTheUserIsNull() { //Arrange _unlockUserCommandValidator.Setup(x => x.ValidateAsync(It.IsAny <UnlockUserCommand>())).ReturnsAsync(new ValidationResult { ValidationDictionary = { { "", "" } } }); var unlockUserCommand = new UnlockUserCommand { UnlockCode = AccessCode, Email = NotAUser }; //Act Assert.ThrowsAsync <InvalidRequestException>(async() => await _unlockUserCommand.Handle(unlockUserCommand)); //Assert _mediator.Verify(x => x.PublishAsync(It.IsAny <AccountLockedEvent>()), Times.Never()); }
public void ThenTheUserRepositoryIsNotUpdatedIfTheUserDoesNotExist() { //Arrange _unlockUserCommandValidator.Setup(x => x.ValidateAsync(It.IsAny <UnlockUserCommand>())).ReturnsAsync(new ValidationResult { ValidationDictionary = { { "", "" } } }); var unlockUserCommand = new UnlockUserCommand { UnlockCode = AccessCode, Email = NotAUser }; //Act Assert.ThrowsAsync <InvalidRequestException>(async() => await _unlockUserCommand.Handle(unlockUserCommand)); //Assert _userRepositry.Verify(x => x.Update(It.IsAny <User>()), Times.Never); }
public async Task ThenTheUserIsUnlockedAndUnlockCodesExpired() { //Arrange var unlockUserCommand = new UnlockUserCommand { UnlockCode = AccessCode, Email = ExpectedEmail }; //Act await _unlockUserCommand.Handle(unlockUserCommand); //Assert _userRepositry.Verify(x => x.Update(It.Is <User>(c => !c.IsActive && c.Email == ExpectedEmail && !c.IsLocked && c.FailedLoginAttempts == 0 && !c.SecurityCodes.Any(sc => sc.CodeType == SecurityCodeType.UnlockCode))), Times.Once); }
public async Task <IActionResult> UnlockUser([FromRoute] UnlockUserCommand request) { await _mediator.Send(request); return(Ok()); }