public void ItemPrice_MaxPriceConditionOnly_DoesItemStandInFilter_No_ShouldPass() { filterByPrice = new FilterByPrice(null, 20); item.Price = 20.1; Assert.IsFalse(filterByPrice.DoesItemStandInFilter(item)); }
public void Setup() { inMemoryConnection = DbConnectionFactory.CreateTransient(); using var context = new MarketDbContext(inMemoryConnection); context.Init(); filterStoreRank = new FilterByStoreRank(4); filterByItemRank = new FilterByItemRank(3); filterByPrice = new FilterByPrice(5, 20.66); RegisteredUser owner = new RegisteredUser("OWNER", new byte[] { }); context.Users.Add(owner); Guid Owner = owner.ID; Guid storeID = Guid.NewGuid(); store = new Store(storeID, DataForTests.CreateTestContactDetails(), new PurchasePolicy(storeID), new DiscountPolicy(storeID), Owner, context); context.Stores.Add(store); HashSet <Category> categories = new HashSet <Category>() { new Category("cat1"), new Category("cat2") }; context.Categories.AddRange(categories); item = new Item(Guid.NewGuid(), store.Id, "name ", 2, categories, 3.55); context.Items.Add(item); context.SaveChanges(); }
public void ItemPrice_MinPriceConditionOnly_DoesItemStandInFilter_No_ShouldPass() { filterByPrice = new FilterByPrice(5.75, null); item.Price = 5.70; Assert.IsFalse(filterByPrice.DoesItemStandInFilter(item)); }
public void SearchItems_ByName_PriceFilter_ShouldPass() { using var context = new MarketDbContext(inMemoryConnection); Store[] stores = DataForTests.CreateStoresForSearchTests(storeHandler, context); SearchFilter priceFilter = new FilterByPrice(null, 20.4); List <SearchFilter> filters = new List <SearchFilter>() { priceFilter }; Dictionary <Guid, ReadOnlyCollection <Item> > results = storeHandler.SearchItems(context: context, name: "item one", filters: filters); Assert.AreEqual(2, results.Keys.Count); ReadOnlyCollection <Item> resultStore = results[stores[0].Id]; ReadOnlyCollection <Item> resultStore1 = results[stores[1].Id]; Assert.AreEqual("item one", resultStore[0].Name); Assert.AreEqual("item one", resultStore1[0].Name); Assert.AreEqual(1, resultStore.Count); Assert.AreEqual(1, resultStore1.Count); }
public void SearchItems_ByCategoryAndKeywords_WithItemRankFilterAndPriceFilter_ShouldPass() { using var context = new MarketDbContext(inMemoryConnection); List <Item> items = SetUpInventoryForSearchTests(context); items[4].Rank = 3.5; items[5].Rank = 8; SearchFilter rankFilter = new FilterByItemRank(2); SearchFilter priceFilter = new FilterByPrice(13, null); List <SearchFilter> filters = new List <SearchFilter>() { rankFilter, priceFilter }; List <string> keywordsForSearch = new List <string>() { "word1" }; ReadOnlyCollection <Item> results = storeInventory.SearchItems(context: context, category: "cat1", keywords: keywordsForSearch, itemFilters: filters); Assert.AreEqual(1, results.Count); Assert.IsTrue(results.Contains(items[5])); }
/// <summary> /// Search for items in store by the "And" of following params: /// name (if provided) & /// category (if provided) & /// keywords (if provided) & /// standing in filters (if provided) /// </summary> /// <param name="name"></param> /// <param name="category"></param> /// <param name="keywords"></param> /// <param name="filters"></param> /// <returns>dictionary of <storeID, reaonly collection of items></storeID> if there are, otherwise empty dictionary</returns> public Dictionary <Guid, ReadOnlyCollection <Item> > SearchItems( MarketDbContext context, double?filterItemRank, double?filterMinPrice, double?filterMaxPrice, double?filterStoreRank, string name = null, string category = null, List <string> keywords = null ) { List <SearchFilter> filters = new List <SearchFilter>(); if (filterItemRank is double itemRank) { Logger.writeEvent(string.Format("SearchFacade: Filtering by Item Rank- {0}", itemRank)); FilterByItemRank fItemRank = new FilterByItemRank(itemRank); filters.Add(fItemRank); } if (filterMinPrice.HasValue || filterMaxPrice.HasValue) // if at least one has a value there is a filter price { Logger.writeEvent(string.Format("SearchFacade: Filtering by price, Max- {0} Min- {1}", filterMaxPrice.HasValue ? string.Format("N2", filterMaxPrice) : "None", filterMinPrice.HasValue ? string.Format("N2", filterMinPrice) : "None")); FilterByPrice fPrice = new FilterByPrice(filterMinPrice, filterMaxPrice); filters.Add(fPrice); } if (filterStoreRank is double storeRank) { Logger.writeEvent(string.Format("SearchFacade: Filtering by Store Rank- {0}", storeRank)); FilterByStoreRank fStoreRank = new FilterByStoreRank(storeRank); filters.Add(fStoreRank); } if (filters.Count == 0) { filters = null; } Dictionary <Guid, ReadOnlyCollection <Item> > results = storeHandler.SearchItems(context, name: name, category: category, keywords: keywords, filters: filters); if (name != null && results.Keys.Count == 0) { Logger.writeEvent(string.Format("SearchFacade: No results found, trying to fix spelling of \'{0}\'", name)); string tryRepairName = TryCorrectNameBySpellChecking(name); if (!tryRepairName.Equals(name)) { results = storeHandler.SearchItems(context, name: tryRepairName, category: category, keywords: keywords, filters: filters); } } return(results); }
public void SearchItems_AllSearchConds_NotStandsInPriceFilter_ShouldPass() { using var context = new MarketDbContext(inMemoryConnection); List <Item> items = SetUpInventoryForSearchTests(context); SearchFilter priceFilter = new FilterByPrice(22, null); List <SearchFilter> filters = new List <SearchFilter>() { priceFilter }; List <string> keywordsForSearch = new List <string>() { "word3", "word2" }; ReadOnlyCollection <Item> results = storeInventory.SearchItems(context: context, name: "item5", category: "cat2", keywords: keywordsForSearch, itemFilters: filters); Assert.AreEqual(0, results.Count); }
public void SearchItems_ByCategory_WithPriceFilter_NoSuchItems_ShouldFail() { using var context = new MarketDbContext(inMemoryConnection); Store[] stores = DataForTests.CreateStoresForSearchTests(storeHandler, context); SearchFilter priceFilter = new FilterByPrice(null, 3); List <SearchFilter> filters = new List <SearchFilter>() { priceFilter }; Dictionary <Guid, ReadOnlyCollection <Item> > results = searchFacade.SearchItems(context: context, filterItemRank: null, filterMinPrice: null, filterMaxPrice: 3, filterStoreRank: null, category: "cat2"); Assert.AreEqual(0, results.Keys.Count); }
public void ItemPrice_MaxPriceConditionOnly_DoesItemStandInFilter_Yes_ShouldPass() { filterByPrice = new FilterByPrice(null, 20); Assert.IsTrue(filterByPrice.DoesItemStandInFilter(item)); }