Exemple #1
0
        private decimal ScanItems(int count, DiscountCard discountCard)
        {
            var terminal = new Terminal(new ProductsPriceSetBuilder().AddProduct(DefaultProductCode.ToString(), 1000.0M).ToArray());

            ScanStringAsChars(terminal, new string(DefaultProductCode, count));
            return(terminal.CalculateTotal(discountCard));
        }
Exemple #2
0
        static void Main(string[] args)
        {
            ITerminal terminal = new Terminal();

            terminal.SetPricing("string");
            terminal.ScanDiscountCard("1");

            var data = new string[] { "A", "A", "A", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "D", "D", "D", "D" };

            for (int i = 0; i < data.Length; i++)
            {
                terminal.Scan(data[i]);
            }

            //for (int i = 0; i < 6; i++)
            //    terminal.Scan("A");
            //for (int i = 0; i < 200; i++)
            //    terminal.Scan("B");
            //for (int i = 0; i < 30; i++)
            //    terminal.Scan("C");
            //for (int i = 0; i < 22; i++)
            //    terminal.Scan("D");

            var amountPurchase = terminal.CalculateTotal();
        }
        public void CalculateTotal_WithVolumeDiscount_ReturnsTotalPrice()
        {
            var terminal = new Terminal(GetCatalog());

            terminal.ScanAll("AAA");

            Assert.Equal(3, terminal.CalculateTotal());
        }
        public void CalculateTotal_ExistingProducts_ReturnsTotalPrice(string productSequence, decimal totalPrice)
        {
            var terminal = new Terminal(GetCatalog());

            terminal.ScanAll(productSequence);

            Assert.Equal(totalPrice, terminal.CalculateTotal());
        }
        public void ScanDiscountCard_AfterAddingProducts_ReturnsReducedPrice()
        {
            var terminal = new Terminal(GetCatalog());

            terminal.ScanAll("BBBB");
            terminal.Scan(new DiscountCard(1000));

            Assert.Equal((decimal)16.83, terminal.CalculateTotal());
        }
        public void ScanDiscountCard_AddProductsWithVolumeDiscount_ReturnsVolumePrice()
        {
            var terminal = new Terminal(GetCatalog());

            terminal.Scan(new DiscountCard(1000));
            terminal.ScanAll("CCCCCCC");

            Assert.Equal((decimal)5.99, terminal.CalculateTotal());
        }
        public void Checkout_ExistingProducts_FinishesSale()
        {
            var terminal = new Terminal(GetCatalog());

            terminal.ScanAll("ABA");

            Assert.Equal((decimal)6.75, terminal.Checkout());
            Assert.Equal(0, terminal.CalculateTotal());
        }
Exemple #8
0
        public void TestCalculation(string[] inputData, double expectedResult)
        {
            // Arrange
            foreach (var item in inputData)
            {
                terminal.Scan(item);
            }

            // Act
            var result = terminal.CalculateTotal();

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
Exemple #9
0
        public void ScanProductsSequence_WithDefaultPricesSet_CorrectTotalValue(string productCodes, decimal expectedResult)
        {
            ProductsPriceSetBuilder productsPriceSetBuilder = new ProductsPriceSetBuilder();

            productsPriceSetBuilder.AddProduct("A", 1.25M, 3, 3.0M);
            productsPriceSetBuilder.AddProduct("B", 4.25M);
            productsPriceSetBuilder.AddProduct("C", 1.0M, 6, 5.0M);
            productsPriceSetBuilder.AddProduct("D", 0.75M);

            IEnumerable <Product> products = productsPriceSetBuilder.GetAllProducts();

            var terminal = new Terminal(products);

            ScanStringAsChars(terminal, productCodes);

            Assert.Equal(expectedResult, terminal.CalculateTotal());
        }