コード例 #1
0
        public void Test16_CalculateTotal_ScannedProductABCD_CalculateTotalEqual7_25()
        {
            // Arrange
            var             terminal          = new PointOfSaleTerminal();
            List <IProduct> productListActual = new List <IProduct>
            {
                new Product("A"),
                new Product("B"),
                new Product("C"),
                new Product("D")
            };

            terminal.SetProductList(productListActual);
            int ReturnValueForCodeA_priceSet = terminal.SetPricing("A", 1.25f, 3, 3.0f);
            int ReturnValueForCodeB_priceSet = terminal.SetPricing("B", 4.25f);
            int ReturnValueForCodeC_priceSet = terminal.SetPricing("C", 1.0f, 6, 5.0f);
            int ReturnValueForCodeD_priceSet = terminal.SetPricing("D", 0.75f);

            terminal.ScanProduct("A");
            terminal.ScanProduct("B");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");

            // Act
            float actualTotal = terminal.CalculateTotal();

            // Assert
            float expectedTotal = 7.25f;

            Assert.AreEqual(expectedTotal, actualTotal, "The calculated total is wrong and should be 7.25");
        }
コード例 #2
0
        public void Test12_ScanProduct_ScanProductProductWithCodeA_B_C_ScanProductReturn1_1_0()
        {
            // Arrange
            var             terminal          = new PointOfSaleTerminal();
            List <IProduct> productListActual = new List <IProduct>
            {
                new Product("A"),
                new Product("B")
            };

            terminal.SetProductList(productListActual);
            int testingValueForCodeA = terminal.SetPricing("A", 1.25f, 3, 3.0f);
            int testingValueForCodeB = terminal.SetPricing("B", 4.25f);

            // Act
            int actualProductAReturn = terminal.ScanProduct("A");
            int actualProductBReturn = terminal.ScanProduct("B");
            int actualProductCReturn = terminal.ScanProduct("C");// there is no C scanned

            // Assert
            int expectedProductAReturn = 1;
            int expectedProductBReturn = 1;
            int expectedProductCReturn = 0;// This is zero because there was no C scanned.

            Assert.AreEqual(expectedProductAReturn, actualProductAReturn, "Return value from ScanProduct('A') is wrong");
            Assert.AreEqual(expectedProductBReturn, actualProductBReturn, "Return value from ScanProduct('B') is wrong");
            Assert.AreEqual(expectedProductCReturn, actualProductCReturn, "Return value from ScanProduct('C') is wrong");
        }
コード例 #3
0
        public void A1LessFromCombination()
        {
            decimal expected = 2.50M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("A");
            terminal.ScanProduct("A");

            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #4
0
        public void EmptyWithUnknownCodes()
        {
            decimal expected = 0.00M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("");
            terminal.ScanProduct("F");
            terminal.ScanProduct("G");
            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #5
0
 public void Test1()
 {
     Assert.AreEqual(13.25M,
                     terminal.ScanProduct("A")
                     .ScanProduct("B")
                     .ScanProduct("C")
                     .ScanProduct("D")
                     .ScanProduct("A")
                     .ScanProduct("B")
                     .ScanProduct("A")
                     .CalculateTotal());
 }
コード例 #6
0
        public void UnknownStartWithValidCodes()
        {
            decimal expected = 2.75M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("F");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");
            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #7
0
        public void ABCD()
        {
            decimal expected = 7.25M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("A");
            terminal.ScanProduct("B");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");
            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #8
0
        public void ScanItemsInOrder_ABCD()
        {
            decimal expected = 7.25m;

            var terminal = new PointOfSaleTerminal();

            //terminal.SetPricing();
            terminal.ScanProduct("A");
            terminal.ScanProduct("B");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");

            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result, "Shopping cart not calculated the total correctly");
        }
コード例 #9
0
 public void TestProductNotFound()
 {
     Assert.Throws <ProductNotFoundException>(() =>
     {
         terminal.ScanProduct("A")
         .ScanProduct("B")
         .ScanProduct("C");
     }, "Product C does not exist");
 }
コード例 #10
0
        public void Terminal_Scan_Should_Return_Total(string scan_items, decimal expected_total)
        {
            foreach (char ch in scan_items)
            {
                _terminal.ScanProduct(ch.ToString());
            }

            Assert.AreEqual(expected_total, _terminal.CalculateTotal());
        }
コード例 #11
0
        public void SingleD()
        {
            decimal expected = 0.75M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("D");
            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #12
0
        public void TwoValidCodesInOneString()
        {
            decimal expected = 0.00M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("AA");
            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #13
0
        [Test] //Given input to check
        public void TotalPriceAfterDiscountForFourdifferentProduct()
        {
            //Arrange
            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             A           = new Product("A", 1, 1.25);
            Product             B           = new Product("B", 1, 4.25);
            Product             C           = new Product("C", 1, 1.00);
            Product             D           = new Product("D", 1, 0.75);

            //Act
            pointOfSale.ScanProduct(A);
            pointOfSale.ScanProduct(B);
            pointOfSale.ScanProduct(C);
            pointOfSale.ScanProduct(D);

            double result = pointOfSale.CalculateTotal();

            //Assert
            Assert.AreEqual(7.25, result);
        }
コード例 #14
0
        [Test] //Given input to check
        public void TotalPriceBeforeDiscountForDifferentOrMoreThanOneSameProduct()
        {
            //Arrange
            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             A           = new Product("A", 3, 1.25);
            Product             B           = new Product("B", 2, 4.25);
            Product             C           = new Product("C", 1, 1.00);
            Product             D           = new Product("D", 1, 0.75);

            //Act
            pointOfSale.ScanProduct(A);
            pointOfSale.ScanProduct(B);
            pointOfSale.ScanProduct(C);
            pointOfSale.ScanProduct(D);

            double result = pointOfSale.GetTotalPriceBeforeDiscount();

            //Assert
            Assert.AreEqual(14, result);
        }
コード例 #15
0
        public void TestForProductNotExist()
        {
            var terminal = new PointOfSaleTerminal();

            // Set default pricing for Products
            Utils.SetDefaultPricing(terminal);

            Assert.Throws <KeyNotFoundException>(
                () => terminal.ScanProduct("Undefined")
                );
        }
コード例 #16
0
        public void TestForNormalPriceAmount()
        {
            Console.WriteLine("### Point Of Sale Terminal Service UP ###");

            var terminal = new PointOfSaleTerminal();

            // Set default pricing for Products
            Utils.SetDefaultPricing(terminal);

            // Order without using BulkPrice
            terminal.ScanProduct("A");
            terminal.ScanProduct("B");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");

            var total = terminal.CalculateTotal();

            Console.WriteLine($"Amount of Random Order: {total}");

            Assert.Equal(7.25m, total);
        }
コード例 #17
0
        public void GetTotalValueForfourSameProductC()
        {
            //Arrange
            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             product     = new Product("C", 5, 1);

            //Act
            pointOfSale.ScanProduct(product);

            //Assert
            Assert.AreEqual(5, pointOfSale.DiscountForC("C"));
        }
コード例 #18
0
        public void ChangePriceOfD()
        {
            decimal expected = 1.00M;
            var     terminal = new PointOfSaleTerminal();

            terminal.SetPricing("D", 1.00);
            terminal.ScanProduct("D");

            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #19
0
        public void ItemIsAddedOnPointOfSaleTerminal()
        {
            //Arrange
            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             A           = new Product("A", 1, 1.25);

            //Act
            pointOfSale.ScanProduct(A);
            int result = pointOfSale.ItemCount();

            //Assert
            Assert.AreEqual(1, result);
        }
コード例 #20
0
        [Test] //Given input to check
        public void TotalPriceAfterDiscountForSevenSameProduct()
        {
            //Arrange
            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             C           = new Product("C", 7, 1);

            //Act
            pointOfSale.ScanProduct(C);
            double result = pointOfSale.CalculateTotal();

            //Assert
            Assert.AreEqual(6, result);
        }
コード例 #21
0
        [Test] //Given input to check
        public void TotalPriceBeforeDiscountForSevenSameProduct()
        {
            //Arrange
            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             C           = new Product("C", 7, 1);

            //Act
            pointOfSale.ScanProduct(C);
            double result = pointOfSale.GetTotalPriceBeforeDiscount();

            //Assert
            Assert.AreEqual(7, result);
        }
コード例 #22
0
        [Test] //
        public void GetTotalValueFoTwoSameProductA()
        {
            //Arrange

            PointOfSaleTerminal pointOfSale = new PointOfSaleTerminal();
            Product             product     = new Product("A", 2, 1.25);

            //Act
            pointOfSale.ScanProduct(product);

            //Assert

            Assert.AreEqual(2.5, pointOfSale.DiscountForA("A"));
        }
コード例 #23
0
        public void TestForAmountAfterPriceChange()
        {
            Console.WriteLine("### Point Of Sale Terminal Service UP ###");

            var terminal = new PointOfSaleTerminal();

            // Set default pricing for Products
            Utils.SetDefaultPricing(terminal);

            // Order without using BulkPrice
            terminal.ScanProduct("A");
            terminal.ScanProduct("B");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");

            // Change the price of Product 'B'
            terminal.SetPricing("B", "item", 5.00m, 0, 0);

            var total = terminal.CalculateTotal();

            Console.WriteLine($"Amount of Random Order: {total}");

            Assert.Equal(8.00m, total);
        }
コード例 #24
0
        public void TestSetPricing()
        {
            terminal.SetPricing('A', 1.25, Tuple.Create(3, 3.0));
            terminal.ScanProduct('A');

            var expectedTotal = 1.25;
            var actualTotal   = terminal.CalculateTotal();

            Assert.AreEqual(expectedTotal, actualTotal, delta: expectedTotal / 100);
        }
コード例 #25
0
        /// <summary>
        /// Runs the user input through the methods from the PointOfSaleTerminalLibrary
        /// </summary>
        /// <param name="input">The products to be scanned</param>
        /// <returns>Returns the total cost of the user input</returns>
        public decimal RunCode(String input)
        {
            String[] inputs = input.Split(',');

            PointOfSaleTerminal terminal = new PointOfSaleTerminal();

            terminal.SetPricing(1.25M, 4.25M, 1.00M, 0.75M);
            foreach (string v in inputs)
            {
                terminal.ScanProduct(v);
            }
            decimal result = terminal.CalculateTotal();

            savings = terminal.CalculateSavings();

            return(result);
        }
コード例 #26
0
ファイル: Program.cs プロジェクト: bagduch/voyagerExecrise
        static void Main(string[] args)
        {
            //init  singleton
            var terminal = new PointOfSaleTerminal();

            //singleton cart
            //var terminal = PointOfSaleTerminal.Instance();

            //add product code if Code not exit will print product not found, accept string or char
            terminal.ScanProduct("CCCCCCCCCCCC");

            //cacualte the result
            decimal result = (decimal)terminal.CaculateTotal();

            //write result to console
            Console.Write("${0:N2}", result);
        }
コード例 #27
0
        public void CCCCCCC()
        {
            decimal expected = 6.00M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #28
0
        public void ValidCodesWithUnknownsMixed()
        {
            decimal expected = 5.25M;
            var     terminal = new PointOfSaleTerminal();

            terminal.ScanProduct("A");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("D");
            terminal.ScanProduct("E");
            terminal.ScanProduct("A");

            decimal result = terminal.CalculateTotal();

            Assert.AreEqual(expected, result);
        }
コード例 #29
0
        public void TestForSequenceScanAmount()
        {
            Console.WriteLine("### Point Of Sale Terminal Service UP ###");

            var terminal = new PointOfSaleTerminal();

            // Set default pricing for Products
            Utils.SetDefaultPricing(terminal);

            // Sequence Order
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");
            terminal.ScanProduct("C");

            var total = terminal.CalculateTotal();

            Console.WriteLine($"Amount of Random Order: {total}");

            Assert.Equal(6.0m, total);
        }
コード例 #30
0
        public void CCCCCCC_Is_6()
        {
            _finalProduct = posTerm.ScanProduct("CCCCCCC");
            totalPrice    = pCalc.CalculateTotalPrice(_finalProduct);

            Assert.AreEqual(6, totalPrice);
        }