Esempio 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));
        }
Esempio 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);
        }
Esempio 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>());
        }
Esempio 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>());
        }
Esempio 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);
        }