示例#1
0
        public async Task HandleAsync(UserCreationCompletedIntegrationEvent integrationEvent, CancellationToken cancellationToken = default)
        {
            try
            {
                var getAccountResult = await _accountGetterService.GetByIdAsync(integrationEvent.UserId);

                var accountCreationCompletedIntegrationEvent =
                    new AccountCreationCompletedIntegrationEvent(integrationEvent.CorrelationId,
                                                                 getAccountResult.Value.Id);
                var publishIntegrationEvenTask = _integrationEventBus.PublishIntegrationEventAsync(accountCreationCompletedIntegrationEvent);

                var accountConfirmationToken = getAccountResult.Value.Tokens.SingleOrDefault(x => x.Type.Equals(TokenTypeEnumeration.AccountConfirmation));
                if (accountConfirmationToken != null)
                {
                    await _accountConfirmationRequestService.PublishAccountConfirmationRequestedIntegrationEventAsync(
                        getAccountResult.Value.Email, accountConfirmationToken.Value, integrationEvent.CorrelationId);
                }

                await publishIntegrationEvenTask;
            }
            catch (Exception e)
            {
                _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaIdentity, integrationEvent,
                                                 "accountId={accountId}, message={message}, stackTrace={stackTrace}", integrationEvent.UserId,
                                                 e.Message, e.StackTrace);

                var accountCreationCompletedIntegrationEventFailure =
                    new AccountCreationCompletedIntegrationEventFailure(integrationEvent.CorrelationId,
                                                                        IntegrationEventErrorCodeEnumeration.UnexpectedError.DisplayName,
                                                                        IntegrationEventErrorMessage.UnexpectedError, integrationEvent.UserId);
                await _integrationEventBus.PublishIntegrationEventAsync(accountCreationCompletedIntegrationEventFailure);
            }
        }
示例#2
0
        public async Task PublishAccountConfirmationRequestedIntegrationEventAsync_Should_Publish_AccountConfirmationRequestedIntegrationEvent()
        {
            const string email         = "*****@*****.**";
            const string token         = "12345";
            var          correlationId = Guid.NewGuid();

            _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>()))
            .Returns(Task.CompletedTask).Verifiable();

            Func <Task> result = async() => await _service.PublishAccountConfirmationRequestedIntegrationEventAsync(email, token, correlationId);

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

            _integrationEventBusMock.Verify(
                x => x.PublishIntegrationEventAsync(It.Is <IIntegrationEvent>(integrationEvent =>
                                                                              integrationEvent.CorrelationId == correlationId)), Times.Once);
        }
示例#3
0
        public async Task HandleAsync(RequestAccountConfirmationTokenCommand command, CancellationToken cancellationToken = default)
        {
            var getAccountResult = await _accountGetterService.GetByEmailAsync(command.Email);

            if (!getAccountResult.Success)
            {
                throw new ValidationException(getAccountResult.Errors);
            }

            var accountIsNotConfirmedVerificationResult = _accountVerificationService.VerifyAccountIsNotConfirmed(getAccountResult.Value.Confirmed);

            if (!accountIsNotConfirmedVerificationResult.Success)
            {
                throw new ValidationException(accountIsNotConfirmedVerificationResult.Errors);
            }

            var correlationId = Guid.NewGuid();
            var token         = getAccountResult.Value.GenerateToken(TokenTypeEnumeration.AccountConfirmation, correlationId);
            await _communicationBus.DispatchDomainEventsAsync(getAccountResult.Value, cancellationToken);

            await _accountRepository.UpdateAsync(getAccountResult.Value);

            await _accountConfirmationRequestService.PublishAccountConfirmationRequestedIntegrationEventAsync(getAccountResult.Value.Email, token.Value, correlationId);
        }