Esempio n. 1
0
        public void CheckAddProductsAddsProducts()
        {
            //  Arrange
            GroceriesBasket basket = new GroceriesBasket();

            //  Act
            basket.AddProducts(new List <IProduct>()
            {
                new Product(It.IsAny <string>(), It.IsAny <decimal>(), ProductType.Bread),
                new Product(It.IsAny <string>(), It.IsAny <decimal>(), ProductType.Butter)
            });

            //  Assert
            Assert.Equal(2, basket.ProductsList.Count);
        }
Esempio n. 2
0
        public void CheckCalculateCalculateCostsCalculatesCorrectly(int buttersQty, int milksQty, int breadsQty, decimal finalCost)
        {
            //  Arrange
            IPromoRepository   promoRepository   = new PromoRepository();
            IProductRepository productRepository = new ProductRepository();
            List <IPromo>      testPromosList    = new List <IPromo>()
            {
                promoRepository.GetPromoOne(), promoRepository.GetPromoTwo()
            };
            List <IProduct>  testProductsList = productRepository.GetProducts(buttersQty, milksQty, breadsQty);
            IGroceriesBasket basket           = new GroceriesBasket();

            basket.AddProducts(testProductsList);
            ICostCalculator costCalculator = new CostCalculator(basket, testPromosList);

            //  Act
            costCalculator.CalculateCosts();

            //  Assert that all the involved Costs are as they should be
            Assert.Equal(testProductsList.Sum(product => product.Price), costCalculator.TotalCost);                                 //  Total Cost of the Items
            Assert.Equal(testPromosList.Sum(promo => promo.CalculateDeduction(testProductsList)), costCalculator.PromosDeductions); //  Total Deductions from the applied Promos
            Assert.Equal(finalCost, costCalculator.FinalCost);                                                                      //  Final Cost
        }