public void AddToStoreList_BananIsAddedToList_AldiAnd8IsInTheList() { List<StoreAndPrice> list = new List<StoreAndPrice>(); var storeandprice = new StoreAndPrice(); storeandprice.Name = "Aldi"; storeandprice.Price = 8; list.Add(storeandprice); _findProduct.ProductName = "Banan"; _findProduct.User.FindStoresThatSellsProduct(_findProduct.ProductName).Returns(list); _findProduct.AddToStoreListCommand.Execute(this); Assert.That(_findProduct.StorePrice.Contains(storeandprice), Is.EqualTo(true)); }
public void ChangeItemToAnotherStores_ChangeFromLidlToAldiWhenItemExistInAldi_returns1() { StoreProductAndPrice storeProductAndPrice = new StoreProductAndPrice() {Price = 2, ProductName = "Test", Quantity = "2", StoreName = "Lidl"}; _uut.GeneratedShoppingListData.Add(storeProductAndPrice); ProductAndPrice productAndPrice = new ProductAndPrice() {Price = 3, Name = "Aldi"}; _unitWork.Stores.FindProductInStore("Aldi", storeProductAndPrice.ProductName).Returns(productAndPrice); List<StoreAndPrice> storeAndPriceList = new List<StoreAndPrice>(); StoreAndPrice storeAndPrice = new StoreAndPrice{Price = 6, Name = _store.StoreName}; storeAndPriceList.Add(storeAndPrice); _unitWork.Products.FindCheapestStoreForAllProductsWithSum(Arg.Any<List<ProductInfo>>()) .Returns(storeAndPriceList); _uut.ShoppingListData.Add(new ProductInfo(_product.ProductName, "2")); Assert.That(_uut.ChangeProductToAnotherStore("Aldi", storeProductAndPrice), Is.EqualTo(1)); }
public void FindCheapestStoreWithSumForListOfProducts_TwoProductsFromOneStore_ReturnsFaktaAsTheCheapestStore() { var testList = new List<ProductInfo>(); testList.Add(new ProductInfo(_product.ProductName, "2")); testList.Add(new ProductInfo("Tomat", "2")); testList.Add(new ProductInfo("Agurk", "2")); var returnList = new List<StoreAndPrice>(); var store1WithPrice = new StoreAndPrice() {Name = "Fakta", Price = 5}; var store1WithPrice2 = new StoreAndPrice() {Name = "Fakta", Price = 4}; var store2WithPrice = new StoreAndPrice() {Name = "Føtex", Price = 10}; returnList.Add(store1WithPrice); returnList.Add(store1WithPrice2); returnList.Add(store2WithPrice); _unitWork.Products.FindCheapestStoreForAllProductsWithSum(testList).Returns(returnList); Assert.That(_uut.FindCheapestStoreWithSumForListOfProducts(testList).Price, Is.EqualTo(9)); }
public void FindCheapestStoreWithSumForListOfProducts_OneProductInList_ReturnsTheCheapestStoreWithPrice() { var testList = new List<ProductInfo>(); testList.Add(new ProductInfo(_product.ProductName)); var returnList = new List<StoreAndPrice>(); var cheapestStoreWithPrice = new StoreAndPrice() {Name = "Fakta", Price = 20}; returnList.Add(cheapestStoreWithPrice); _unitWork.Products.FindCheapestStoreForAllProductsWithSum(testList).Returns(returnList); Assert.That(_uut.FindCheapestStoreWithSumForListOfProducts(testList).Price, Is.EqualTo(cheapestStoreWithPrice.Price)); }
public void CreateShoppingList_CreateShoppingListForBananAndBuyInFakta_YouSave0Kr() { _uut.ShoppingListData.Add(new ProductInfo(_product.ProductName)); _uut.OptionsStores.Add(new StoresInPristjek("Fakta")); List<StoreAndPrice> storeAndPriceList = new List<StoreAndPrice>(); StoreAndPrice storeAndPrice = new StoreAndPrice(); storeAndPrice.Price = 1.95; storeAndPrice.Name = "fakta"; storeAndPriceList.Add(storeAndPrice); _unitWork.Products.FindCheapestStoreForAllProductsWithSum(Arg.Any<List<ProductInfo>>()) .Returns(storeAndPriceList); var fakta = new Store() {StoreName = "Fakta"}; _unitWork.Products.FindProduct(_product.ProductName).Returns(_product); _product.HasARelation.Add(new HasA() {Price = 2.95, Store = _store}); _product.HasARelation.Add(new HasA() {Price = 1.95, Store = fakta}); _store.HasARelation.Add(new HasA() {Price = 2.95, Product = _product, Store = _store}); fakta.HasARelation.Add(new HasA() {Price = 1.95, Product = _product, Store = fakta}); _uut.CreateShoppingList(); Assert.That(_uut.MoneySaved, Is.EqualTo(double.Parse("0,00", new CultureInfo("da-DK")).ToString("F2") + " kr")); }
/// <summary> /// Find the cheapest Store with sum that sells all the products in a list /// </summary> /// <param name="products"></param> /// <returns>The store and the sum of all the products in the list</returns> public StoreAndPrice FindCheapestStoreWithSumForListOfProducts(List<ProductInfo> products) { var cheapestStore = new StoreAndPrice {Price = double.MaxValue}; var list = _unit.Products.FindCheapestStoreForAllProductsWithSum(products); if (list == null || list.Count == 0) return null; var name = list[0].Name; double sum = 0; foreach (var item in list) { if (item.Name == name) { sum += item.Price; } else { if (cheapestStore.Price > sum) cheapestStore = new StoreAndPrice {Name = name, Price = sum}; name = item.Name; sum = item.Price; } } if (name == list[list.Count - 1].Name && cheapestStore.Price > sum) cheapestStore = new StoreAndPrice {Name = name, Price = sum}; return cheapestStore; }