public void CheckShoppingBasketAddProductToBasket() { string[] args = { "Apple", "Milk", "Bread" }; var products = TestDataHelper.GetProductsBeansBreadMilkApple(); IBasketInputReader shoppingBasketInput = new BasketInputReader(); ShoppingBasket shoppingBasket = shoppingBasketInput.CreateBasketFromInput(args, products); Assert.IsTrue(shoppingBasket.GetItemCountById(products.GetProductByName("Apple").Id) == 1); Assert.IsTrue(shoppingBasket.GetItemCountById(products.GetProductByName("Milk").Id) == 1); Assert.IsTrue(shoppingBasket.GetItemCountById(products.GetProductByName("Bread").Id) == 1); Assert.IsTrue(products.GetProductByName("Not In Basket") == null); }
public string Process(string[] args) { // read input from user IBasketInputReader basketInputReader = new BasketInputReader(); ShoppingBasket shoppingBasket = basketInputReader.CreateBasketFromInput(args, _productsDL); // calculate snopping basket price IBasketCalculator basketCalculator = new BasketCalculator(_specialOffersDL); CalculatedPrice calculatedPrice = basketCalculator.CalculatePrice(shoppingBasket); // write output IBasketPriceWriter basketPriceWriter = new BasketPriceWriter(); return(basketPriceWriter.GetOutputString(calculatedPrice)); }
public void CheckNoProductToBuyIfNullThrowsNoProductToBuyException() { string input = "Not In Product"; string[] args = { input }; IBasketInputReader shoppingBasketInput = new BasketInputReader(); try { ShoppingBasket shoppingBasket = shoppingBasketInput.CreateBasketFromInput(args, null); Assert.Fail("Should have thrown InvalidProductArgumentException exception"); } catch (NoProductToBuyException ex) { Assert.IsTrue(ex.Message.ToLower().Contains("no products to purchase")); } }
public void CheckInvalidInputThrowsInvalidInputException() { string input = "Not In Product"; string[] args = { input }; var products = TestDataHelper.GetProductsBeansBreadMilkApple(); IBasketInputReader shoppingBasketInput = new BasketInputReader(); try { ShoppingBasket shoppingBasket = shoppingBasketInput.CreateBasketFromInput(args, products); Assert.Fail("Should have thrown InvalidProductArgumentException exception"); }catch (InvalidInputException ex) { Assert.IsTrue(ex.Message.ToLower().Contains(input.ToLower())); } }