コード例 #1
0
        public void Should_ThrowException_When_CreatingInvoiceWithNullProductList()
        {
            // Arrange
            var orderInvoiceManager = new OrderInvoiceManager();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => orderInvoiceManager.CreateInvoice(null));
        }
コード例 #2
0
        public void Should_ThrowException_When_CreatingInvoiceWithEmptyProductList()
        {
            // Arrange
            var orderInvoiceManager = new OrderInvoiceManager();

            // Act & Assert
            var exception = Assert.Throws <ArgumentException>(() => orderInvoiceManager.CreateInvoice(new List <Product>(0)));

            Assert.Equal("Value cannot be an empty collection.\r\nParameter name: products", exception.Message);
        }
コード例 #3
0
        public void Should_ReturnExpectedAmounts_When_CalculatingTaxes(List <Product> products, decimal expectedTaxAmount, decimal expectedTotalAmount)
        {
            // Arrange
            var orderInvoiceManager = new OrderInvoiceManager();
            var orderInvoice        = orderInvoiceManager.CreateInvoice(products);

            // Act
            var totalTaxes  = orderInvoiceManager.GetTotalTaxes(orderInvoice);
            var totalAmount = orderInvoiceManager.GetTotalAmount(orderInvoice);

            // Assert
            Assert.Equal(expectedTaxAmount, totalTaxes);
            Assert.Equal(expectedTotalAmount, totalAmount);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: SimoneDalka/SalesTax
        static void Main(string[] args)
        {
            Console.WriteLine("INPUT:");

            var i = 1;

            foreach (var productList in InputOrders)
            {
                Console.WriteLine();
                Console.WriteLine($"Input {i++}:");

                foreach (var productString in productList)
                {
                    Console.WriteLine(productString);
                }
            }

            i = 1;

            Console.WriteLine();
            Console.WriteLine("OUTPUT:");

            using (new CultureOverride(CultureInfo.InvariantCulture))
            {
                foreach (var productList in InputOrders)
                {
                    Console.WriteLine();
                    Console.WriteLine($"Output {i++}:");

                    var productParser       = new ProductParser();
                    var orderInvoiceManager = new OrderInvoiceManager();

                    var orderInvoice = orderInvoiceManager.CreateInvoice(productParser.ParseAll(productList));

                    foreach (var computedProduct in orderInvoice.Products)
                    {
                        Console.WriteLine(computedProduct);
                    }

                    Console.WriteLine($"Sales Taxes: {orderInvoiceManager.GetTotalTaxes(orderInvoice).ToString("0.00")}");
                    Console.WriteLine($"Total: {orderInvoiceManager.GetTotalAmount(orderInvoice).ToString("0.00")}");
                }

                Console.WriteLine();
                Console.Write("Press any key to exit...");

                Console.ReadLine();
            }
        }
コード例 #5
0
        public void Should_ReturnExpectedAmounts_When_CalculatingTaxes(Product product, decimal expectedTaxAmount, decimal expectedAmount)
        {
            // Arrange
            var orderInvoiceManager = new OrderInvoiceManager();

            // Act
            var orderInvoice = orderInvoiceManager.CreateInvoice(new List <Product> {
                product
            });

            // Assert
            var computedProduct = orderInvoice.Products[0];

            Assert.Equal(expectedTaxAmount, computedProduct.TaxAmount);
            Assert.Equal(expectedAmount, computedProduct.Amount);
        }
コード例 #6
0
        public void Should_ReturnExpectedString_When_PrintingComputedProduct(string productInput, string expectedOutput)
        {
            using (new CultureOverride(CultureInfo.InvariantCulture))
            {
                // Arrange
                var productParser       = new ProductParser();
                var orderInvoiceManager = new OrderInvoiceManager();

                // Act
                var orderInvoice = orderInvoiceManager.CreateInvoice(productParser.ParseAll(new List <string> {
                    productInput
                }));

                // Assert
                Assert.Equal(1, orderInvoice.Products.Count);
                Assert.Equal(expectedOutput, orderInvoice.Products.Single().ToString());
            }
        }