コード例 #1
0
        [TestCase(new[] { "10 imported bottles of whiskey at 27.99", "10 bottles of local whiskey at 18.99", "10 packets of iodine tablets at 9.75", "10 boxes of imported potato chips at 11.25" }, "10 imported bottles of whiskey: 321.88\n10 bottles of local whiskey: 208.89\n10 packets of iodine tablets: 97.50\n10 imported boxes of potato chips: 118.12\nSales Taxes: 66.59\nTotal: 746.40", TestName = "10 Bottles of Whiskey, 10 Bottles of Local Whiskey, 10 Packets of Iodine Tablets & 10 Boxes of Potato Chips (Test 4)", Category = "Mixed")] // Test 4
        public void PrintReceipt_OutputsExpectedResult(string[] input, string expectedResult)
        {
            // Arrange
            Sale     sale    = new Sale();
            IPrinter printer = new BasicPrinter();

            // Act
            foreach (string item in input)
            {
                sale.Add(item);
            }

            // Assert
            Assert.That(printer.PrintReceipt(sale), Is.EqualTo(expectedResult));
        }
コード例 #2
0
        private static void Main()
        {
            Sale sale = new Sale();

            Console.WriteLine("Enter sales in the format <qty> <description> at <unit price>\nFor example: 2 books at 13.25\nEntering a blank line completes the sale\n");
            string input = GetInput();

            while (!string.IsNullOrEmpty(input))
            {
                if (!sale.Add(input))
                {
                    Console.WriteLine("Sales should be in the format of <qty> <description> at <unit price>\nFor example: 2 books at 13.25");
                }
                input = GetInput();
            }

            IPrinter receiptPrinter = new BasicPrinter();

            Console.WriteLine(receiptPrinter.PrintReceipt(sale));
            Console.WriteLine("--- Press Enter to Finish ---");
            Console.ReadLine();
        }