Exemplo n.º 1
0
 public Item(Country saleCountry, Article article, int quantity, Tax tax)
 {
     _tax = tax;
     Id   = article.Id;
     Name = article.Name;
     UnitPriceBeforeTaxes = article.Price;
     TotalPriceAfterTaxes = _tax.ApplyTo(quantity * article.Price);
     Quantity             = quantity;
     IsImported           = saleCountry != article.SupplierCountry;
 }
        public void Tax20ShouldIncreasePriceAfterTax()
        {
            Product product = Product.Sample;

            Tax tax = new Tax(20);

            AffectPriceResult result = tax.ApplyTo(product.Price);

            string expected = "Product price reported as $20.25 before tax and $24.30 after 20% tax";

            Assert.AreEqual(expected, result.DescribeWith(product, tax));
        }
        public void NoneTaxShouldNotAffectPrice()
        {
            Product product = Product.Sample;

            Tax tax = Tax.None;

            AffectPriceResult result = tax.ApplyTo(product.Price);

            string expected = "Product price reported as $20.25 before tax and $20.25 after 0% tax";

            Assert.AreEqual(expected, result.DescribeWith(product, tax));
        }
        public void Tax20Discount15ShouldAffectPriceAfterTax()
        {
            Product product = Product.Sample;

            Tax tax = new Tax(20);

            AffectPriceResult taxResult = tax.ApplyTo(product.Price);

            Discount discount = new Discount(15);

            AffectPriceResult discountResult = discount.ApplyTo(product.Price);

            Amount priceAfterAll = product.Price + taxResult.AffectedAmount - discountResult.AffectedAmount;

            Assert.AreEqual("20%", tax.ToString());
            Assert.AreEqual("$4.05", taxResult.AffectedAmount.ToString());

            Assert.AreEqual("15%", discount.ToString());
            Assert.AreEqual("$3.04", discountResult.AffectedAmount.ToString());

            Assert.AreEqual("$21.26", priceAfterAll.ToString());
        }
Exemplo n.º 5
0
        private static void CheckReceiptTaxedPrice(int n, IReadOnlyList <Category> categories, Country supplierCountry, Country checkoutCountry, Tax expectedTax)
        {
            var     catalog       = new Catalog();
            var     checkout      = new Checkout(checkoutCountry, catalog, new TaxEngine());
            decimal nonTaxedPrice = 0;

            Enumerable.Range(1, n)
            .ForEach(x =>
            {
                var category = categories[x % categories.Count];
                var name     = Guid.NewGuid().ToString();
                var price    = x;
                var article  = new Article(x, supplierCountry, category, name, price);
                catalog.TryAdd(article);
                var quantity = x;
                var origin   = checkoutCountry == supplierCountry ? Origin.Local : Origin.Imported;
                var good     = new Good(article.Name, quantity, price, origin);
                checkout.Scan(good);
                nonTaxedPrice += x * x;
            });
            Assert.Equal(expectedTax.ApplyTo(nonTaxedPrice), checkout.EmitReceipt().Total);
        }
Exemplo n.º 6
0
 public void IncreaseQuantity(int quantity)
 {
     Quantity            += quantity;
     TotalPriceAfterTaxes = _tax.ApplyTo(Quantity * UnitPriceBeforeTaxes);
 }