예제 #1
0
        public void RoundingRules_FromInput3()
        {
            var purchaseInput = new List <string>()
            {
                "1 imported bottle of perfume at 27.99 1",
                "1 bottle of perfume at 18.99",
                "1 packet of headache pills at 9.75",
                "1 box of imported chocolates at 11.25",
            };

            var factory        = new MerchandiseFactory();
            var merchandises   = factory.Create(new InputReader(purchaseInput));
            var availableTaxes = new List <ITax>
            {
                new SalesTax(new Exemptions()),
                new ImportTax()
            };


            var output = new StringBuilder();
            var saved  = Console.Out;

            try
            {
                using (var writer = new StringWriter(output))
                {
                    Console.SetOut(writer);

                    var processor = new PurchaseProcessor(new Purchase(merchandises), availableTaxes);
                    processor.PrintReceipt();

                    string expected = "Sales Taxes: 6.70 Total: 74.68";
                    var    text     = output.ToString();
                    Assert.IsTrue(text.Contains(expected));
                }
            }
            finally
            {
                Console.SetOut(saved);
            }
        }
예제 #2
0
        public void RoundingRules_FromInput2()
        {
            var purchaseInput = new List <string>()
            {
                "1 imported box of chocolates at 10.00",
                "1 imported bottle of perfume at 47.50"
            };

            var factory        = new MerchandiseFactory();
            var merchandises   = factory.Create(new InputReader(purchaseInput));
            var availableTaxes = new List <ITax>
            {
                new SalesTax(new Exemptions()),
                new ImportTax()
            };


            var output = new StringBuilder();
            var saved  = Console.Out;

            try
            {
                using (var writer = new StringWriter(output))
                {
                    Console.SetOut(writer);

                    var processor = new PurchaseProcessor(new Purchase(merchandises), availableTaxes);
                    processor.PrintReceipt();

                    string expected = "Sales Taxes: 7.65 Total: 65.15";
                    var    text     = output.ToString();
                    Assert.IsTrue(text.Contains(expected));
                }
            }
            finally
            {
                Console.SetOut(saved);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("       Sales Taxes Problem         ");
            Console.WriteLine("-----------------------------------");


            while (true)
            {
                char selection     = SelectInput();
                var  purchaseInput = GetInput(selection);

                if (purchaseInput is null)
                {
                    return;
                }
                var factory      = new MerchandiseFactory();
                var merchandises = factory.Create(new InputReader(purchaseInput));

                var availableTaxes = new List <ITax>
                {
                    new SalesTax(new Exemptions()),
                    new ImportTax()
                };

                var processor = new PurchaseProcessor(new Purchase(merchandises), availableTaxes);
                processor.PrintReceipt();

                Console.WriteLine("-----------------------------------");
                Console.WriteLine();
            }


            //Console.WriteLine(">> Press ENTER to quit.");
            //Console.ReadLine();
        }