Ejemplo n.º 1
0
        public Receipt Checkout()
        {
            var cart = _cartItemDataAccess.GetCart();

            cart.ForEach(orderProduct => _taxCalculatorDataAccess.ApplyTax(orderProduct));

            cart.ForEach(orderProduct => orderProduct.TotalAmount += orderProduct.ApplicableTaxes.Sum(t => t.TaxAmount));

            _cartItemDataAccess.SaveCart(cart);

            Receipt receipt = new Receipt()
            {
                Total    = cart.Sum(orderProduct => orderProduct.TotalAmount),
                TotalTax = cart.Sum(orderProduct => orderProduct.ApplicableTaxes.Sum(t => t.TaxAmount)),
            };

            AddLineItems(receipt, cart);
            AddTaxItems(receipt);

            return(receipt);
        }
Ejemplo n.º 2
0
        public void ApplyTax_BasicTax_ShouldCalculateTax()
        {
            _mockTaxSpecification.Setup(f => f.IsSatisfied(It.IsAny <Product>())).Returns(true);

            _mockCountryDefinitionService.Setup(f => f.GetCountry()).Returns(new Country()
            {
                Name     = "Canada",
                TaxBands = new List <TaxBand>()
                {
                    new TaxBand()
                    {
                        Percentage  = 10M,
                        ProductType = Infrastructure.Interfaces.Enum.ProductType.Default,
                        TaxType     = Infrastructure.Interfaces.Enum.TaxType.BasicSalesTax
                    }
                }
            });

            _mockTaxSpecification.As <ITaxableType>().SetupGet(x => x.TaxType).Returns(Infrastructure.Interfaces.Enum.TaxType.BasicSalesTax);

            OrderProduct orderProduct = new OrderProduct()
            {
                Product = new Product()
                {
                    CountryOfDelivery = "Canada",
                    Name        = "lollipop",
                    ProductType = Infrastructure.Interfaces.Enum.ProductType.Default,
                    UnitPrice   = 10.45M
                },
                Quantity       = 1,
                ExtendedAmount = 10.45M
            };

            _taxCalculatorService.ApplyTax(orderProduct);

            Assert.AreEqual(1, orderProduct.ApplicableTaxes.Count);
            Assert.AreEqual(1.05M, orderProduct.ApplicableTaxes[0].TaxAmount);
        }