Customer.Project.Domain.Entities.Product.GetPriceWithTax C# (CSharp) Метод

GetPriceWithTax() публичный Метод

public GetPriceWithTax ( ITaxCalculator calculator ) : decimal
calculator ITaxCalculator
Результат decimal
        public virtual decimal GetPriceWithTax(ITaxCalculator calculator)
        {
            decimal price = 0;
            if (calculator != null)
            {
             price = calculator.GetTax(RawPrice) + RawPrice;
            }
            return price;
        }

Usage Example

Пример #1
0
        public void GetTax()
        {
            //Initialize our product
            Product myProduct = new Product { IdOfEntity = 1, Name = "Simple Product", RawPrice = 25.0M };

            //Create a mock with Moq
            Mock<ITaxCalculator> fakeTaxCalculator = new Mock<ITaxCalculator>();

            // make sure to return 5$ of tax for a 25$ product
            fakeTaxCalculator.Setup(tax => tax.GetTax(25.0M)).Returns(5.0M);

            // Retrived the calculated tax
            decimal calculatedTax = 0;
            calculatedTax = myProduct.GetPriceWithTax(fakeTaxCalculator.Object);

            // Verify that the "GetTax" method was called from  the interface
            fakeTaxCalculator.Verify(tax => tax.GetTax(25.0M));

            // Retrived the calculated tax
            calculatedTax = myProduct.GetPriceWithTax(fakeTaxCalculator.Object);

            // Make sure that the taxes were calculated
            Assert.AreEqual(calculatedTax, 30.0M);
        }