public async Task HandleAsync_Should_Complete_Account_Creation_With_Success_When_UserCreationCompletedIntegrationEvent_Is_Received_And_Account_Has_Not_Confirmation_Token() { var userCreationCompletedIntegrationEvent = new UserCreationCompletedIntegrationEvent(Guid.NewGuid(), DateTimeOffset.UtcNow, Guid.NewGuid()); var account = Account.Builder() .SetId(userCreationCompletedIntegrationEvent.UserId) .SetEmail("*****@*****.**") .SetConfirmed(false) .SetPasswordHash("PasswordHash") .SetSecurityStamp(Guid.NewGuid()) .SetCreated(DateTimeOffset.UtcNow) .SetRoles(new List <Guid> { Guid.NewGuid() }) .Build(); var getAccountResult = GetResult <Account> .Ok(account); _accountGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getAccountResult); _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>())) .Returns(Task.CompletedTask).Verifiable(); Func <Task> result = async() => await _userCreatedIntegrationEventHandler.HandleAsync(userCreationCompletedIntegrationEvent); await result.Should().NotThrowAsync <Exception>(); _integrationEventBusMock.Verify(x => x.PublishIntegrationEventAsync(It.Is <IIntegrationEvent>(ie => IsPublishedIntegrationEventCorrect((AccountCreationCompletedIntegrationEvent)ie, userCreationCompletedIntegrationEvent.CorrelationId, account.Id)))); }
public async Task HandleAsync_Should_Complete_Account_Creation_With_Failure_When_UserCreationCompletedIntegrationEventFailure_Is_Received() { var userCreationCompletedIntegrationEventFailure = new UserCreationCompletedIntegrationEventFailure(Guid.NewGuid(), DateTimeOffset.UtcNow, "AnyCode", "AnyReason", Guid.NewGuid()); var account = Account.Builder() .SetId(userCreationCompletedIntegrationEventFailure.UserId) .SetEmail("*****@*****.**") .SetConfirmed(false) .SetPasswordHash("PasswordHash") .SetSecurityStamp(Guid.NewGuid()) .SetCreated(DateTimeOffset.UtcNow) .SetRoles(new List <Guid> { Guid.NewGuid() }) .Build(); var getAccountResult = GetResult <Account> .Ok(account); var message = $"Could not finish {nameof(Account)} creation process."; const string logMessage = "accountId={accountId}, message={message}, reason={reason}, code={code}"; var logParams = new object[] { userCreationCompletedIntegrationEventFailure.UserId, message, userCreationCompletedIntegrationEventFailure.Reason, userCreationCompletedIntegrationEventFailure.Code }; _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(); _accountGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getAccountResult); _accountDataConsistencyServiceMock.Setup(x => x.DeleteAccountWithRelatedPersistedGrants(It.IsAny <Account>())) .Returns(Task.CompletedTask); Func <Task> result = async() => await _userCreatedIntegrationEventHandlerFailure.HandleAsync(userCreationCompletedIntegrationEventFailure); await result.Should().NotThrowAsync <Exception>(); _loggerMock.Verify(x => x.LogIntegrationEventError( It.Is <ServiceComponentEnumeration>(s => Equals(s, ServiceComponentEnumeration.RivaIdentity)), It.Is <IIntegrationEvent>(ie => ie == userCreationCompletedIntegrationEventFailure), 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((AccountCreationCompletedIntegrationEventFailure)ie, userCreationCompletedIntegrationEventFailure.CorrelationId, userCreationCompletedIntegrationEventFailure.UserId, userCreationCompletedIntegrationEventFailure.Code, userCreationCompletedIntegrationEventFailure.Reason)))); }
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)))); }
public async Task HandleAsync_Should_Complete_Account_Deletion_With_Success_When_UserDeletionCompletedIntegrationEvent_Is_Received() { var userDeletionCompletedIntegrationEvent = new UserDeletionCompletedIntegrationEvent(Guid.NewGuid(), DateTimeOffset.UtcNow, Guid.NewGuid()); _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>())) .Returns(Task.CompletedTask) .Verifiable(); Func <Task> result = async() => await _userDeletionCompletedIntegrationEvent.HandleAsync(userDeletionCompletedIntegrationEvent); await result.Should().NotThrowAsync <Exception>(); _integrationEventBusMock.Verify(x => x.PublishIntegrationEventAsync(It.Is <IIntegrationEvent>(ie => IsPublishedIntegrationEventCorrect((AccountDeletionCompletedIntegrationEvent)ie, userDeletionCompletedIntegrationEvent.CorrelationId, userDeletionCompletedIntegrationEvent.UserId)))); }