コード例 #1
0
        public void ProductController_Index_ShouldReturnTheSearchQueryAsTheModel()
        {
            var productAdminSearchQuery = new ProductAdminSearchQuery();

            ViewResult viewResult = _productController.Index(productAdminSearchQuery);

            viewResult.Model.Should().Be(productAdminSearchQuery);
        }
コード例 #2
0
        public void ProductController_Index_ShouldCallProductServiceSearch()
        {
            var productAdminSearchQuery = new ProductAdminSearchQuery();

            _productController.Index(productAdminSearchQuery);

            A.CallTo(() => _productService.Search(productAdminSearchQuery)).MustHaveHappened();
        }
コード例 #3
0
        public void ProductController_Index_ShouldReturnTheSearchResultInViewData()
        {
            var pagedList = new ProductPagedList(new StaticPagedList<Product>(new List<Product>(), 1, 1, 0), 1);
            var productAdminSearchQuery = new ProductAdminSearchQuery();
            A.CallTo(() => _productService.Search(productAdminSearchQuery)).Returns(pagedList);

            ViewResult viewResult = _productController.Index(productAdminSearchQuery);

            viewResult.ViewData["results"].Should().Be(pagedList);
        }
コード例 #4
0
ファイル: ProductService.cs プロジェクト: neozhu/Ecommerce
        public IPagedList<Product> Search(ProductAdminSearchQuery query)
        {
            Product productAlias = null;

            var queryOver = _session.QueryOver(()=> productAlias);

            switch (query.PublishStatus)
            {
                case PublishStatus.Unpublished:
                    queryOver = queryOver.Where(product => product.PublishOn == null || product.PublishOn > CurrentRequestData.Now);
                    break;
                case PublishStatus.Published:
                    queryOver = queryOver.Where(product => product.PublishOn != null && product.PublishOn <= CurrentRequestData.Now);
                    break;
            }

            if (!string.IsNullOrWhiteSpace(query.Brand))
            {
                Brand brandAlias = null;
                queryOver = queryOver.JoinAlias(product => product.BrandPage, () => brandAlias)
                    .Where(() => brandAlias.Name.IsInsensitiveLike(query.Brand, MatchMode.Anywhere));
            }

            if (!string.IsNullOrWhiteSpace(query.CategoryName))
            {
                Product categoryProductAlias = null;
                queryOver =
                    queryOver.WithSubquery.WhereExists(
                        QueryOver.Of<Category>()
                            .JoinAlias(category => category.Products, () => categoryProductAlias)
                            .Where(
                                x =>
                                    x.Name.IsInsensitiveLike(query.CategoryName, MatchMode.Anywhere) &&
                                    categoryProductAlias.Id == productAlias.Id)
                            .Select(x => x.Id));
                //queryOver = queryOver.JoinAlias(product => product.Categories, () => categoryAlias)
                //    .Where(() => categoryAlias.Name.IsInsensitiveLike(query.CategoryName, MatchMode.Anywhere));
            }

            if (!string.IsNullOrWhiteSpace(query.SKU))
            {
                queryOver =
                    queryOver.WithSubquery.WhereExists(
                        QueryOver.Of<ProductVariant>()
                            .Where(
                                x =>
                                    x.Product.Id == productAlias.Id &&
                                    x.SKU.IsInsensitiveLike(query.SKU, MatchMode.Anywhere)).Select(x => x.Id));
                //queryOver = queryOver.JoinAlias(product => product.Variants, () => productVariantAlias)
                //    .Where(() => productVariantAlias.SKU.IsInsensitiveLike(query.SKU, MatchMode.Anywhere));
            }

            return queryOver.OrderBy(product => product.Name).Asc.Paged(query.Page);
        }