public async Task GivenConfirmEmailCommandHandler_WhenUserIsNotFound_ThenShouldThrowRestException() { _mockUserManager.FindByIdAsync(_userId).ReturnsNullForAnyArgs(); var confirmEmailCommandHandler = new ConfirmEmailCommandHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus, _mockFailedIdentityResult); await Assert.ThrowsAsync <RestException>(() => confirmEmailCommandHandler.Handle(_command, CancellationToken.None)); }
GivenConfirmEmailCommandHandler_WhenReceivesCorrectCommand_ThenShouldCallUserManagerToFindById() { _mockUserManager.FindByIdAsync(_userId).ReturnsForAnyArgs(_user); _mockUserManager.ConfirmEmailAsync(_user, _emailConfirmationToken) .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Success)); var confirmEmailCommandHandler = new ConfirmEmailCommandHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus, _mockFailedIdentityResult); await confirmEmailCommandHandler.Handle(_command, CancellationToken.None); await _mockUserManager.Received().FindByIdAsync(_userId); }
public async Task GivenConfirmEmailCommandHandler_WhenEmailConfirmed_ThenShouldPublishAuthenticationLogEvent() { _mockUserManager.FindByIdAsync(_userId).ReturnsForAnyArgs(_user); _mockUserManager.ConfirmEmailAsync(_user, _emailConfirmationToken) .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Success)); var confirmEmailCommandHandler = new ConfirmEmailCommandHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus, _mockFailedIdentityResult); await confirmEmailCommandHandler.Handle(_command, CancellationToken.None); _mockEventBus.Received().Publish(Arg.Any <AuthenticationLogEvent>()); }
GivenConfirmEmailCommandHandler_WhenEmailConfirmFails_ThenShouldCallFailedIdentityResult() { _mockUserManager.FindByIdAsync(_userId).ReturnsForAnyArgs(_user); _mockUserManager.ConfirmEmailAsync(_user, _emailConfirmationToken) .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Failed())); var confirmEmailCommandHandler = new ConfirmEmailCommandHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus, _mockFailedIdentityResult); await confirmEmailCommandHandler.Handle(_command, CancellationToken.None); _mockFailedIdentityResult.Received() .Handle(Arg.Any <AppUser>(), Arg.Any <List <IdentityError> >(), Arg.Any <string>()); }
GivenConfirmEmailCommandHandler_WhenReceivesCorrectCommand_ThenShouldConfirmUserAccountAndReturnUser() { _mockUserManager.FindByIdAsync(_userId).ReturnsForAnyArgs(_user); _mockUserManager.ConfirmEmailAsync(_user, _emailConfirmationToken) .ReturnsForAnyArgs(Task.FromResult(IdentityResult.Success)); var confirmEmailCommandHandler = new ConfirmEmailCommandHandler(_mockUserManager, _mockJwtGenerator, _mockEventBus, _mockFailedIdentityResult); var confirmedUser = await confirmEmailCommandHandler.Handle(_command, CancellationToken.None); Assert.NotNull(confirmedUser); Assert.True(confirmedUser.EmailConfirmed); }