示例#1
0
        public void ReturnCatalogItemCacheKey(
            int pageIndex,
            int itemPerPage,
            string culture,
            int?brandId,
            int?typeId,
            string searchText,
            NamesOrderBy?orderBy,
            Ordination order,
            string expectedResult,
            Type exceptionType = null
            )
        {
            var catalogPageFiltersViewModel = new CatalogPageFiltersViewModel()
            {
                PageId           = pageIndex,
                ItemsPerPage     = itemPerPage,
                Culture          = culture,
                BrandFilter      = brandId,
                TypesFilter      = typeId,
                SearchTextFilter = searchText,
                OrderBy          = orderBy,
                Order            = order
            };

            if (string.IsNullOrEmpty(expectedResult))
            {
                if (exceptionType == null)
                {
                    throw new Exception("Missing exception type to check");
                }
                Assert.Throws(
                    exceptionType,
                    () => CacheHelpers.GenerateCatalogItemCacheKey(catalogPageFiltersViewModel));
            }
            else
            {
                var result = CacheHelpers.GenerateCatalogItemCacheKey(catalogPageFiltersViewModel);

                Assert.Equal(expectedResult, result);
            }
        }
示例#2
0
        public CatalogFilterPaginatedSpecification(int skip, int take, string term, NamesOrderBy?orderBy, Ordination ordination, int?brandId, int?typeId)
            : base(brandId, typeId, term)
        {
            // return all if take == 0
            if (0 < take)
            {
                ApplyPaging(skip, take);
            }
            //ApplyOrderBy(i => i.Name);
            // if(!string.IsNullOrEmpty(orderBy)){
            //     Expression<Func<CatalogItem, object>> expr = x => x.GetType().GetProperty(orderBy).GetValue(x, null);
            //     ApplyOrderBy(expr);
            // }
            //var propertyInfo = (new CatalogItem()).GetType().GetProperty(orderBy, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            //ApplyOrderBy(x => propertyInfo.GetValue(x, null));
            //var x  = new CatalogItem();
            //var y = x.GetType().GetProperty("Name").Name;
            switch (orderBy)
            {
            case NamesOrderBy.Name:
                if (ordination == Ordination.ASC)
                {
                    ApplyOrderBy(x => x.Name);
                }
                else
                {
                    ApplyOrderByDescending(x => x.Name);
                };
                break;

            case NamesOrderBy.Price:
                if (ordination == Ordination.ASC)
                {
                    ApplyOrderBy(x => x.Price);
                }
                else
                {
                    ApplyOrderByDescending(x => x.Price);
                };
                break;
            }
        }