Beispiel #1
0
        public void Checkout_get_total_price_bulk_matching_offer_mixed_items_at_checkout()
        {
            // Setup
            ICheckout checkout          = new CheckoutController(productInventory);
            Product   inventoryProductA = productInventory.Get("A");
            MultiDeal multiDealA        = inventoryProductA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(inventoryProductA);
            }
            Product   inventoryProductB = productInventory.Get("B");
            MultiDeal multiDealB        = inventoryProductB.MultiDeal;

            for (int i = 0; i < multiDealB.Units; i++)
            {
                checkout.Scan(inventoryProductB);
            }
            int expectedPrice = multiDealA.MultiDealPrice + multiDealB.MultiDealPrice;

            // Act
            int actualTotalPrice = checkout.GetTotalPrice();

            // Assert
            Assert.AreEqual(expectedPrice, actualTotalPrice);
        }
Beispiel #2
0
        public void Checkout_get_total_price_at_complete_checkout()
        {
            // Setup
            ICheckout checkout   = new CheckoutController(productInventory);
            Product   productA   = productInventory.Get("A");
            MultiDeal multiDealA = productA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(productA);
            }
            checkout.Scan(productA);
            Product   productB   = productInventory.Get("B");
            MultiDeal multiDealB = productB.MultiDeal;

            for (int i = 0; i < multiDealB.Units; i++)
            {
                checkout.Scan(productB);
            }
            checkout.Scan(productB);
            int expectedPrice = multiDealA.MultiDealPrice + productA.Price + multiDealB.MultiDealPrice + productB.Price;

            // Act
            int actualTotalPrice = checkout.CompleteCheckout();

            // Assert
            Assert.AreEqual(expectedPrice, actualTotalPrice);
        }
Beispiel #3
0
        public void MultiDeal_check_price_validation()
        {
            // Setup
            // Act
            // Assert
            try
            {
                MultiDeal multiDeal = new MultiDeal(10, 0, lastWeek, nextWeek);
                Assert.Fail("Fail: price can't be less than one, '0' given.");
            }
            catch
            {
                // Test passes.
            }

            try
            {
                MultiDeal multiDeal = new MultiDeal(10, -1, lastWeek, nextWeek);
                Assert.Fail("Fail: price can't be less than one, '-1' given.");
            }
            catch
            {
                // Test passes.
            }
        }
Beispiel #4
0
        public void Checkout_get_total_price_bulk_matching_offer_same_item_at_checkout_inc_offer_change()
        {
            // Setup
            ICheckout checkout          = new CheckoutController(productInventory);
            string    testSku           = "A";
            Product   inventoryProductA = productInventory.Get(testSku);
            MultiDeal multiDealA        = inventoryProductA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(inventoryProductA);
            }
            int       newDealUnits = multiDealA.Units - 1;
            int       newDealPrice = multiDealA.MultiDealPrice * 3;
            int       numOfMatchingDealsAfterChange       = checkout.Count(testSku) / newDealUnits;
            int       numberOfMiscProductsAfterDealChange = checkout.Count(testSku) % newDealUnits;
            int       newExpectedPrice = (newDealPrice * numOfMatchingDealsAfterChange) + (inventoryProductA.Price * numberOfMiscProductsAfterDealChange);
            MultiDeal newMultiDeal     = new MultiDeal(newDealUnits, newDealPrice, multiDealA.ValidFromDate, multiDealA.ValidBeforeDate);

            // Act
            int totalPriceBeforeChange = checkout.GetTotalPrice();

            Assert.AreEqual(multiDealA.MultiDealPrice, totalPriceBeforeChange);
            // Change inventory multiDeal
            productInventory.Replace(new Product(testSku, inventoryProductA.Price, newMultiDeal));
            int totalPriceAfterChange = checkout.GetTotalPrice();

            // Assert
            // prove that offer change is reflected
            Assert.AreNotEqual(totalPriceBeforeChange, totalPriceAfterChange);
            Assert.AreEqual(newExpectedPrice, totalPriceAfterChange);
        }
Beispiel #5
0
        public void MultiDeal_check_units_validation()
        {
            // Setup
            TimeSpan interval = new TimeSpan(2, 0, 0, 0);
            DateTime lastWeek = DateTime.Now.Subtract(interval);
            DateTime nextWeek = DateTime.Now.Add(interval);

            // Act
            // Assert
            try
            {
                MultiDeal multiDeal = new MultiDeal(0, 10, lastWeek, nextWeek);
                Assert.Fail("Fail: units can't be less than one, '0' given.");
            }
            catch
            {
                // Test passes.
            }

            try
            {
                MultiDeal multiDeal = new MultiDeal(-1, 10, lastWeek, nextWeek);
                Assert.Fail("Fail: units can't be less than one, '-1' given.");
            }
            catch
            {
                // Test passes.
            }
        }
Beispiel #6
0
        public void MultiDeal_check_before_date_validation()
        {
            // Setup
            DateTime nextWeekMinus2Days = lastWeek.Subtract(interval);

            // Act
            // Assert
            try
            {
                MultiDeal multiDeal = new MultiDeal(10, 10, nextWeek, nextWeek);
                Assert.Fail($"Fail: before date must be greater than from date, {nextWeek.ToString()} is the same as {nextWeek.ToString()}.");
            }
            catch
            {
                // Test passes.
            }

            try
            {
                MultiDeal multiDeal = new MultiDeal(10, 10, nextWeek, nextWeekMinus2Days);
                Assert.Fail($"Fail: before date must be greater than from date, {nextWeekMinus2Days} is less than {nextWeek.ToString()}.");
            }
            catch
            {
                // Test passes.
            }
        }
Beispiel #7
0
        public void MultiDeal_check_from_date_validation()
        {
            // Setup
            DateTime lastWeekPlusADay = lastWeek.AddDays(1);

            // Act
            // Assert
            try
            {
                MultiDeal multiDeal = new MultiDeal(10, 10, lastWeek, lastWeek);
                Assert.Fail($"Fail: from date must be less than before date, {lastWeek.ToString()} is the same as {lastWeek.ToString()}.");
            }
            catch
            {
                // Test passes.
            }

            try
            {
                MultiDeal multiDeal = new MultiDeal(10, 10, lastWeekPlusADay, lastWeek);
                Assert.Fail($"Fail: from date must be less than before date, {lastWeekPlusADay} is greater than {lastWeek.ToString()}.");
            }
            catch
            {
                // Test passes.
            }
        }
Beispiel #8
0
        public void Checkout_get_total_price_bulk_matching_offer_same_item_at_checkout()
        {
            // Setup
            ICheckout checkout          = new CheckoutController(productInventory);
            Product   inventoryProductA = productInventory.Get("A");
            int       priceA            = inventoryProductA.Price;
            MultiDeal multiDealA        = inventoryProductA.MultiDeal;

            for (int i = 0; i < multiDealA.Units; i++)
            {
                checkout.Scan(inventoryProductA);
            }

            // Act
            int totalPrice = checkout.GetTotalPrice();

            // Assert
            Assert.AreEqual(multiDealA.MultiDealPrice, totalPrice);
        }
Beispiel #9
0
        public void Product_check_product_offer_is_valid_test()
        {
            // Setup
            TimeSpan interval = new TimeSpan(2, 0, 0, 0);
            DateTime lastWeek = DateTime.Now.Subtract(interval);
            DateTime nextWeek = DateTime.Now.Add(interval);
            DateTime now      = DateTime.Now;

            // A valid MultiDeal (for now)
            MultiDeal multiDeal = new MultiDeal(3, 130, lastWeek, nextWeek);

            Product product_1 = new Product("A", 50, multiDeal);
            Product product_2 = new Product("A", 50, new MultiDeal());

            // Act
            // Assert
            Assert.IsTrue(product_1.IsMultiDealValid(now));
            Assert.IsFalse(product_2.IsMultiDealValid(now));

            // Invalid current times for valid MultiDeal
            Assert.IsFalse(product_1.IsMultiDealValid(lastWeek.Subtract(interval)));
            Assert.IsFalse(product_1.IsMultiDealValid(nextWeek.Add(interval)));
        }
Beispiel #10
0
        public void Checkout_scanned_products_reset_at_complete_checkout()
        {
            // Setup
            ICheckout checkout   = new CheckoutController(productInventory);
            Product   productA   = productInventory.Get("A");
            MultiDeal multiDealA = productA.MultiDeal;

            for (int i = 0; i < 10; i++)
            {
                checkout.Scan(productA);
            }
            int expectedCountBeforeCheckout = 10;
            int expectedCountAfterCheckout  = 0;
            int actualCountBeforeCheckout   = checkout.CountAll();

            // Act
            checkout.CompleteCheckout();
            int actualCountAfterCheckout = checkout.CountAll();

            // Assert
            Assert.AreNotEqual(expectedCountBeforeCheckout, expectedCountAfterCheckout);
            Assert.AreEqual(expectedCountBeforeCheckout, actualCountBeforeCheckout);
            Assert.AreEqual(expectedCountAfterCheckout, actualCountAfterCheckout);
        }