Пример #1
0
        public void Order_Should_Total_Correctly_With_Tax_And_Shipping_Set()
        {
            Order order = _orderService.GetCurrentOrder("testuser");

            //each product is $10
            order.AddItem(_catalogService.GetProduct(1), 1);
            order.AddItem(_catalogService.GetProduct(2), 1);
            order.AddItem(_catalogService.GetProduct(3), 1);
            Assert.AreEqual(30, order.SubTotal);

            //set the shipping address to HI, US
            //the test repo has this at 5%
            order.ShippingAddress = new Address("testuser", "first", "last", "email",
                                                "street1", "street2", "city", "HI", "94510", "US");

            IShippingRepository rep = new TestShippingRepository();
            ISalesTaxService    tax = new RegionalSalesTaxService(new TestTaxRepository());

            //each item in testrepo is 5 pounds
            var methods = rep.GetRates(order).ToList();

            //the first method is 10/pound
            //15 pounds at 10/pound == $150
            order.ShippingMethod = methods[0];
            Assert.AreEqual(150, order.ShippingMethod.Cost);

            //tax is 5% of taxable goods
            //30 * .05 is 1.5
            order.TaxAmount = tax.CalculateTaxAmount(order);
            Assert.AreEqual(1.5M, order.TaxAmount);

            //the total should be 30 + 150 + 1.5 = 181.5
            Assert.AreEqual(181.5M, order.Total);
        }
Пример #2
0
        public void Order_Should_Total_Correctly_With_Tax_And_Shipping_Set()
        {
            Order order = _orderService.GetCurrentOrder("testuser");

            //each product is $10
            order.AddItem(_catalogService.GetProduct(1), 1);
            order.AddItem(_catalogService.GetProduct(2), 1);
            order.AddItem(_catalogService.GetProduct(3), 1);
            Assert.AreEqual(30, order.SubTotal);
            
            //set the shipping address to HI, US
            //the test repo has this at 5% 
            order.ShippingAddress = new Address("testuser", "first", "last", "email",
                "street1", "street2", "city", "HI", "94510", "US");
            
            IShippingRepository rep = new TestShippingRepository();
            ISalesTaxService tax = new RegionalSalesTaxService(new TestTaxRepository());

            //each item in testrepo is 5 pounds
            var methods = rep.GetRates(order).ToList();

            //the first method is 10/pound
            //15 pounds at 10/pound == $150
            order.ShippingMethod = methods[0];
            Assert.AreEqual(150, order.ShippingMethod.Cost);

            //tax is 5% of taxable goods
            //30 * .05 is 1.5
            order.TaxAmount = tax.CalculateTaxAmount(order);
            Assert.AreEqual(1.5M, order.TaxAmount);

            //the total should be 30 + 150 + 1.5 = 181.5
            Assert.AreEqual(181.5M, order.Total);

        }