コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: AppMain.cs プロジェクト: leemorgale/PriceCalculator
        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));
        }
コード例 #3
0
        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"));
            }
        }
コード例 #4
0
        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()));
            }
        }