コード例 #1
0
        public void Totals_Are_Using_Correct_Adjustment_Rates()
        {
            var calc = new RecipeCalculator();
            var receiptItems = calc.CreateRecipeReceipt(CreateRecipeTwo());
            var receiptTotals = calc.TotalCost(receiptItems);

            decimal beforeTax = receiptItems.FirstOrDefault(chicken => chicken.ProductId == 4).BeforeTaxTotal;
            decimal afterTax = calc.ApplySalesTax(beforeTax);
            var taxPercentageDifference = Math.Round((Math.Round((afterTax - beforeTax), 2) / beforeTax), 3) * 100;
            decimal beforeDiscount = receiptItems.FirstOrDefault(garlic => garlic.ProductId == 1).BeforeTaxTotal;
            decimal afterDiscount = calc.ApplyWellnessDiscount(beforeDiscount);
            var discountPercentageDifference = ((beforeDiscount - afterDiscount) / beforeDiscount) * 100;

            Assert.IsNotNull(receiptItems);
            Assert.IsNotNull(receiptTotals);
            Assert.AreNotEqual(0, receiptItems.Count);
            Assert.IsNotNull(discountPercentageDifference);
            Assert.AreEqual(WelnessDiscountRate, discountPercentageDifference);
            Assert.IsNotNull(taxPercentageDifference);
            Assert.AreEqual(TaxRate, taxPercentageDifference);

            //View receipt results in the Output pane.
            PrintReceiptToOutput(calc.CreateRecipeReceipt(CreateRecipeOne()), calc.TotalCost(calc.CreateRecipeReceipt(CreateRecipeOne())));
            PrintReceiptToOutput(calc.CreateRecipeReceipt(CreateRecipeTwo()), calc.TotalCost(calc.CreateRecipeReceipt(CreateRecipeTwo())));
            PrintReceiptToOutput(calc.CreateRecipeReceipt(CreateRecipeThree()), calc.TotalCost(calc.CreateRecipeReceipt(CreateRecipeThree())));
        }
コード例 #2
0
        public void Verify_Tax_Rate_Is_Correct()
        {
            var calc = new RecipeCalculator();
            var chicken = new IngredientBO()
            {
                Id = 1,
                ProductId = 4,
                Quantity = 17,
                RecipeId = 1,
                UnitType = Enums.UnitTypes.None
            };

            decimal beforeTax = calc.BeforeTaxPrice(chicken);
            decimal afterTax = calc.ApplySalesTax(beforeTax);
            var percentageDifference = Math.Round((Math.Round((afterTax - beforeTax), 2) / beforeTax), 3) * 100;

            Assert.IsNotNull(beforeTax);
            Assert.IsNotNull(afterTax);
            Assert.IsNotNull(percentageDifference);
            Assert.AreEqual(TaxRate, percentageDifference);
        }