示例#1
0
        public async Task <PropertySearchResult> SearchPropertiesAsync(PropertySearchCriteria criteria)
        {
            var result = AbstractTypeFactory <PropertySearchResult> .TryCreateInstance();

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var sortInfos = BuildSortExpression(criteria);
                var query     = BuildQuery(repository, criteria);

                result.TotalCount = await query.CountAsync();

                if (criteria.Take > 0)
                {
                    var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                              .Select(x => x.Id)
                              .Skip(criteria.Skip).Take(criteria.Take)
                              .AsNoTracking()
                              .ToArrayAsync();

                    result.Results = (await _propertyService.GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                }
            }
            return(result);
        }
示例#2
0
        public GenericSearchResult <Property> SearchProperties(PropertySearchCriteria criteria)
        {
            var result = new GenericSearchResult <Property>();

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var query = repository.Properties;
                if (!string.IsNullOrEmpty(criteria.CatalogId))
                {
                    query = query.Where(x => x.CatalogId == criteria.CatalogId);
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Name.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }
                query             = query.OrderBySortInfos(sortInfos);
                result.TotalCount = query.Count();
                var ids = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToList();

                var properties = _propertyService.GetByIds(ids);
                result.Results = properties.OrderBy(x => ids.IndexOf(x.Id)).ToList();
            }
            return(result);
        }
        public PropertySearchCriteria GetPropertySearchCriteria(string methodName)
        {
            string rentOrBuy      = TestCasesParser.GetValueOf(SearchForApartmentsColumns.RentOrBuy, methodName, GetType().Name);
            string propertyType   = TestCasesParser.GetValueOf(SearchForApartmentsColumns.PropertyType, methodName, GetType().Name);
            string propertyName   = TestCasesParser.GetValueOf(SearchForApartmentsColumns.PropertyName, methodName, GetType().Name);
            string propertyPeriod = TestCasesParser.GetValueOf(SearchForApartmentsColumns.PropertyPeriod, methodName, GetType().Name);
            string minPrice       = TestCasesParser.GetValueOf(SearchForApartmentsColumns.MinPrice, methodName, GetType().Name);
            string maxPrice       = TestCasesParser.GetValueOf(SearchForApartmentsColumns.MaxPrice, methodName, GetType().Name);
            string minArea        = TestCasesParser.GetValueOf(SearchForApartmentsColumns.MinArea, methodName, GetType().Name);
            string maxArea        = TestCasesParser.GetValueOf(SearchForApartmentsColumns.MaxArea, methodName, GetType().Name);
            string minBed         = TestCasesParser.GetValueOf(SearchForApartmentsColumns.MinBed, methodName, GetType().Name);
            string maxBed         = TestCasesParser.GetValueOf(SearchForApartmentsColumns.MaxBed, methodName, GetType().Name);
            string furnishing     = TestCasesParser.GetValueOf(SearchForApartmentsColumns.Furnishing, methodName, GetType().Name);
            string keywords       = TestCasesParser.GetValueOf(SearchForApartmentsColumns.Keywords, methodName, GetType().Name);

            PropertySearchCriteria criteria = new PropertySearchCriteria();

            criteria.RentOrBuy      = rentOrBuy;
            criteria.PropertyType   = propertyType;
            criteria.PropertyName   = propertyName;
            criteria.PropertyPeriod = propertyPeriod;
            criteria.MinPrice       = minPrice;
            criteria.MaxPrice       = maxPrice;
            criteria.MinArea        = minArea;
            criteria.MaxArea        = maxArea;
            criteria.MinBed         = minBed;
            criteria.MaxBed         = maxBed;
            criteria.Furnishing     = furnishing;
            criteria.Keywords       = keywords;

            return(criteria);
        }
示例#4
0
        protected virtual IList <SortInfo> BuildSortExpression(PropertySearchCriteria criteria)
        {
            var sortInfos = criteria.SortInfos;

            if (sortInfos.IsNullOrEmpty())
            {
                sortInfos = new[]
                {
                    new SortInfo {
                        SortColumn = nameof(PropertyEntity.Name)
                    }
                };
            }
            return(sortInfos);
        }
        public void ShouldSearchForApartmentLeastExpensiveWithTwoBeds()
        {
            //Prepare the data
            PropertySearchCriteria criteria = GetPropertySearchCriteria(TestContext.CurrentContext.Test.MethodName);
            HomePage     homePage           = new HomePage();
            PropertyPage propertyPage       = new PropertyPage();

            //actions
            homePage.FillPropertyCriteria(criteria);
            homePage.SelectlastSearchResult();
            string actualBedRooms = propertyPage.GetBedRooms();

            //verifications
            Assert.AreEqual("The bed rooms number is not correct", criteria.MinBed, actualBedRooms);
        }
示例#6
0
        public async Task <PropertySearchResult> SearchPropertiesAsync(PropertySearchCriteria criteria)
        {
            var result = AbstractTypeFactory <PropertySearchResult> .TryCreateInstance();

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var query = repository.Properties;
                if (!string.IsNullOrEmpty(criteria.CatalogId))
                {
                    query = query.Where(x => x.CatalogId == criteria.CatalogId);
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Name.Contains(criteria.Keyword));
                }
                if (!criteria.PropertyNames.IsNullOrEmpty())
                {
                    query = query.Where(x => criteria.PropertyNames.Contains(x.Name));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }
                query             = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);
                result.TotalCount = await query.CountAsync();

                if (criteria.Take > 0)
                {
                    var ids = await query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToListAsync();

                    var properties = await _propertyService.GetByIdsAsync(ids);

                    result.Results = properties.OrderBy(x => ids.IndexOf(x.Id)).ToList();
                }
            }
            return(result);
        }
        public void FillPropertyCriteria(PropertySearchCriteria criteria)
        {
            if (!string.IsNullOrEmpty(criteria.RentOrBuy))
            {
                BuyOrRentSelector().ClickOnIt("Buy or Rent selector");
                IReadOnlyCollection <IWebElement> elements = BuyOrRent();
                Utilities.Utilities.SelectElementInList(elements, criteria.RentOrBuy);
            }

            if (!string.IsNullOrEmpty(criteria.PropertyName))
            {
                PropertyName().EnterText(criteria.PropertyName, "Property Name");
                PropertyName().SendKeys(Keys.Enter);
            }
            if (!string.IsNullOrEmpty(criteria.PropertyType))
            {
                PropertyTypeSelector().ClickOnIt("Property type selector");
                IReadOnlyCollection <IWebElement> elements = PropertyType();
                Utilities.Utilities.SelectElementInList(elements, criteria.PropertyType);
            }
            if (!string.IsNullOrEmpty(criteria.PropertyPeriod))
            {
                PropertyPeriodSelector().ClickOnIt("Property Period Selector");
                IReadOnlyCollection <IWebElement> elements = PropertyPeriod();
                Utilities.Utilities.SelectElementInList(elements, criteria.PropertyPeriod);
            }
            if (!string.IsNullOrEmpty(criteria.MinPrice))
            {
                MinPriceSelector().ClickOnIt("Min Price Selector");
                IReadOnlyCollection <IWebElement> elements = MinPrice();
                Utilities.Utilities.SelectElementInList(elements, criteria.MinPrice);
            }
            if (!string.IsNullOrEmpty(criteria.MaxPrice))
            {
                MaxPriceSelector().ClickOnIt("Max Price Selector");
                IReadOnlyCollection <IWebElement> elements = MaxPrice();
                Utilities.Utilities.SelectElementInList(elements, criteria.MaxPrice);
            }
            if (!string.IsNullOrEmpty(criteria.MinBed))
            {
                MinBedSelector().ClickOnIt("Min Bed Selector");
                IReadOnlyCollection <IWebElement> elements = MinBed();
                Utilities.Utilities.SelectElementInList(elements, criteria.MinBed);
            }
            if (!string.IsNullOrEmpty(criteria.MaxBed))
            {
                MaxBedSelector().ClickOnIt("Max Bed Selector");
                IReadOnlyCollection <IWebElement> elements = MaxBed();
                Utilities.Utilities.SelectElementInList(elements, criteria.MaxBed);
            }
            if (!string.IsNullOrEmpty(criteria.MinArea))
            {
                MinAreaSelector().ClickOnIt("Min Area Selector");
                IReadOnlyCollection <IWebElement> elements = MinArea();
                Utilities.Utilities.SelectElementInList(elements, criteria.MinArea);
            }
            if (!string.IsNullOrEmpty(criteria.MaxArea))
            {
                MaxAreaSelector().ClickOnIt("Max Area Selector");
                IReadOnlyCollection <IWebElement> elements = MaxArea();
                Utilities.Utilities.SelectElementInList(elements, criteria.MaxArea);
            }
            if (!string.IsNullOrEmpty(criteria.Furnishing))
            {
                FurnishingSelector().ClickOnIt("Furnishing Selector");
                IReadOnlyCollection <IWebElement> elements = Furnishing();
                Utilities.Utilities.SelectElementInList(elements, criteria.Furnishing);
            }
            if (!string.IsNullOrEmpty(criteria.Keywords))
            {
                Keywords().EnterText(criteria.Keywords, "Keywords");
            }

            SelectSearch();
        }
示例#8
0
        protected virtual IQueryable <PropertyEntity> BuildQuery(ICatalogRepository repository, PropertySearchCriteria criteria)
        {
            var query = repository.Properties;

            if (!criteria.CatalogIds.IsNullOrEmpty())
            {
                query = query.Where(x => criteria.CatalogIds.Contains(x.CatalogId));
            }
            if (!string.IsNullOrEmpty(criteria.Keyword))
            {
                query = query.Where(x => x.Name.Contains(criteria.Keyword));
            }
            if (!criteria.PropertyNames.IsNullOrEmpty())
            {
                query = query.Where(x => criteria.PropertyNames.Contains(x.Name));
            }
            return(query);
        }
示例#9
0
 public PropertySearchCriteriaBuilder()
 {
     _searchCriteria = AbstractTypeFactory <PropertySearchCriteria> .TryCreateInstance();
 }