Ejemplo n.º 1
0
        public async Task HandleAsync_Should_Return_FlatForRentAnnouncementOutputQuery()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement);

            var flatForRentAnnouncementOutputQuery = new FlatForRentAnnouncementOutputQuery(flatForRentAnnouncement.Id,
                                                                                            flatForRentAnnouncement.Title, flatForRentAnnouncement.SourceUrl, flatForRentAnnouncement.CityId,
                                                                                            flatForRentAnnouncement.Created, flatForRentAnnouncement.Description, flatForRentAnnouncement.Price,
                                                                                            flatForRentAnnouncement.NumberOfRooms, flatForRentAnnouncement.CityDistricts);

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);
            _mapperMock
            .Setup(x => x.Map <FlatForRentAnnouncement, FlatForRentAnnouncementOutputQuery>(It.IsAny <FlatForRentAnnouncement>()))
            .Returns(flatForRentAnnouncementOutputQuery);

            var result = await _queryHandler.HandleAsync(new GetFlatForRentAnnouncementInputQuery(flatForRentAnnouncement.Id));

            result.Should().BeEquivalentTo(flatForRentAnnouncementOutputQuery);
        }
Ejemplo n.º 2
0
        public async Task HandleAsync_Should_Return_CollectionOutputQuery_With_FlatForRentAnnouncementOutputQuery_When_Input_Is_Null()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var flatForRentAnnouncements = new List <FlatForRentAnnouncement> {
                flatForRentAnnouncement
            };
            var forRentAnnouncementOutputQueries = flatForRentAnnouncements
                                                   .Select(x => new FlatForRentAnnouncementOutputQuery(x.Id, x.Title, x.SourceUrl, x.CityId, x.Created, x.Description,
                                                                                                       x.Price, x.NumberOfRooms, x.CityDistricts)).ToList();
            var collectionOutputQuery = new CollectionOutputQuery <FlatForRentAnnouncementOutputQuery>(forRentAnnouncementOutputQueries.Count,
                                                                                                       forRentAnnouncementOutputQueries);

            _flatForRentAnnouncementRepositoryMock.Setup(x => x.GetAllAsync()).ReturnsAsync(flatForRentAnnouncements);
            _flatForRentAnnouncementRepositoryMock.Setup(x => x.CountAsync())
            .ReturnsAsync(flatForRentAnnouncements.Count);
            _mapperMock
            .Setup(x => x.Map <List <FlatForRentAnnouncement>, IEnumerable <FlatForRentAnnouncementOutputQuery> >(It.IsAny <List <FlatForRentAnnouncement> >()))
            .Returns(forRentAnnouncementOutputQueries);

            var result = await _queryHandler.HandleAsync(null);

            result.Should().BeEquivalentTo(collectionOutputQuery);
        }
Ejemplo n.º 3
0
        public async Task HandleAsync_Should_Delete_FlatForRentAnnouncement()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement);

            var deleteFlatForRentAnnouncementCommand = new DeleteFlatForRentAnnouncementCommand(flatForRentAnnouncement.Id);

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);
            _flatForRentAnnouncementRepositoryMock
            .Setup(x => x.DeleteAsync(It.IsAny <FlatForRentAnnouncement>()))
            .Returns(Task.CompletedTask);

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

            await result.Should().NotThrowAsync <Exception>();
        }
Ejemplo n.º 4
0
        public async Task HandleAsync_Should_Update_FlatForRentAnnouncement()
        {
            var cityDistrictToRemove    = Guid.NewGuid();
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                cityDistrictToRemove
            })
                                          .Build();
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement);

            var          cityVerificationResult          = VerificationResult.Ok();
            var          cityDistrictsVerificationResult = VerificationResult.Ok();
            var          cityDistrictToAdd = Guid.NewGuid();
            const string newTitle          = "NewTitle";
            var          updateFlatForRentAnnouncementCommand = new UpdateFlatForRentAnnouncementCommand(
                flatForRentAnnouncement.Id, newTitle, flatForRentAnnouncement.SourceUrl,
                flatForRentAnnouncement.CityId, flatForRentAnnouncement.Description, flatForRentAnnouncement.Price,
                flatForRentAnnouncement.NumberOfRooms, new List <Guid> {
                cityDistrictToAdd
            });

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);
            _cityVerificationServiceMock.Setup(x => x.VerifyCityExistsAsync(It.IsAny <Guid>()))
            .ReturnsAsync(cityVerificationResult);
            _cityDistrictVerificationServiceMock
            .Setup(x => x.VerifyCityDistrictsExistAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >()))
            .ReturnsAsync(cityDistrictsVerificationResult);
            _flatForRentAnnouncementRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <FlatForRentAnnouncement>()))
            .Returns(Task.CompletedTask);

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

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

            flatForRentAnnouncement.Title.Should().Be(newTitle);
            flatForRentAnnouncement.CityDistricts.Should().NotContain(cityDistrictToRemove);
            flatForRentAnnouncement.CityDistricts.Should().Contain(cityDistrictToAdd);
        }
Ejemplo n.º 5
0
        public FlatForRentAnnouncementProfile()
        {
            CreateMap <FlatForRentAnnouncement, FlatForRentAnnouncementOutputQuery>();

            CreateMap <CreateFlatForRentAnnouncementCommand, FlatForRentAnnouncement>()
            .ForMember(x => x.CityDistricts, opt => opt.Ignore())
            .ConstructUsing(x => FlatForRentAnnouncement.Builder()
                            .SetId(x.FlatForRentAnnouncementId)
                            .SetTitle(x.Title)
                            .SetSourceUrl(x.SourceUrl)
                            .SetCityId(x.CityId)
                            .SetCreated(DateTimeOffset.UtcNow)
                            .SetDescription(x.Description)
                            .SetNumberOfRooms(x.NumberOfRooms)
                            .SetPrice(x.Price)
                            .SetCityDistricts(x.CityDistricts)
                            .Build());
        }
Ejemplo n.º 6
0
        public void Should_Create_FlatForRentAnnouncement()
        {
            var result = FlatForRentAnnouncement.Builder()
                         .SetId(Guid.NewGuid())
                         .SetTitle("Title")
                         .SetSourceUrl("http://source")
                         .SetCityId(Guid.NewGuid())
                         .SetCreated(DateTimeOffset.UtcNow)
                         .SetDescription("Description")
                         .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                         .SetPrice(1000)
                         .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                         .Build();


            result.Should().NotBeNull();
        }
Ejemplo n.º 7
0
        public async Task HandleAsync_Should_Throw_ValidationException_When_Any_Of_CityDistricts_Is_Not_Found()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var getFlatForRentAnnouncementResult = GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement);

            var cityVerificationResult = VerificationResult.Ok();
            var errors = new Collection <IError>
            {
                new Error(CityDistrictErrorCodeEnumeration.NotFound, CityDistrictErrorMessage.NotFound)
            };
            var cityDistrictsVerificationResult      = VerificationResult.Fail(errors);
            var updateFlatForRentAnnouncementCommand = new UpdateFlatForRentAnnouncementCommand(
                flatForRentAnnouncement.Id, flatForRentAnnouncement.Title, flatForRentAnnouncement.SourceUrl,
                flatForRentAnnouncement.CityId, flatForRentAnnouncement.Description, flatForRentAnnouncement.Price,
                flatForRentAnnouncement.NumberOfRooms, flatForRentAnnouncement.CityDistricts);

            _flatForRentAnnouncementGetterServiceMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(getFlatForRentAnnouncementResult);
            _cityVerificationServiceMock.Setup(x => x.VerifyCityExistsAsync(It.IsAny <Guid>()))
            .ReturnsAsync(cityVerificationResult);
            _cityDistrictVerificationServiceMock
            .Setup(x => x.VerifyCityDistrictsExistAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >()))
            .ReturnsAsync(cityDistrictsVerificationResult);

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

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

            exceptionResult.And.Errors.Should().BeEquivalentTo(errors);
        }
Ejemplo n.º 8
0
        public void Should_Throw_FlatForRentAnnouncementCityDistrictsNullException_When_CityDistricts_Is_Null()
        {
            Action result = () =>
            {
                var unused = FlatForRentAnnouncement.Builder()
                             .SetId(Guid.NewGuid())
                             .SetTitle("Title")
                             .SetSourceUrl("http://source")
                             .SetCityId(Guid.NewGuid())
                             .SetCreated(DateTimeOffset.UtcNow)
                             .SetDescription("Description")
                             .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                             .SetPrice(1000)
                             .SetCityDistricts(null)
                             .Build();
            };

            result.Should().ThrowExactly <FlatForRentAnnouncementCityDistrictsNullException>()
            .WithMessage("CityDistricts argument is required.");
        }
Ejemplo n.º 9
0
        public FlatForRentAnnouncementProfile()
        {
            CreateMap <FlatForRentAnnouncementEntity, FlatForRentAnnouncement>()
            .ForMember(x => x.CityDistricts, opt => opt.Ignore())
            .ConvertUsing(x => FlatForRentAnnouncement.Builder()
                          .SetId(x.Id)
                          .SetTitle(x.Title)
                          .SetSourceUrl(x.SourceUrl)
                          .SetCityId(x.CityId)
                          .SetCreated(x.Created)
                          .SetDescription(x.Description)
                          .SetNumberOfRooms(x.NumberOfRooms.ConvertToEnumeration())
                          .SetPrice(x.Price)
                          .SetCityDistricts(x.CityDistricts)
                          .Build());

            CreateMap <FlatForRentAnnouncement, FlatForRentAnnouncementEntity>()
            .ForMember(x => x.NumberOfRooms,
                       opt => opt.MapFrom <NumberOfRoomsEnumerationToNumberOfRoomsEnumValueResolver>());
        }
Ejemplo n.º 10
0
        public void RemoveCityDistrict_Should_Throw_FlatForRentAnnouncementCityDistrictNullException_When_CityDistrict_Is_Empty_Guid()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();

            Action result = () => flatForRentAnnouncement.RemoveCityDistrict(Guid.Empty);

            result.Should().ThrowExactly <FlatForRentAnnouncementCityDistrictNullException>()
            .WithMessage("CityDistrict argument is required.");
        }
Ejemplo n.º 11
0
        public void ChangeNumberOfRooms_Should_Change_NumberOfRooms()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var newNumberOfRooms = NumberOfRoomsEnumeration.FiveAndMore;

            flatForRentAnnouncement.ChangeNumberOfRooms(newNumberOfRooms);

            flatForRentAnnouncement.NumberOfRooms.Should().BeEquivalentTo(newNumberOfRooms);
        }
Ejemplo n.º 12
0
        public void RemoveCityDistrict_Should_Remove_CityDistrict()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var cityDistrict = Guid.NewGuid();

            flatForRentAnnouncement.RemoveCityDistrict(cityDistrict);

            flatForRentAnnouncement.CityDistricts.Should().NotContain(cityDistrict);
        }
Ejemplo n.º 13
0
        public void ChangeChangePrice_Should_Change_ChangePrice()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var newPrice = 2000;

            flatForRentAnnouncement.ChangePrice(newPrice);

            flatForRentAnnouncement.Price.Should().Be(newPrice);
        }
Ejemplo n.º 14
0
        public void ChangeTitle_Should_Throw_FlatForRentAnnouncementTitleMaxLengthException_When_Title_Exceeds_Allowed_Max_Length_Value()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://source")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                          .SetPrice(1000)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var title = CreateString(257);

            Action result = () => flatForRentAnnouncement.ChangeTitle(title);

            result.Should().ThrowExactly <FlatForRentAnnouncementTitleMaxLengthException>()
            .WithMessage("Title argument max length is 256.");
        }
Ejemplo n.º 15
0
        public void Should_Throw_FlatForRentAnnouncementCityDistrictsInvalidValueException_When_CityDistricts_Contains_Empty_Guid()
        {
            Action result = () =>
            {
                var unused = FlatForRentAnnouncement.Builder()
                             .SetId(Guid.NewGuid())
                             .SetTitle("Title")
                             .SetSourceUrl("http://source")
                             .SetCityId(Guid.NewGuid())
                             .SetCreated(DateTimeOffset.UtcNow)
                             .SetDescription("Description")
                             .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                             .SetPrice(1000)
                             .SetCityDistricts(new List <Guid> {
                    Guid.Empty
                })
                             .Build();
            };

            result.Should().ThrowExactly <FlatForRentAnnouncementCityDistrictsInvalidValueException>()
            .WithMessage("CityDistricts argument is invalid.");
        }
Ejemplo n.º 16
0
        public async Task HandleAsync_Should_Create_FlatForRentAnnouncement()
        {
            var cityVerificationResult          = VerificationResult.Ok();
            var cityDistrictsVerificationResult = VerificationResult.Ok();
            var flatForRentAnnouncement         = FlatForRentAnnouncement.Builder()
                                                  .SetId(Guid.NewGuid())
                                                  .SetTitle("Title")
                                                  .SetSourceUrl("http://source")
                                                  .SetCityId(Guid.NewGuid())
                                                  .SetCreated(DateTimeOffset.UtcNow)
                                                  .SetDescription("Description")
                                                  .SetNumberOfRooms(NumberOfRoomsEnumeration.One)
                                                  .SetPrice(1000)
                                                  .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                                  .Build();
            var createFlatForRentAnnouncementCommand = new CreateFlatForRentAnnouncementCommand(
                flatForRentAnnouncement.Id, flatForRentAnnouncement.Title, flatForRentAnnouncement.SourceUrl,
                flatForRentAnnouncement.CityId, flatForRentAnnouncement.Description, flatForRentAnnouncement.Price,
                flatForRentAnnouncement.NumberOfRooms, flatForRentAnnouncement.CityDistricts);

            _cityVerificationServiceMock.Setup(x => x.VerifyCityExistsAsync(It.IsAny <Guid>()))
            .ReturnsAsync(cityVerificationResult);
            _cityDistrictVerificationServiceMock
            .Setup(x => x.VerifyCityDistrictsExistAsync(It.IsAny <Guid>(), It.IsAny <IEnumerable <Guid> >()))
            .ReturnsAsync(cityDistrictsVerificationResult);
            _mapperMock.Setup(x =>
                              x.Map <CreateFlatForRentAnnouncementCommand, FlatForRentAnnouncement>(
                                  It.IsAny <CreateFlatForRentAnnouncementCommand>())).Returns(flatForRentAnnouncement);
            _flatForRentAnnouncementRepositoryMock.Setup(x => x.AddAsync(It.IsAny <FlatForRentAnnouncement>()))
            .Returns(Task.CompletedTask);

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

            await result.Should().NotThrowAsync <Exception>();
        }
Ejemplo n.º 17
0
        public async Task GetByIdAsync_Should_Return_GetResult_Ok()
        {
            var flatForRentAnnouncement = FlatForRentAnnouncement.Builder()
                                          .SetId(Guid.NewGuid())
                                          .SetTitle("Title")
                                          .SetSourceUrl("http://sourceUrl")
                                          .SetCityId(Guid.NewGuid())
                                          .SetCreated(DateTimeOffset.UtcNow)
                                          .SetDescription("Description")
                                          .SetNumberOfRooms(NumberOfRoomsEnumeration.FiveAndMore)
                                          .SetPrice(100)
                                          .SetCityDistricts(new List <Guid> {
                Guid.NewGuid()
            })
                                          .Build();
            var expectedResult = GetResult <FlatForRentAnnouncement> .Ok(flatForRentAnnouncement);

            _flatForRentAnnouncementRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(flatForRentAnnouncement);

            var result = await _service.GetByIdAsync(flatForRentAnnouncement.Id);

            result.Should().BeEquivalentTo(expectedResult);
        }
Ejemplo n.º 18
0
        public async Task GetAllAsync_Should_Return_FlatForRentAnnouncements()
        {
            var flatForRentAnnouncementEntities = await _cosmosStore.Query().ToListAsync();

            var flatForRentAnnouncements = flatForRentAnnouncementEntities.Select(x => FlatForRentAnnouncement.Builder()
                                                                                  .SetId(x.Id)
                                                                                  .SetTitle(x.Title)
                                                                                  .SetSourceUrl(x.SourceUrl)
                                                                                  .SetCityId(x.CityId)
                                                                                  .SetCreated(x.Created)
                                                                                  .SetDescription(x.Description)
                                                                                  .SetNumberOfRooms(x.NumberOfRooms.ConvertToEnumeration())
                                                                                  .SetPrice(x.Price)
                                                                                  .SetCityDistricts(x.CityDistricts)
                                                                                  .Build())
                                           .ToList();

            _mapperMock
            .Setup(x => x.Map <List <FlatForRentAnnouncementEntity>, List <FlatForRentAnnouncement> >(It.IsAny <List <FlatForRentAnnouncementEntity> >()))
            .Returns(flatForRentAnnouncements);
            var result = await _repository.GetAllAsync();

            result.Should().BeEquivalentTo(flatForRentAnnouncements);
        }