public void ProductController_Index_ShouldCallProductServiceSearch() { var productAdminSearchQuery = new ProductAdminSearchQuery(); _productController.Index(productAdminSearchQuery); A.CallTo(() => _productService.Search(productAdminSearchQuery)).MustHaveHappened(); }
public void ProductController_Index_ShouldReturnTheSearchQueryAsTheModel() { var productAdminSearchQuery = new ProductAdminSearchQuery(); ViewResult viewResult = _productController.Index(productAdminSearchQuery); viewResult.Model.Should().Be(productAdminSearchQuery); }
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)); }
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); }