Exemplo n.º 1
0
        public static ITaxCalcService CreateCalcService(double taxRate, double importDutyRate, IEnumerable <string> taxExemptProductTypeNames)
        {
            var exemptDiscriminatorService = new TaxExemptDiscriminatorService(taxExemptProductTypeNames);
            var taxCalcService             = new TaxCalcService(taxRate, importDutyRate, exemptDiscriminatorService);

            return(taxCalcService);
        }
        public void Initialize(IEnumerable <ITaxProviderSetting> settings)
        {
            _settings = settings.ToList();
            _logger   = new Logger(_settings.DebugLoggingEnabled());

            _taxCalcService = new TaxCalcService(_logger, _settings);
        }
Exemplo n.º 3
0
        public void CalculateTaxes_Input1_CD_150Tax_Test()
        {
            var expected         = 1.50d;
            var transactionItems = new List <ITransactionItem>
            {
                MockUtil.MockTransaction(1, "music CD", 14.99d, ProductType.Taxable, false),
            };
            var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);
            var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);

            var actual = sut.CalculateTaxes(transactionItems);

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 4
0
        public void CalculateTaxes_Input_multiple_Choc_NoTax_Test()
        {
            var expected         = 0.00d;
            var transactionItems = new List <ITransactionItem>
            {
                MockUtil.MockTransaction(10, "chocolate bar", 0.85d, ProductType.Food, false),
            };
            var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);
            var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);

            var actual = sut.CalculateTaxes(transactionItems);

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 5
0
        public void CalculateTaxes_Input2_Test()
        {
            var expected         = 7.65d;
            var transactionItems = new List <ITransactionItem>
            {
                MockUtil.MockTransaction(1, "box of chocolates", 10.00d, ProductType.Food, true),
                MockUtil.MockTransaction(1, "bottle of perfume", 47.50d, ProductType.Taxable, true),
            };
            var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);
            var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);

            var actual = sut.CalculateTaxes(transactionItems);

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 6
0
        public void CalculateTaxes_Input3_Test()
        {
            var expected         = 6.70;
            var transactionItems = new List <ITransactionItem>
            {
                MockUtil.MockTransaction(1, "bottle of perfume", 27.99d, ProductType.Taxable, true),
                MockUtil.MockTransaction(1, "bottle of perfume", 18.99d, ProductType.Taxable, false),
                MockUtil.MockTransaction(1, "packet of headache pills", 9.70d, ProductType.Medical, false),
                MockUtil.MockTransaction(1, "box of imported chocolates", 11.25d, ProductType.Food, true),
            };
            var mockDiscriminatorService = MockUtil.MockDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);
            var sut = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, mockDiscriminatorService);

            var actual = sut.CalculateTaxes(transactionItems);

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            var exemptDiscriminatorService = new TaxExemptDiscriminatorService(Settings.Config.TaxExemptProductTypeNames);
            var taxCalcService             = new TaxCalcService(Settings.Config.TaxRate, Settings.Config.ImportDutyRate, exemptDiscriminatorService);
            var salesTransaction           = new SalesTransaction(taxCalcService);

            Console.WriteLine("Problem: Sales Taxes");
            Console.WriteLine();

            var input = GetInput1Items1();

            WriteReceiptToConsole(input, salesTransaction, 1);

            input = GetInput1Items2();
            WriteReceiptToConsole(input, salesTransaction, 2);

            input = GetInput1Items3();
            WriteReceiptToConsole(input, salesTransaction, 3);
        }