Exemple #1
0
 public void AddRoomForRentAnnouncementPreference(RoomForRentAnnouncementPreference roomForRentAnnouncementPreference, Guid correlationId)
 {
     _roomForRentAnnouncementPreferences.Add(roomForRentAnnouncementPreference);
     _roomForRentAnnouncementPreferences = new UserRoomForRentAnnouncementPreferences(_roomForRentAnnouncementPreferences, _flatForRentAnnouncementPreferences.Count,
                                                                                      AnnouncementPreferenceLimit);
     AddEvent(new UserRoomForRentAnnouncementPreferenceAddedDomainEvent(Id, correlationId, roomForRentAnnouncementPreference));
 }
Exemple #2
0
        public void GetByByUserAndId_Should_Return_GetResult_Ok_With_RoomForRentAnnouncementPreference()
        {
            var id = Guid.NewGuid();
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(id)
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(0)
                                                    .SetPriceMax(1500)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();
            var roomForRentAnnouncementPreferences = new List <RoomForRentAnnouncementPreference> {
                roomForRentAnnouncementPreference
            };
            var user = User.Builder()
                       .SetId(Guid.NewGuid())
                       .SetEmail("*****@*****.**")
                       .SetServiceActive(DefaultUserSettings.ServiceActive)
                       .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                       .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                       .SetRoomForRentAnnouncementPreferences(roomForRentAnnouncementPreferences)
                       .Build();
            var expectedResult = GetResult <RoomForRentAnnouncementPreference> .Ok(roomForRentAnnouncementPreference);

            var result = _service.GetByByUserAndId(user, id);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #3
0
        public void VerifyRoomForRentAnnouncementPreferences_Should_Return_Fail_VerificationResult_When_Prices_Can_Be_Changed()
        {
            var cityId        = Guid.NewGuid();
            var cityDistricts = new List <Guid> {
                Guid.NewGuid()
            };
            var roomForRentAnnouncementPreferences = new List <RoomForRentAnnouncementPreference>
            {
                RoomForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(cityId)
                .SetPriceMin(0)
                .SetPriceMax(1000)
                .SetRoomType(RoomTypeEnumeration.Single)
                .SetCityDistricts(cityDistricts)
                .Build(),
                RoomForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(cityId)
                .SetPriceMin(0)
                .SetPriceMax(1500)
                .SetRoomType(RoomTypeEnumeration.Single)
                .SetCityDistricts(cityDistricts)
                .Build()
            };
            var errors = new List <IError>
            {
                new Error(RoomForRentAnnouncementPreferenceErrorCode.ChangeablePrices, RoomForRentAnnouncementPreferenceErrorMessage.ChangeablePrices)
            };
            var expectedResult = VerificationResult.Fail(errors);

            var result = _service.VerifyRoomForRentAnnouncementPreferences(roomForRentAnnouncementPreferences);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #4
0
        public void Should_Create_RoomForRentAnnouncementPreference()
        {
            var roomForRentAnnouncementPreferenceId = Guid.NewGuid();
            var cityId        = Guid.NewGuid();
            var cityDistricts = new List <Guid> {
                Guid.NewGuid()
            };
            const decimal priceMin = 0;
            const decimal priceMax = 2000;
            var           roomType = RoomTypeEnumeration.Single;
            var           roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                              .SetId(roomForRentAnnouncementPreferenceId)
                                                              .SetCityId(cityId)
                                                              .SetPriceMin(priceMin)
                                                              .SetPriceMax(priceMax)
                                                              .SetRoomType(roomType)
                                                              .SetCityDistricts(cityDistricts)
                                                              .Build();

            roomForRentAnnouncementPreference.Id.Should().Be(roomForRentAnnouncementPreferenceId);
            roomForRentAnnouncementPreference.CityId.Should().Be(cityId);
            roomForRentAnnouncementPreference.PriceMin.Should().Be(priceMin);
            roomForRentAnnouncementPreference.PriceMax.Should().Be(priceMax);
            roomForRentAnnouncementPreference.RoomType.Should().Be(roomType);
            roomForRentAnnouncementPreference.CityDistricts.Should().BeEquivalentTo(cityDistricts);
        }
Exemple #5
0
        private async Task UpdateCityAndCityDistrictsAsync(RoomForRentAnnouncementPreference roomForRentAnnouncementPreference, Guid cityId, ICollection <Guid> cityDistricts)
        {
            var sameCityDistricts = roomForRentAnnouncementPreference.CityDistricts.All(cityDistricts.Contains) &&
                                    roomForRentAnnouncementPreference.CityDistricts.Count == cityDistricts.Count;

            if (roomForRentAnnouncementPreference.CityId != cityId)
            {
                var cityAndCityDistrictsVerificationResult = await _cityVerificationService.VerifyCityAndCityDistrictsAsync(cityId, cityDistricts);

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

                roomForRentAnnouncementPreference.ChangeCityId(cityId);
                roomForRentAnnouncementPreference.ChangeCityDistricts(cityDistricts);
            }

            if (roomForRentAnnouncementPreference.CityId == cityId && !sameCityDistricts)
            {
                var cityAndCityDistrictsVerificationResult = await _cityVerificationService.VerifyCityAndCityDistrictsAsync(cityId, cityDistricts);

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

                roomForRentAnnouncementPreference.ChangeCityDistricts(cityDistricts);
            }
        }
Exemple #6
0
        private static void ProcessRoomForRentAnnouncementPreference(RoomForRentAnnouncementPreference roomForRentAnnouncementPreference,
                                                                     RoomForRentAnnouncementsIntegrationEvent integrationEvent, HashSet <Guid> processedAnnouncementPreferenceIds)
        {
            lock (processedAnnouncementPreferenceIds)
            {
                if (!processedAnnouncementPreferenceIds.Add(roomForRentAnnouncementPreference.Id))
                {
                    return;
                }
            }

            foreach (var roomForRentAnnouncement in integrationEvent.RoomForRentAnnouncements)
            {
                if (roomForRentAnnouncementPreference.RoomType.HasValue)
                {
                    if (roomForRentAnnouncement.RoomTypes.Any())
                    {
                        if (roomForRentAnnouncement.RoomTypes.Contains(roomForRentAnnouncementPreference.RoomType.Value))
                        {
                            ProcessRoomForRentAnnouncementPreferenceForPriceMin(roomForRentAnnouncement, roomForRentAnnouncementPreference);
                        }
                    }
                    else
                    {
                        ProcessRoomForRentAnnouncementPreferenceForPriceMin(roomForRentAnnouncement, roomForRentAnnouncementPreference);
                    }
                }
                else
                {
                    ProcessRoomForRentAnnouncementPreferenceForPriceMin(roomForRentAnnouncement, roomForRentAnnouncementPreference);
                }
            }
        }
Exemple #7
0
 private static void UpdateRoomForRentAnnouncementPreferenceEntity(AnnouncementPreferenceEntity announcementPreferenceEntity,
                                                                   RoomForRentAnnouncementPreference roomForRentAnnouncementPreference)
 {
     announcementPreferenceEntity.CityId   = roomForRentAnnouncementPreference.CityId;
     announcementPreferenceEntity.PriceMin = roomForRentAnnouncementPreference.PriceMin;
     announcementPreferenceEntity.PriceMax = roomForRentAnnouncementPreference.PriceMax;
     announcementPreferenceEntity.RoomType = roomForRentAnnouncementPreference.RoomType.ConvertToEnum();
 }
Exemple #8
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_Flat_For_Rent_Announcement_Preferences_Verification_Fails()
        {
            var command = new CreateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(), 1, 1000,
                                                                             RoomTypeEnumeration.Single, new List <Guid> {
                Guid.NewGuid()
            });
            var user = User.Builder()
                       .SetId(command.UserId)
                       .SetEmail("*****@*****.**")
                       .SetServiceActive(DefaultUserSettings.ServiceActive)
                       .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                       .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                       .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var cityAndCityDistrictsVerificationResult = VerificationResult.Ok();
            var announcementPreferenceLimitIsNotExceededVerificationResult = VerificationResult.Ok();
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(command.RoomForRentAnnouncementPreferenceId)
                                                    .SetCityId(command.CityId)
                                                    .SetPriceMin(command.PriceMin)
                                                    .SetPriceMax(command.PriceMax)
                                                    .SetRoomType(command.RoomType)
                                                    .SetCityDistricts(command.CityDistricts)
                                                    .Build();
            var errors = new Collection <IError>
            {
                new Error(RoomForRentAnnouncementPreferenceErrorCode.ExpansibleCityDistricts,
                          RoomForRentAnnouncementPreferenceErrorMessage.ExpansibleCityDistricts)
            };
            var roomForRentAnnouncementPreferencesVerificationResult = VerificationResult.Fail(errors);


            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _cityVerificationServiceMock
            .Setup(x => x.VerifyCityAndCityDistrictsAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >()))
            .ReturnsAsync(cityAndCityDistrictsVerificationResult);
            _userVerificationServiceMock
            .Setup(x => x.VerifyAnnouncementPreferenceLimitIsNotExceeded(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(announcementPreferenceLimitIsNotExceededVerificationResult);
            _mapperMock.Setup(x =>
                              x.Map <CreateRoomForRentAnnouncementPreferenceCommand, RoomForRentAnnouncementPreference>(
                                  It.IsAny <CreateRoomForRentAnnouncementPreferenceCommand>()))
            .Returns(roomForRentAnnouncementPreference);
            _roomForRentAnnouncementPreferenceVerificationServiceMock
            .Setup(x => x.VerifyRoomForRentAnnouncementPreferences(
                       It.IsAny <IEnumerable <RoomForRentAnnouncementPreference> >()))
            .Returns(roomForRentAnnouncementPreferencesVerificationResult);

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

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Exemple #9
0
        public async Task HandleAsync_Should_Create_Room_For_Rent_Announcement_Preference()
        {
            var command = new CreateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(), 1, 1000,
                                                                             RoomTypeEnumeration.Single, new List <Guid> {
                Guid.NewGuid()
            });
            var user = User.Builder()
                       .SetId(command.UserId)
                       .SetEmail("*****@*****.**")
                       .SetServiceActive(DefaultUserSettings.ServiceActive)
                       .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                       .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                       .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var cityAndCityDistrictsVerificationResult = VerificationResult.Ok();
            var announcementPreferenceLimitIsNotExceededVerificationResult = VerificationResult.Ok();
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(command.RoomForRentAnnouncementPreferenceId)
                                                    .SetCityId(command.CityId)
                                                    .SetPriceMin(command.PriceMin)
                                                    .SetPriceMax(command.PriceMax)
                                                    .SetRoomType(command.RoomType)
                                                    .SetCityDistricts(command.CityDistricts)
                                                    .Build();
            var roomForRentAnnouncementPreferencesVerificationResult = VerificationResult.Ok();


            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _cityVerificationServiceMock
            .Setup(x => x.VerifyCityAndCityDistrictsAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >()))
            .ReturnsAsync(cityAndCityDistrictsVerificationResult);
            _userVerificationServiceMock
            .Setup(x => x.VerifyAnnouncementPreferenceLimitIsNotExceeded(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(announcementPreferenceLimitIsNotExceededVerificationResult);
            _mapperMock.Setup(x =>
                              x.Map <CreateRoomForRentAnnouncementPreferenceCommand, RoomForRentAnnouncementPreference>(
                                  It.IsAny <CreateRoomForRentAnnouncementPreferenceCommand>()))
            .Returns(roomForRentAnnouncementPreference);
            _roomForRentAnnouncementPreferenceVerificationServiceMock
            .Setup(x => x.VerifyRoomForRentAnnouncementPreferences(
                       It.IsAny <IEnumerable <RoomForRentAnnouncementPreference> >()))
            .Returns(roomForRentAnnouncementPreferencesVerificationResult);
            _communicationBusMock
            .Setup(x => x.DispatchDomainEventsAsync(It.IsAny <User>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _userRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <User>())).Returns(Task.CompletedTask);
            _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>()))
            .Returns(Task.CompletedTask);

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

            await result.Should().NotThrowAsync <Exception>();
        }
Exemple #10
0
 public RoomForRentAnnouncementPreferenceProfile()
 {
     CreateMap <AnnouncementPreferenceEntity, RoomForRentAnnouncementPreference>()
     .ConvertUsing(x => RoomForRentAnnouncementPreference.Builder()
                   .SetId(x.Id)
                   .SetCityId(x.CityId)
                   .SetPriceMin(x.PriceMin)
                   .SetPriceMax(x.PriceMax)
                   .SetRoomType(x.RoomType.ConvertToEnumeration())
                   .SetCityDistricts(x.AnnouncementPreferenceCityDistricts.Select(acd => acd.CityDistrictId))
                   .Build());
 }
Exemple #11
0
        public RoomForRentAnnouncementPreferenceProfile()
        {
            CreateMap <RoomForRentAnnouncementPreference, RoomForRentAnnouncementPreferenceOutputQuery>();

            CreateMap <CreateRoomForRentAnnouncementPreferenceCommand, RoomForRentAnnouncementPreference>()
            .ForMember(x => x.CityDistricts, opt => opt.Ignore())
            .ConstructUsing(x => RoomForRentAnnouncementPreference.Builder()
                            .SetId(x.RoomForRentAnnouncementPreferenceId)
                            .SetCityId(x.CityId)
                            .SetPriceMin(x.PriceMin)
                            .SetPriceMax(x.PriceMax)
                            .SetRoomType(x.RoomType)
                            .SetCityDistricts(x.CityDistricts)
                            .Build());
        }
Exemple #12
0
 private static void ProcessRoomForRentAnnouncementPreferenceForPriceMin(RoomForRentAnnouncement roomForRentAnnouncement,
                                                                         RoomForRentAnnouncementPreference roomForRentAnnouncementPreference)
 {
     if (roomForRentAnnouncementPreference.PriceMin.HasValue && roomForRentAnnouncement.Price.HasValue)
     {
         if (PriceMinMatches(roomForRentAnnouncement.Price.Value, roomForRentAnnouncementPreference.PriceMin.Value))
         {
             ProcessRoomForRentAnnouncementPreferenceForPriceMax(roomForRentAnnouncement, roomForRentAnnouncementPreference);
         }
     }
     else
     {
         ProcessRoomForRentAnnouncementPreferenceForPriceMax(roomForRentAnnouncement, roomForRentAnnouncementPreference);
     }
 }
Exemple #13
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_City_And_City_Districts_Verification_Fails_For_The_Same_CityId()
        {
            var command = new UpdateRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid(),
                                                                             Guid.NewGuid(), 1, 1500, RoomTypeEnumeration.Double, new List <Guid> {
                Guid.NewGuid()
            });
            var user = User.Builder()
                       .SetId(command.UserId)
                       .SetEmail("*****@*****.**")
                       .SetServiceActive(DefaultUserSettings.ServiceActive)
                       .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                       .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                       .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(command.RoomForRentAnnouncementPreferenceId)
                                                    .SetCityId(command.CityId)
                                                    .SetPriceMin(1)
                                                    .SetPriceMax(1000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();
            var getRoomForRentAnnouncementPreferenceResult =
                GetResult <RoomForRentAnnouncementPreference> .Ok(roomForRentAnnouncementPreference);

            var errors = new Collection <IError>
            {
                new Error(CityErrorCodeEnumeration.IncorrectCityDistricts, CityErrorMessage.IncorrectCityDistricts)
            };
            var cityAndCityDistrictsVerificationResult = VerificationResult.Fail(errors);

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _roomForRentAnnouncementPreferenceGetterServiceMock
            .Setup(x => x.GetByByUserAndId(It.IsAny <User>(), It.IsAny <Guid>()))
            .Returns(getRoomForRentAnnouncementPreferenceResult);
            _cityVerificationServiceMock
            .Setup(x => x.VerifyCityAndCityDistrictsAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >()))
            .ReturnsAsync(cityAndCityDistrictsVerificationResult);

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

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Exemple #14
0
        public void Should_Throw_RoomForRentAnnouncementPreferenceCityDistrictsNullException_When_CityDistricts_Is_Null()
        {
            Action result = () =>
            {
                var unused = RoomForRentAnnouncementPreference.Builder()
                             .SetId(Guid.NewGuid())
                             .SetCityId(Guid.NewGuid())
                             .SetPriceMin(0)
                             .SetPriceMax(1000)
                             .SetRoomType(RoomTypeEnumeration.Single)
                             .SetCityDistricts(null)
                             .Build();
            };

            result.Should().ThrowExactly <RoomForRentAnnouncementPreferenceCityDistrictsNullException>()
            .WithMessage("CityDistricts argument is required.");
        }
Exemple #15
0
        public void ChangePriceMax_Should_Change_PriceMax()
        {
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(Guid.NewGuid())
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(0)
                                                    .SetPriceMax(2000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();

            roomForRentAnnouncementPreference.ChangePriceMax(null);

            roomForRentAnnouncementPreference.PriceMax.Should().BeNull();
        }
Exemple #16
0
        public void ChangeCityId_Should_Throw_RoomForRentAnnouncementPreferenceCityIdNullException_When_CityId_Is_New_Guid()
        {
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(Guid.NewGuid())
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(0)
                                                    .SetPriceMax(2000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();

            Action result = () => roomForRentAnnouncementPreference.ChangeCityId(new Guid());

            result.Should().ThrowExactly <RoomForRentAnnouncementPreferenceCityIdNullException>()
            .WithMessage("CityId argument is required.");
        }
Exemple #17
0
        public void ChangePriceMax_Should_Throw_RoomForRentAnnouncementPreferencePriceMaxLowerThanPriceMinException_When_PriceMax_Is_Lower_Than_PriceMin()
        {
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(Guid.NewGuid())
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(1000)
                                                    .SetPriceMax(2000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();

            Action result = () => roomForRentAnnouncementPreference.ChangePriceMax(0);

            result.Should().ThrowExactly <RoomForRentAnnouncementPreferencePriceMaxLowerThanPriceMinException>()
            .WithMessage("PriceMax argument cannot be lower than PriceMin.");
        }
Exemple #18
0
        public void ChangePriceMax_Should_Throw_RoomForRentAnnouncementPreferencePriceMaxMinValueException_When_PriceMax_Is_Negative_Value()
        {
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(Guid.NewGuid())
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(0)
                                                    .SetPriceMax(2000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();

            Action result = () => roomForRentAnnouncementPreference.ChangePriceMax(-1);

            result.Should().ThrowExactly <RoomForRentAnnouncementPreferencePriceMaxMinValueException>()
            .WithMessage("PriceMax argument min value is 0.");
        }
Exemple #19
0
        public void ChangeRoomType_Should_Change_RoomType()
        {
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(Guid.NewGuid())
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(0)
                                                    .SetPriceMax(2000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();
            var newRoomType = RoomTypeEnumeration.Double;

            roomForRentAnnouncementPreference.ChangeRoomType(newRoomType);

            roomForRentAnnouncementPreference.RoomType.Should().BeEquivalentTo(newRoomType);
        }
Exemple #20
0
 private static void ProcessRoomForRentAnnouncementPreferenceForPriceMax(RoomForRentAnnouncement roomForRentAnnouncement,
                                                                         RoomForRentAnnouncementPreference roomForRentAnnouncementPreference)
 {
     if (roomForRentAnnouncementPreference.PriceMax.HasValue && roomForRentAnnouncement.Price.HasValue)
     {
         if (PriceMaxMatches(roomForRentAnnouncement.Price.Value, roomForRentAnnouncementPreference.PriceMax.Value) &&
             CityDistrictsMatch(roomForRentAnnouncement, roomForRentAnnouncementPreference))
         {
             roomForRentAnnouncementPreference.AnnouncementUrlsToSend.Add(roomForRentAnnouncement.SourceUrl);
         }
     }
     else
     {
         if (CityDistrictsMatch(roomForRentAnnouncement, roomForRentAnnouncementPreference))
         {
             roomForRentAnnouncementPreference.AnnouncementUrlsToSend.Add(roomForRentAnnouncement.SourceUrl);
         }
     }
 }
Exemple #21
0
        public void Should_Throw_RoomForRentAnnouncementPreferenceIdNullException_When_Id_Is_Empty_Guid()
        {
            Action result = () =>
            {
                var unused = RoomForRentAnnouncementPreference.Builder()
                             .SetId(Guid.Empty)
                             .SetCityId(Guid.NewGuid())
                             .SetPriceMin(0)
                             .SetPriceMax(2000)
                             .SetRoomType(RoomTypeEnumeration.Single)
                             .SetCityDistricts(new List <Guid> {
                    Guid.NewGuid()
                })
                             .Build();
            };

            result.Should().ThrowExactly <RoomForRentAnnouncementPreferenceIdNullException>()
            .WithMessage("Id argument is required.");
        }
Exemple #22
0
        public void Should_Throw_RoomForRentAnnouncementPreferenceCityDistrictsDuplicateValuesException_When_CityDistricts_Contains_Duplicates()
        {
            var    cityDistrict = Guid.NewGuid();
            Action result       = () =>
            {
                var unused = RoomForRentAnnouncementPreference.Builder()
                             .SetId(Guid.NewGuid())
                             .SetCityId(Guid.NewGuid())
                             .SetPriceMin(0)
                             .SetPriceMax(1000)
                             .SetRoomType(RoomTypeEnumeration.Single)
                             .SetCityDistricts(new List <Guid> {
                    cityDistrict, cityDistrict
                })
                             .Build();
            };

            result.Should().ThrowExactly <RoomForRentAnnouncementPreferenceCityDistrictsDuplicateValuesException>()
            .WithMessage("CityDistricts argument contains duplicate values.");
        }
Exemple #23
0
        public void VerifyRoomForRentAnnouncementPreferences_Should_Return_Success_VerificationResult()
        {
            var cityId        = Guid.NewGuid();
            var cityDistricts = new List <Guid> {
                Guid.NewGuid()
            };
            var roomForRentAnnouncementPreferences = new List <RoomForRentAnnouncementPreference>
            {
                RoomForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(cityId)
                .SetPriceMin(0)
                .SetPriceMax(1000)
                .SetRoomType(RoomTypeEnumeration.Single)
                .SetCityDistricts(cityDistricts)
                .Build(),
                RoomForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(cityId)
                .SetPriceMin(0)
                .SetPriceMax(1000)
                .SetRoomType(RoomTypeEnumeration.Double)
                .SetCityDistricts(cityDistricts)
                .Build(),
                RoomForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(Guid.NewGuid())
                .SetPriceMin(0)
                .SetPriceMax(1000)
                .SetRoomType(RoomTypeEnumeration.Double)
                .SetCityDistricts(new List <Guid> {
                    Guid.NewGuid()
                })
                .Build()
            };
            var expectedResult = VerificationResult.Ok();

            var result = _service.VerifyRoomForRentAnnouncementPreferences(roomForRentAnnouncementPreferences);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #24
0
        private User CreateUser(string email)
        {
            var cityId        = Guid.NewGuid();
            var cityDistricts = new List <Guid> {
                Guid.NewGuid()
            };
            var flatForRentAnnouncementPreferences = new List <FlatForRentAnnouncementPreference>
            {
                FlatForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(cityId)
                .SetPriceMin(0)
                .SetPriceMax(2000)
                .SetRoomNumbersMin(1)
                .SetRoomNumbersMax(2)
                .SetCityDistricts(cityDistricts)
                .Build()
            };
            var roomForRentAnnouncementPreferences = new List <RoomForRentAnnouncementPreference>
            {
                RoomForRentAnnouncementPreference.Builder()
                .SetId(Guid.NewGuid())
                .SetCityId(cityId)
                .SetPriceMin(0)
                .SetPriceMax(2000)
                .SetRoomType(RoomTypeEnumeration.Single)
                .SetCityDistricts(cityDistricts)
                .Build()
            };

            return(User.Builder()
                   .SetId(Guid.NewGuid())
                   .SetEmail(email)
                   .SetServiceActive(DefaultUserSettings.ServiceActive)
                   .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                   .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                   .SetFlatForRentAnnouncementPreferences(flatForRentAnnouncementPreferences)
                   .SetRoomForRentAnnouncementPreferences(roomForRentAnnouncementPreferences)
                   .Build());
        }
Exemple #25
0
        public async Task HandleAsync_Should_Delete_Room_For_Rent_Announcement_Preference()
        {
            var command = new DeleteRoomForRentAnnouncementPreferenceCommand(Guid.NewGuid(), Guid.NewGuid());
            var user    = User.Builder()
                          .SetId(command.UserId)
                          .SetEmail("*****@*****.**")
                          .SetServiceActive(DefaultUserSettings.ServiceActive)
                          .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                          .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                          .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(command.RoomForRentAnnouncementPreferenceId)
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(1)
                                                    .SetPriceMax(1000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                    .Build();
            var getRoomForRentAnnouncementPreferenceResult =
                GetResult <RoomForRentAnnouncementPreference> .Ok(roomForRentAnnouncementPreference);

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _roomForRentAnnouncementPreferenceGetterServiceMock
            .Setup(x => x.GetByByUserAndId(It.IsAny <User>(), It.IsAny <Guid>()))
            .Returns(getRoomForRentAnnouncementPreferenceResult);
            _communicationBusMock
            .Setup(x => x.DispatchDomainEventsAsync(It.IsAny <User>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            _userRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <User>())).Returns(Task.CompletedTask);
            _integrationEventBusMock.Setup(x => x.PublishIntegrationEventAsync(It.IsAny <IIntegrationEvent>()))
            .Returns(Task.CompletedTask);

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

            await result.Should().NotThrowAsync <Exception>();
        }
Exemple #26
0
        public async Task HandleAsync_Should_Return_RoomForRentAnnouncementPreferenceOutputQuery()
        {
            var inputQuery = new GetRoomForRentAnnouncementPreferenceInputQuery(Guid.NewGuid(), Guid.NewGuid());
            var user       = User.Builder()
                             .SetId(inputQuery.UserId)
                             .SetEmail("*****@*****.**")
                             .SetServiceActive(DefaultUserSettings.ServiceActive)
                             .SetAnnouncementPreferenceLimit(DefaultUserSettings.AnnouncementPreferenceLimit)
                             .SetAnnouncementSendingFrequency(DefaultUserSettings.AnnouncementSendingFrequency)
                             .Build();
            var getUserResult = GetResult <User> .Ok(user);

            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(inputQuery.RoomForRentAnnouncementPreferenceId)
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(1)
                                                    .SetPriceMax(1000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .Build();
            var getRoomForRentAnnouncementPreferenceResult =
                GetResult <RoomForRentAnnouncementPreference> .Ok(roomForRentAnnouncementPreference);

            var expectedResult = new RoomForRentAnnouncementPreferenceOutputQuery(roomForRentAnnouncementPreference.Id,
                                                                                  roomForRentAnnouncementPreference.CityId, roomForRentAnnouncementPreference.PriceMin,
                                                                                  roomForRentAnnouncementPreference.PriceMax, roomForRentAnnouncementPreference.RoomType,
                                                                                  roomForRentAnnouncementPreference.CityDistricts);

            _userGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(getUserResult);
            _roomForRentAnnouncementPreferenceGetterServiceMock
            .Setup(x => x.GetByByUserAndId(It.IsAny <User>(), It.IsAny <Guid>()))
            .Returns(getRoomForRentAnnouncementPreferenceResult);
            _mapperMock.Setup(x =>
                              x.Map <RoomForRentAnnouncementPreference, RoomForRentAnnouncementPreferenceOutputQuery>(
                                  It.IsAny <RoomForRentAnnouncementPreference>()))
            .Returns(expectedResult);

            var result = await _queryHandler.HandleAsync(inputQuery);

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemple #27
0
        public async Task HandleAsync_Should_Store_DomainEvent()
        {
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(Guid.NewGuid())
                                                    .SetCityId(Guid.NewGuid())
                                                    .SetPriceMin(1)
                                                    .SetPriceMax(1000)
                                                    .SetRoomType(RoomTypeEnumeration.Single)
                                                    .Build();
            var domainEvent = new UserRoomForRentAnnouncementPreferenceDeletedDomainEvent(Guid.NewGuid(),
                                                                                          Guid.NewGuid(), roomForRentAnnouncementPreference);

            _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(UserRoomForRentAnnouncementPreferenceDeletedDomainEvent))));
        }
Exemple #28
0
        private void AddNewRoomForRentAnnouncementPreferenceEntity(RoomForRentAnnouncementPreference roomForRentAnnouncementPreference, Guid userId)
        {
            var announcementPreferenceEntity = new AnnouncementPreferenceEntity
            {
                Id       = roomForRentAnnouncementPreference.Id,
                UserId   = userId,
                CityId   = roomForRentAnnouncementPreference.CityId,
                PriceMin = roomForRentAnnouncementPreference.PriceMin,
                PriceMax = roomForRentAnnouncementPreference.PriceMax,
                RoomType = roomForRentAnnouncementPreference.RoomType.ConvertToEnum(),
                AnnouncementPreferenceType          = AnnouncementPreferenceType.RoomForRentAnnouncementPreference,
                AnnouncementPreferenceCityDistricts = roomForRentAnnouncementPreference.CityDistricts.Select(
                    cd =>
                    new AnnouncementPreferenceCityDistrictEntity
                {
                    CityDistrictId           = cd,
                    AnnouncementPreferenceId = roomForRentAnnouncementPreference.Id
                }).ToList()
            };

            _announcementPreferencesDbSet.Add(announcementPreferenceEntity);
        }
Exemple #29
0
        public void Should_Create_RoomForRentAnnouncementPreference_With_Null_Values()
        {
            var roomForRentAnnouncementPreferenceId = Guid.NewGuid();
            var cityId        = Guid.NewGuid();
            var cityDistricts = new List <Guid> {
                Guid.NewGuid()
            };
            var roomForRentAnnouncementPreference = RoomForRentAnnouncementPreference.Builder()
                                                    .SetId(roomForRentAnnouncementPreferenceId)
                                                    .SetCityId(cityId)
                                                    .SetPriceMin(null)
                                                    .SetPriceMax(null)
                                                    .SetRoomType(null)
                                                    .SetCityDistricts(cityDistricts)
                                                    .Build();

            roomForRentAnnouncementPreference.Id.Should().Be(roomForRentAnnouncementPreferenceId);
            roomForRentAnnouncementPreference.CityId.Should().Be(cityId);
            roomForRentAnnouncementPreference.PriceMin.Should().BeNull();
            roomForRentAnnouncementPreference.PriceMax.Should().BeNull();
            roomForRentAnnouncementPreference.RoomType.Should().BeNull();
            roomForRentAnnouncementPreference.CityDistricts.Should().BeEquivalentTo(cityDistricts);
        }
Exemple #30
0
        public async Task AddAsync(UserRoomForRentAnnouncementPreferenceCreatedIntegrationEvent integrationEvent)
        {
            var roomForRentAnnouncementPreference = new RoomForRentAnnouncementPreference
            {
                Id            = integrationEvent.RoomForRentAnnouncementPreferenceId,
                UserId        = integrationEvent.UserId,
                UserEmail     = integrationEvent.UserEmail,
                CityId        = integrationEvent.CityId,
                ServiceActive = integrationEvent.ServiceActive,
                AnnouncementSendingFrequency = integrationEvent.AnnouncementSendingFrequency,
                PriceMin         = integrationEvent.PriceMin,
                PriceMax         = integrationEvent.PriceMax,
                RoomType         = integrationEvent.RoomType,
                CityDistricts    = integrationEvent.CityDistricts.ToList(),
                CosmosEntityName = nameof(RoomForRentAnnouncementPreference)
            };
            var addResult = await _cosmosStore.AddAsync(roomForRentAnnouncementPreference);

            if (!addResult.IsSuccess)
            {
                throw addResult.Exception;
            }
        }