Esempio n. 1
0
        public void ProductController_Index_ShouldCallProductServiceSearch()
        {
            var productAdminSearchQuery = new ProductAdminSearchQuery();

            _productController.Index(productAdminSearchQuery);

            A.CallTo(() => _productService.Search(productAdminSearchQuery)).MustHaveHappened();
        }
Esempio n. 2
0
        public void ProductController_Index_ShouldReturnTheSearchQueryAsTheModel()
        {
            var productAdminSearchQuery = new ProductAdminSearchQuery();

            ViewResult viewResult = _productController.Index(productAdminSearchQuery);

            viewResult.Model.Should().Be(productAdminSearchQuery);
        }
Esempio n. 3
0
        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));
            }

            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));
            }

            if (!string.IsNullOrWhiteSpace(query.Name))
            {
                queryOver = queryOver.Where(x => x.Name.IsInsensitiveLike(query.Name, MatchMode.Anywhere));
            }

            var min = query.PriceFrom ?? 0;
            var max = query.PriceTo ?? int.MaxValue;

            queryOver = queryOver.WithSubquery.WhereExists(QueryOver.Of <ProductVariant>()
                                                           .Where(x => x.Product.Id == productAlias.Id && x.BasePrice >= min && x.BasePrice <= max)
                                                           .Select(x => x.Id));

            return(queryOver.OrderBy(product => product.Name).Asc.Paged(query.Page));
        }
        public ViewResult Index(ProductAdminSearchQuery searchQuery)
        {
            ViewData["publish-status"] = _productService.GetPublishStatusOptions();
            ViewData["results"]        = _productService.Search(searchQuery);
            var productContainer = _uniquePageService.GetUniquePage <ProductContainer>();

            ViewData["product-containerId"] = productContainer == null ? (int?)null : productContainer.Id;

            return(View(searchQuery));
        }
Esempio n. 5
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);
        }