Exemplo n.º 1
0
        public async Task <CollectionOutputQuery <FlatForRentAnnouncementOutputQuery> > HandleAsync(GetFlatForRentAnnouncementsInputQuery inputQuery,
                                                                                                    CancellationToken cancellationToken = default)
        {
            List <FlatForRentAnnouncement> flatForRentAnnouncements;
            long totalCount;

            if (inputQuery != null)
            {
                var findTask = _flatForRentAnnouncementRepository.FindAsync(inputQuery.Page,
                                                                            inputQuery.PageSize, inputQuery.Sort, inputQuery.CityId, inputQuery.CreatedFrom, inputQuery.CreatedTo, inputQuery.PriceFrom,
                                                                            inputQuery.PriceTo, inputQuery.CityDistrict, inputQuery.NumberOfRooms);
                totalCount = await _flatForRentAnnouncementRepository.CountAsync(inputQuery.CityId, inputQuery.CreatedFrom,
                                                                                 inputQuery.CreatedTo, inputQuery.PriceFrom, inputQuery.PriceTo, inputQuery.CityDistrict, inputQuery.NumberOfRooms);

                flatForRentAnnouncements = await findTask;
            }
            else
            {
                var getAllTask = _flatForRentAnnouncementRepository.GetAllAsync();
                totalCount = await _flatForRentAnnouncementRepository.CountAsync();

                flatForRentAnnouncements = await getAllTask;
            }

            var results = _mapper.Map <List <FlatForRentAnnouncement>, IEnumerable <FlatForRentAnnouncementOutputQuery> >(flatForRentAnnouncements);

            return(new CollectionOutputQuery <FlatForRentAnnouncementOutputQuery>(totalCount, results));
        }
Exemplo n.º 2
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);
        }