Exemplo n.º 1
0
        static void Main()
        {
            Database ds = new Database();

            CheckoutKata.Checkout co = new CheckoutKata.Checkout(new Repository(ds));

            Console.WriteLine("Begin scanning items. Type 'Total' when complete");

            bool scanning = true;

            while (scanning)
            {
                var input = Console.ReadLine();

                if (input != "Total")
                {
                    co.Scan(input);
                }
                else
                {
                    scanning = false;

                    var totalprice = co.GetTotalPrice();
                    Console.WriteLine($"The total price is: {totalprice}");
                    Console.Read();
                }
            }
        }
 public CheckoutPricing()
 {
     subject = new Checkout(
         new ProductPricing("A", 50, 3, 20),
         new ProductPricing("B", 30, 2, 15),
         new ProductPricing("C", 20),
         new ProductPricing("D", 15));
 }
Exemplo n.º 3
0
        public void ScanNoItems_TotalIsZero()
        {
            // Arrange
            var checkout = new Checkout();

            // Act + Assert
            Assert.AreEqual(0, checkout.Total);
        }
Exemplo n.º 4
0
        public void CalculateTotal_NoItems_ReturnsZero()
        {
            var checkout = new Checkout(null);

            var total = checkout.CalculateTotal();

            total.Should().Be(0);
        }
Exemplo n.º 5
0
 public void SimpleCheckoutTests_Setup()
 {
     pricingRules = new PricingRules();
     pricingRules.Price("A", 10);
     pricingRules.Price("B", 20);
     pricingRules.MultibuyDiscount("A", 2, 15);
     checkout = new Checkout(pricingRules);
 }
Exemplo n.º 6
0
        public void ScanOneItem_TotalIsValueItem(char item, int total)
        {
            // Arrange
            var checkout = new Checkout();

            // Act
            checkout.Scan(item);

            // Assert
            Assert.AreEqual(total, checkout.Total);
        }
Exemplo n.º 7
0
        public void CalculateTotal_OneItem_ReturnsItemsValue()
        {
            var prices = GetPrices();

            var checkout = new Checkout(prices);
            checkout.Scan("A");

            var total = checkout.CalculateTotal();

            total.Should().Be(50);
        }
Exemplo n.º 8
0
        public void Setup()
        {
            var offers = new Offers(new List<Offer>
                {
                    new Offer{SKU = 'A', Frequency = 3, Discount = 20},
                    new Offer{SKU = 'B', Frequency = 2, Discount = 15}
                });
            var catalogue = new Catalogue(new Dictionary<char, int> {{'A', 50}, {'B', 30}, {'C', 20}, {'D', 15}});

            _checkout = new Checkout(offers, catalogue);
        }
Exemplo n.º 9
0
        public void CalulateTotal_ItemsThatDontQualifyForOffer_ShouldBeSummed()
        {
            var prices = GetPrices();

            var checkout = new Checkout(prices);
            checkout.Scan("A");
            checkout.Scan("A");

            var total = checkout.CalculateTotal();

            total.Should().Be(100);
        }
Exemplo n.º 10
0
        public CheckoutTests()
        {
            // arrange for all tests
            var prices = new List<PricingStrategy>() {
                new MultiStockPricing('A', 50, 3, 130),
                new MultiStockPricing('B', 30, 2, 45),
                new IndividualStockPricing('C', 20),
                new IndividualStockPricing('D', 15)
            };

            this.co = new Checkout(prices);
        }
Exemplo n.º 11
0
        public void CalculateTotal_TwoItems_ReturnsSumOfTwoItems()
        {
            var prices = GetPrices();

            var checkout = new Checkout(prices);
            checkout.Scan("A");
            checkout.Scan("B");

            var total = checkout.CalculateTotal();

            total.Should().Be(80);
        }
Exemplo n.º 12
0
        private void ScanMultipleItems(string items, int total)
        {
            // Arrange
            var checkout = new Checkout();

            // Act
            for (int i = 0; i < items.Length; i++)
            {
                checkout.Scan(items[i]);
            }

            // Assert
            Assert.AreEqual(total, checkout.Total);
        }
Exemplo n.º 13
0
        public void CalulateTotal_ItemsThatQualifyForOfferOfDifferentKinds_OfferShouldBeAppliedToBoth()
        {
            var prices = GetPrices();

            var checkout = new Checkout(prices);
            checkout.Scan("A");
            checkout.Scan("A");
            checkout.Scan("A");
            checkout.Scan("B");
            checkout.Scan("B");

            var total = checkout.CalculateTotal();

            total.Should().Be(175);
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            IList <ISpecialPrice> specialPrices = new List <ISpecialPrice>
            {
                new SpecialPrice(2, 2, 45),
                new SpecialPrice(1, 3, 130),
            };
            IList <Product> products = new List <Product>
            {
                new Product(1, "A", 50, specialPrices[1]),
                new Product(2, "B", 30, specialPrices[0]),
                new Product(3, "C", 10, null),
                new Product(4, "D", 20, null),
            };
            ICheckSpecialPrice specialPrice = new CheckSpecialPrice();

            ICheckout checkout = new Checkout(specialPrice);

            checkout.ScanItem(products[1]);
            checkout.ScanItem(products[1]);
            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[0]);

            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[0]);
            checkout.ScanItem(products[1]);
            var total = checkout.GetTotalPrice();



            Console.WriteLine("TOTAL IS: " + total);
        }
Exemplo n.º 15
0
 public void TestItemsThatDontExist()
 {
     Assert.AreEqual(0.00, Checkout.ProcessOrder("EFGH"));
 }
Exemplo n.º 16
0
 private void ScanItems(Checkout checkout, string items)
 {
     List<string> itemList = new List<string>(items.Split(','));
     itemList.ForEach(item => checkout.Scan(item));
 }
Exemplo n.º 17
0
        public void CalulateTotal_OneItemFromEachProduct_ReturnsSum()
        {
            var prices = GetPrices();

            var checkout = new Checkout(prices);
            checkout.Scan("C");
            checkout.Scan("D");
            checkout.Scan("B");
            checkout.Scan("A");

            var total = checkout.CalculateTotal();

            total.Should().Be(115);
        }
Exemplo n.º 18
0
 public void TestEmptyOrder()
 {
     Assert.AreEqual(0.00, Checkout.ProcessOrder(""));
 }
Exemplo n.º 19
0
 private static void OutputCheckoutCost(Checkout checkout)
 {
     Console.WriteLine("--- Current Cost: " + checkout.TotalBasketCost + " ---");
 }
Exemplo n.º 20
0
 public void TestItemDDiscount(string order, double expected)
 {
     Assert.AreEqual(expected, Checkout.ProcessOrder(order));
 }
Exemplo n.º 21
0
 public void TestMixedOrders(string order, double expected)
 {
     Assert.AreEqual(expected, Checkout.ProcessOrder(order));
 }
Exemplo n.º 22
0
 public void TestOneOfEachItem()
 {
     Assert.AreEqual(120, Checkout.ProcessOrder("ABCD"));
 }
Exemplo n.º 23
0
 public void SetUp()
 {
     _checkout = new Checkout();
 }