private IBrewerRepository MockDataSource(SKUInfo skuInfo) { Fake().DocumentType <Brewer>(Brewer.CLASS_NAME); var brewer1 = TreeNode.New <Brewer>().With(x => { x.DocumentName = BREWER_TITLE1; x.SKU = skuInfo; }); var brewer2 = TreeNode.New <Brewer>().With(x => { x.DocumentName = BREWER_TITLE2; x.SKU = skuInfo; }); var repository = Substitute.For <IBrewerRepository>(); mFilter = Substitute.For <BrewerFilterViewModel>(); repository.GetBrewers(mFilter).Returns(new List <Brewer> { brewer1, brewer2 }); mFilter2 = Substitute.For <BrewerFilterViewModel>(); repository.GetBrewers(mFilter2).Returns(new List <Brewer> { brewer2 }); mFilter3 = Substitute.For <BrewerFilterViewModel>(); repository.GetBrewers(mFilter3).Returns(new List <Brewer>()); return(repository); }
public async Task <ActionResult> Filter(BrewerFilterViewModel model) { var parameters = new List <IQueryParameter> { new OrderParameter($"elements.{Brewer.ProductNameCodename}"), new ElementsParameter(Brewer.ImageCodename, Brewer.PriceCodename, Brewer.ProductStatusCodename, Brewer.ProductNameCodename, Brewer.UrlPatternCodename), new DepthParameter(0), new LanguageParameter(Language) }; var manufacturers = model.GetFilteredManufacturers().ToArray(); if (manufacturers.Any()) { parameters.Add(new AnyFilter($"elements.{Brewer.ManufacturerCodename}", manufacturers)); } var statusTypes = model.GetFilteredProductStatuses().ToArray(); if (statusTypes.Any()) { parameters.Add(new AnyFilter($"elements.{Brewer.ProductStatusCodename}", statusTypes)); } var response = await _client.GetItemsAsync <Brewer>(parameters); return(PartialView("ProductListing", response.Items)); }
public ActionResult Filter(BrewerFilterViewModel filter) { if (!Request.IsAjaxRequest()) { return(HttpNotFound()); } var items = GetFilteredBrewers(filter); return(PartialView("BrewersList", items)); }
public void GetWhereCondition_EmptyViewModel_EmptyWhereCondition() { var filter = new BrewerFilterViewModel(repository); filter.Load(); var where = filter.GetWhereCondition(); CMSAssert.All( () => Assert.IsNotNull(where), () => Assert.IsEmpty(where.ToString(true)) ); }
// GET: Brewers public ActionResult Index() { var item = GetFilteredBrewers(null); var filter = new BrewerFilterViewModel(mBrewerRepository); filter.Load(); var model = new ProductListViewModel { Filter = filter, Items = item }; return(View(model)); }
public void Load_FilterContainsCorrectPublicStatuses() { var filter = new BrewerFilterViewModel(repository); filter.Load(); var status1 = filter.Manufacturers.FirstOrDefault(checkbox => checkbox.Value == 1); var status2 = filter.Manufacturers.FirstOrDefault(checkbox => checkbox.Value == 2); CMSAssert.All( () => Assert.AreEqual(2, filter.PublicStatuses.Count), () => Assert.IsNotNull(status1), () => Assert.IsNotNull(status2) ); }
public void GetWhereCondition_SetupStatuses_CorrectRestrictionInWhereCondition() { var filter = new BrewerFilterViewModel(repository); filter.Load(); filter.PublicStatuses[0].IsChecked = true; filter.PublicStatuses[1].IsChecked = true; var where = filter.GetWhereCondition(); CMSAssert.All( () => Assert.IsNotNull(where), () => Assert.AreEqual("[SKUPublicStatusID] IN (1, 2)", where.ToString(true)) ); }
public void GetWhereCondition_SetUpOnlyInStock_CorrectRestrictionInWhereCondition() { var filter = new BrewerFilterViewModel(repository) { OnlyInStock = true }; filter.Load(); var where = filter.GetWhereCondition(); CMSAssert.All( () => Assert.IsNotNull(where), () => Assert.AreEqual("([SKUAvailableItems] > 0 OR [SKUAvailableItems] IS NULL)", where.ToString(true)) ); }
public void GetWhereCondition_SetupPrice_CorrectRestrictionInWhereCondition() { var filter = new BrewerFilterViewModel(repository); filter.Load(); filter.Prices[0].IsChecked = true; filter.Prices[1].IsChecked = false; filter.Prices[2].IsChecked = true; var where = filter.GetWhereCondition(); CMSAssert.All( () => Assert.IsNotNull(where), () => Assert.AreEqual("(([SKUPrice] >= 0 AND [SKUPrice] < 50) OR ([SKUPrice] >= 250 AND [SKUPrice] < 5000))", where.ToString(true)) ); }
public async Task <ActionResult> Filter(BrewerFilterViewModel model) { var parameters = new List <IQueryParameter> { new EqualsFilter("system.type", "brewer"), new OrderParameter("elements.product_name"), new ElementsParameter("image", "price", "product_status", "processing", "url_pattern"), new DepthParameter(0) }; var manufacturers = model.GetManufacturerFilters().ToArray(); if (manufacturers.Any()) { parameters.Add(new InFilter("elements.manufacturer", manufacturers)); } var response = await client.GetItemsAsync <Brewer>(parameters); return(PartialView("ProductListing", response.Items)); }
public void Load_FilterContainsCorrectPrices() { var filter = new BrewerFilterViewModel(repository); filter.Load(); var toFifty = filter.Prices.FirstOrDefault(checkbox => (int)BrewerPriceRangesEnum.ToFifty == checkbox.Value); var fromTwoHundredFiftyToFiveThousand = filter.Prices.FirstOrDefault(checkbox => (int)BrewerPriceRangesEnum.FromTwoHundredFiftyToFiveThousand == checkbox.Value); var fromFiftyToTwoHundredFifty = filter.Prices.FirstOrDefault(checkbox => (int)BrewerPriceRangesEnum.FromFiftyToTwoHundredFifty == checkbox.Value); CMSAssert.All( () => Assert.AreEqual(3, filter.Prices.Count), () => Assert.IsNotNull(toFifty), () => Assert.IsNotNull(fromTwoHundredFiftyToFiveThousand), () => Assert.IsNotNull(fromFiftyToTwoHundredFifty) ); }
public void GetWhereCondition_SetupFullFilter_ReturnsCorrectWhereCondition() { var filter = new BrewerFilterViewModel(repository); filter.Load(); filter.Manufacturers[0].IsChecked = true; filter.Manufacturers[1].IsChecked = true; filter.Prices[0].IsChecked = true; filter.Prices[1].IsChecked = true; filter.PublicStatuses[0].IsChecked = true; filter.PublicStatuses[1].IsChecked = true; filter.OnlyInStock = true; var where = filter.GetWhereCondition(); CMSAssert.All( () => Assert.IsNotNull(where), () => Assert.AreEqual("[SKUManufacturerID] IN (1, 2) AND (([SKUPrice] >= 0 AND [SKUPrice] < 50) OR ([SKUPrice] >= 50 AND [SKUPrice] < 250)) AND [SKUPublicStatusID] IN (1, 2) AND ([SKUAvailableItems] > 0 OR [SKUAvailableItems] IS NULL)", where.ToString(true)) ); }