Exemplo n.º 1
0
        public void BasketService_WhenWeightedProductAddedToBasketMatchingPriceWeight_TotalPriceEqualsWeightPrice()
        {
            var basket = new BasketService(mockProductRepository.Object);

            basket.AddWeightedProduct(banana.Barcode, 1);

            Assert.Equal(banana.Price, basket.GetTotal());
        }
Exemplo n.º 2
0
        public void BasketService_WhenWeightedProductAddedToBasketMoreThanWeightPrice_TotalPriceIsMoreThanWeightPrice()
        {
            var basket = new BasketService(mockProductRepository.Object);

            basket.AddWeightedProduct(sweets.Barcode, 300);

            Assert.Equal(sweets.Price * 3, basket.GetTotal());
            Assert.True(sweets.Price < basket.GetTotal());
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var repository = new MockProductRepository();
            var basket     = new BasketService(repository);

            Console.WriteLine("Scanning Products");

            Console.WriteLine("Adding 3 apples to basket...");
            basket.AddProduct(appleBarcode, 3);

            Console.WriteLine("Adding 5 oranges to basket...");
            basket.AddProduct(orangeBarcode, 5);

            Console.WriteLine("Adding 2lbs of bananas to basket...");
            basket.AddWeightedProduct(bananaBarcode, 2);

            Console.WriteLine($"Basket Total: £{basket.GetTotal()}");

            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
Exemplo n.º 4
0
        public void BasketService_WhenMultipleItemsAddedToBasket_TotalPriceIsCalculatedCorrectly()
        {
            var basket = new BasketService(mockProductRepository.Object);

            basket.AddProduct(apple.Barcode, 3);
            basket.AddProduct(orange.Barcode, 5);
            basket.AddWeightedProduct(banana.Barcode, 2);

            /*
             *  3 apples =          £1.50,
             *  5 oranges
             *  --> 1 offer         £1.00
             *  --> 2 orange        £0.90
             *  6 bananas           £4.00 (2 X £2 per lb)
             *  expected total      £7.40
             */

            var expectedResult = (decimal)7.40;

            Assert.Equal(expectedResult, basket.GetTotal());
        }