Ejemplo n.º 1
0
        public async Task HandleAsync(AnnouncementPreferenceCreationCompletedIntegrationEventFailure integrationEvent, CancellationToken cancellationToken = default)
        {
            var announcementPreferenceName = integrationEvent.AnnouncementPreferenceType == AnnouncementPreferenceType.FlatForRentAnnouncementPreference
                    ? nameof(FlatForRentAnnouncementPreference)
                    : nameof(RoomForRentAnnouncementPreference);
            var message = $"Could not finish {announcementPreferenceName} creation process.";

            _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaUsers, integrationEvent,
                                             "userId={userId}, message={message}, reason={reason}, code={code}",
                                             integrationEvent.UserId, message, integrationEvent.Reason, integrationEvent.Code);

            var userAnnouncementPreferenceCreationCompletedIntegrationEventFailure =
                new UserAnnouncementPreferenceCreationCompletedIntegrationEventFailure(integrationEvent.CorrelationId,
                                                                                       integrationEvent.Code, integrationEvent.Reason, integrationEvent.UserId,
                                                                                       integrationEvent.AnnouncementPreferenceId, integrationEvent.AnnouncementPreferenceType);
            var userAnnouncementPreferenceCreationCompletedIntegrationEventFailureTask =
                _integrationEventBus.PublishIntegrationEventAsync(userAnnouncementPreferenceCreationCompletedIntegrationEventFailure);

            try
            {
                await _userRevertService.RevertUserAsync(integrationEvent.UserId, integrationEvent.CorrelationId);
            }
            catch (Exception e)
            {
                _logger.LogIntegrationEventError(ServiceComponentEnumeration.RivaUsers, integrationEvent,
                                                 "userId={userId}, message={message}, stackTrace={stackTrace}", integrationEvent.UserId,
                                                 e.Message, e.StackTrace);
            }

            await userAnnouncementPreferenceCreationCompletedIntegrationEventFailureTask;
        }
Ejemplo n.º 2
0
        public async Task RevertUserAsync_Should_Revert_User_State()
        {
            var user = User.Builder()
                       .SetId(Guid.NewGuid())
                       .SetEmail("*****@*****.**")
                       .SetServiceActive(false)
                       .SetAnnouncementPreferenceLimit(10)
                       .SetAnnouncementSendingFrequency(AnnouncementSendingFrequencyEnumeration.EveryHour)
                       .SetPicture("UrlToPicture")
                       .Build();
            var userCreatedDomainEvent = new UserCreatedDomainEvent(user.Id, Guid.NewGuid(), user.Email,
                                                                    user.Picture, DefaultUserSettings.ServiceActive, DefaultUserSettings.AnnouncementPreferenceLimit,
                                                                    DefaultUserSettings.AnnouncementSendingFrequency);
            var userAnnouncementPreferenceLimitChangedDomainEvent =
                new UserAnnouncementPreferenceLimitChangedDomainEvent(user.Id, Guid.NewGuid(), 5);
            var domainEvents = new List <IDomainEvent> {
                userCreatedDomainEvent, userAnnouncementPreferenceLimitChangedDomainEvent
            };
            var getUserResult = GetResult <User> .Ok(user);

            var expectedUser = User.Builder()
                               .SetId(user.Id)
                               .SetEmail(user.Email)
                               .SetServiceActive(userCreatedDomainEvent.ServiceActive)
                               .SetAnnouncementPreferenceLimit(userAnnouncementPreferenceLimitChangedDomainEvent
                                                               .AnnouncementPreferenceLimit)
                               .SetAnnouncementSendingFrequency(userCreatedDomainEvent.AnnouncementSendingFrequency)
                               .SetPicture(userCreatedDomainEvent.Picture)
                               .Build();

            _domainEventStoreMock.Setup(x => x.FindAllAsync(It.IsAny <Guid>())).ReturnsAsync(domainEvents);
            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getUserResult);
            _userRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <User>())).Returns(Task.CompletedTask).Verifiable();

            Func <Task> result = async() => await _service.RevertUserAsync(user.Id, Guid.NewGuid());

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

            _userRepositoryMock.Verify(x => x.UpdateAsync(It.Is <User>(u =>
                                                                       u.Id == expectedUser.Id && u.Email.Equals(expectedUser.Email) &&
                                                                       u.Picture == expectedUser.Picture &&
                                                                       u.ServiceActive == expectedUser.ServiceActive &&
                                                                       u.AnnouncementPreferenceLimit == expectedUser.AnnouncementPreferenceLimit &&
                                                                       Equals(u.AnnouncementSendingFrequency, expectedUser.AnnouncementSendingFrequency))));
        }