Esempio n. 1
0
        public void Get_Discounted_Total_With_Group_Sale_Promotion()
        {
            //Arrange
            Sale sale = new Sale();

            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });


            sale.ApplyPromotion(new GroupSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has group-sale", 3, 2m));


            //Act
            decimal total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(2.00m, total);


            // Reassign
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            //Act
            total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(4.00m, total);


            // Reassign
            sale.ClearPromotions();
            sale.ApplyPromotion(new GroupSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has group-sale", 10, 2m));

            //Act
            total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(5.00m, total);
        }
Esempio n. 2
0
        public void Get_Discounted_Total_With_Additional_Sale_Promotion()
        {
            //Arrange
            Sale sale = new Sale();

            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });


            sale.ApplyPromotion(new AdditionalSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has buy one get one free sale", 1, 0f));


            //Act
            decimal total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(3.00m, total);



            //Rearrange
            sale.AddProduct(new Product()
            {
                Id = "Banana", Price = 1.00m
            });

            //Act
            total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(3.00m, total);



            //Rearrange
            sale.ClearPromotions();
            sale.ApplyPromotion(new AdditionalSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has buy one get 50% off free sale", 1, 0.5f));

            //Act
            total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(4.50m, total);



            //Rearrange
            sale.ClearPromotions();
            sale.ApplyPromotion(new AdditionalSalePromotion("Banana", DateTime.Now.AddMonths(-6), DateTime.Now.AddMonths(6), "Banana has buy two get one 50% off sale", 2, 0.5f));

            //Act
            total = sale.CreateReceipt().GetTotalPayment();

            //Assert
            Assert.AreEqual(5.00m, total);
        }