Ejemplo n.º 1
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_Account_Is_Already_Confirmed()
        {
            var requestAccountConfirmationTokenCommand = new RequestAccountConfirmationTokenCommand("*****@*****.**");
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail(requestAccountConfirmationTokenCommand.Email)
                          .SetConfirmed(false)
                          .SetPasswordHash("PasswordHash")
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                          .Build();
            var getAccountResult = GetResult <Account> .Ok(account);

            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.AlreadyConfirmed, AccountErrorMessage.AlreadyConfirmed)
            };
            var emailIsNotConfirmedVerificationResult = VerificationResult.Fail(errors);

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);
            _accountVerificationServiceMock.Setup(x => x.VerifyAccountIsNotConfirmed(It.IsAny <bool>()))
            .Returns(emailIsNotConfirmedVerificationResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(requestAccountConfirmationTokenCommand);

            var exceptionResult = await result.Should().ThrowExactlyAsync <ValidationException>();

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Ejemplo n.º 2
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_Account_Is_Not_Found()
        {
            var requestAccountConfirmationTokenCommand = new RequestAccountConfirmationTokenCommand("*****@*****.**");
            var errors = new Collection <IError>
            {
                new Error(AccountErrorCodeEnumeration.NotFound, AccountErrorMessage.NotFound)
            };
            var getAccountResult = GetResult <Account> .Fail(errors);

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);

            Func <Task> result = async() => await _commandHandler.HandleAsync(requestAccountConfirmationTokenCommand);

            var exceptionResult = await result.Should().ThrowExactlyAsync <ValidationException>();

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Ejemplo n.º 3
0
        public async Task HandleAsync_Should_Request_Account_Confirmation_Token()
        {
            var requestAccountConfirmationTokenCommand = new RequestAccountConfirmationTokenCommand("*****@*****.**");
            var account = Account.Builder()
                          .SetId(Guid.NewGuid())
                          .SetEmail(requestAccountConfirmationTokenCommand.Email)
                          .SetConfirmed(false)
                          .SetPasswordHash("PasswordHash")
                          .SetSecurityStamp(Guid.NewGuid())
                          .SetCreated(DateTimeOffset.UtcNow)
                          .SetRoles(new List <Guid> {
                Guid.NewGuid()
            })
                          .Build();
            var getAccountResult = GetResult <Account> .Ok(account);

            var emailIsNotConfirmedVerificationResult = VerificationResult.Ok();
            var cancellationToken = new CancellationToken();

            _accountGetterServiceMock.Setup(x => x.GetByEmailAsync(It.IsAny <string>()))
            .ReturnsAsync(getAccountResult);
            _accountVerificationServiceMock.Setup(x => x.VerifyAccountIsNotConfirmed(It.IsAny <bool>()))
            .Returns(emailIsNotConfirmedVerificationResult);
            _communicationBusMock.Setup(x => x.DispatchDomainEventsAsync(It.IsAny <Account>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _accountRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <Account>())).Returns(Task.CompletedTask);
            _accountConfirmationRequestServiceMock
            .Setup(x => x.PublishAccountConfirmationRequestedIntegrationEventAsync(It.IsAny <string>(),
                                                                                   It.IsAny <string>(), It.IsAny <Guid>())).Returns(Task.CompletedTask)
            .Verifiable();

            Func <Task> result = async() => await _commandHandler.HandleAsync(requestAccountConfirmationTokenCommand, cancellationToken);

            await result.Should().NotThrowAsync <Exception>();

            _communicationBusMock.Verify(
                x => x.DispatchDomainEventsAsync(It.Is <Account>(a => a == account),
                                                 It.Is <CancellationToken>(ct => ct == cancellationToken)), Times.Once);
        }
Ejemplo n.º 4
0
        public async Task RequestAccountConfirmationTokenAsync_Should_Return_NoContentResult()
        {
            var requestAccountConfirmationTokenRequest = new RequestAccountConfirmationTokenRequest
            {
                Email = "*****@*****.**"
            };
            var requestAccountConfirmationTokenCommand = new RequestAccountConfirmationTokenCommand(requestAccountConfirmationTokenRequest.Email);

            _mapperMock.Setup(x =>
                              x.Map <RequestAccountConfirmationTokenRequest, RequestAccountConfirmationTokenCommand>(
                                  It.IsAny <RequestAccountConfirmationTokenRequest>()))
            .Returns(requestAccountConfirmationTokenCommand);
            _communicationBusMock
            .Setup(x => x.SendCommandAsync(It.IsAny <RequestAccountConfirmationTokenCommand>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

            var result = await _controller.RequestAccountConfirmationTokenAsync(requestAccountConfirmationTokenRequest);

            var noContentResult = result.As <NoContentResult>();

            noContentResult.Should().NotBeNull();
        }