Example #1
0
        public async Task HandleAsync_Should_Store_DomainEvent()
        {
            var domainEvent = new AccountCreatedDomainEvent(Guid.NewGuid(), Guid.NewGuid(), "*****@*****.**", false,
                                                            "PasswordHash", Guid.NewGuid(), DateTimeOffset.UtcNow, null);

            _domainEventStoreMock.Setup(x => x.Store(It.IsAny <IDomainEvent>())).Verifiable();

            Func <Task> result = async() => await _domainEventHandler.HandleAsync(domainEvent);

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

            _domainEventStoreMock.Verify(x => x.Store(It.Is <IDomainEvent>(e => e.GetType() == typeof(AccountCreatedDomainEvent))));
        }
Example #2
0
        public async Task HandleAsync_Should_Complete_Account_Deletion_With_Failure_When_UserDeletionCompletedIntegrationEventFailure_Is_Received()
        {
            var userDeletionCompletedIntegrationEventFailure = new UserDeletionCompletedIntegrationEventFailure(Guid.NewGuid(),
                                                                                                                DateTimeOffset.UtcNow, "AnyCode", "AnyReason", Guid.NewGuid());
            var          message    = $"Could not finish {nameof(Account)} deletion process.";
            const string logMessage = "accountId={accountId}, message={message}, reason={reason}, code={code}";
            var          logParams  = new object[]
            {
                userDeletionCompletedIntegrationEventFailure.UserId,
                message,
                userDeletionCompletedIntegrationEventFailure.Reason,
                userDeletionCompletedIntegrationEventFailure.Code
            };
            var accountCreatedDomainEvent = new AccountCreatedDomainEvent(
                userDeletionCompletedIntegrationEventFailure.UserId,
                userDeletionCompletedIntegrationEventFailure.UserId, "*****@*****.**", true, "PasswordHash",
                Guid.NewGuid(), DateTimeOffset.UtcNow, null);
            var domainEvents = new List <IDomainEvent> {
                accountCreatedDomainEvent
            };

            _loggerMock.Setup(x => x.LogIntegrationEventError(It.IsAny <ServiceComponentEnumeration>(),
                                                              It.IsAny <IIntegrationEvent>(), It.IsAny <string>(), It.IsAny <object[]>()))
            .Verifiable();
            _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>()))
            .Returns(Task.CompletedTask)
            .Verifiable();
            _domainEventStoreMock.Setup(x => x.FindAllAsync(It.IsAny <Guid>())).ReturnsAsync(domainEvents);
            _accountRepositoryMock.Setup(x => x.AddAsync(It.IsAny <Account>())).Returns(Task.CompletedTask);
            _accountRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <Account>())).Returns(Task.CompletedTask);


            Func <Task> result = async() => await _userDeletionCompletedIntegrationEventFailure.HandleAsync(userDeletionCompletedIntegrationEventFailure);

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

            _loggerMock.Verify(x => x.LogIntegrationEventError(
                                   It.Is <ServiceComponentEnumeration>(s => Equals(s, ServiceComponentEnumeration.RivaIdentity)),
                                   It.Is <IIntegrationEvent>(ie => ie == userDeletionCompletedIntegrationEventFailure),
                                   It.Is <string>(m => m.Equals(logMessage)), It.Is <object[]>(p => !p.Except(logParams).Any())));
            _integrationEventBusMock.Verify(x => x.PublishIntegrationEventAsync(It.Is <IIntegrationEvent>(ie =>
                                                                                                          IsPublishedIntegrationEventCorrect((AccountDeletionCompletedIntegrationEventFailure)ie,
                                                                                                                                             userDeletionCompletedIntegrationEventFailure.CorrelationId, userDeletionCompletedIntegrationEventFailure.UserId,
                                                                                                                                             userDeletionCompletedIntegrationEventFailure.Code, userDeletionCompletedIntegrationEventFailure.Reason))));
        }
Example #3
0
        private void AccountCreated()
        {
            var notification = new AccountCreatedDomainEvent(Id);

            base.AddDomainEvent(notification);
        }