Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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>());
        }
Ejemplo n.º 4
0
        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>());
        }
Ejemplo n.º 5
0
        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);
        }