public void Test_CalculateTotalToPay_Valid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m, VAT = 15 });

            var orderCalcSvc = new DefaultOrderCalculationService();
            decimal serviceCharge = 100.0m;

            // Act
            var expected = 0.0m;
            foreach (var item in items)
            {
                var total = item.Quantity * item.Price;
                var totalPlusVat = total * (1 + item.VAT / 100);
                expected += totalPlusVat;
            }
            expected += serviceCharge;

            var actual = orderCalcSvc.CalculateTotalToPay(items, serviceCharge);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void Test_ProcessOrder_Valid()
        {
            // Arrange
            var orderCalcSvc = new DefaultOrderCalculationService();
            var serviceChargeCalcSvc = new DefaultDeliveryServiceChargeCalculationService();

            var deliveryOrderProcessor = new DeliveryOrderProcessor(
                orderCalcSvc, serviceChargeCalcSvc);

            var deliveryOrder = new DeliveryOrder
            {
                UserId = "this.User",
                From = new DefaultAddress { Address = "My Home" },
                To = new DefaultAddress { Address = "My Office" },
                OrderCart = new OrderDetails
                {
                    PackageList = new List<ItemDetails>()
                    {
                        new ItemDetails
                        {
                            Item = "Coffee",
                            Quantity = 2,
                            Price = 150.0m,
                            VAT = 15.0m
                        }              
                    }                    
                },
                PaymentMethod = "CashOnDelivery"
            };

            // Act
            deliveryOrderProcessor.ProcessOrder(deliveryOrder);
            var coffees = deliveryOrder.OrderCart.PackageList;
            var cart = deliveryOrder.OrderCart;

            var serviceCharge = serviceChargeCalcSvc.CalculateServiceCharge(coffees);
            var subTotal = orderCalcSvc.CalculateSubtotal(coffees);
            var totalToPay = orderCalcSvc.CalculateTotalToPay(coffees, serviceCharge);
            var totalVATAmount = orderCalcSvc.CalculateTotalVATAmount(coffees, serviceCharge);
            var totalWeight = 0;


            // Assert
            Assert.AreEqual(serviceCharge, cart.ServiceCharge);
            Assert.AreEqual(subTotal, cart.SubTotal);
            Assert.AreEqual(totalToPay, cart.TotalToPay);
            Assert.AreEqual(totalVATAmount, cart.TotalVATAmount);
            Assert.AreEqual(totalWeight, cart.TotalWeight);
        }
        public void Test_CalculateNetTotal_Valid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m });

            var orderCalcSvc = new DefaultOrderCalculationService();

            // Act
            var expected = 0.0m;
            foreach (var item in items)
            {
                expected += (item.Price * item.Quantity);
            }
            var actual = orderCalcSvc.CalculateNetTotal(items);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void Test_CalculateTotaVATAmount_Valid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m, VAT = 15 });

            var orderCalcSvc = new DefaultOrderCalculationService();
            var subTotal = 0.0m;
            var netTotal = 0.0m;

            // Act
            foreach (var item in items)
            {
                var total = item.Quantity * item.Price;
                var totalPlusVat = total * (1 + item.VAT / 100);
                subTotal += totalPlusVat;
                netTotal += total;
            }
            var expected = subTotal - netTotal;
            var actual = orderCalcSvc.CalculateTotalVATAmount(items, 10.0m);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void Test_VerifyAndCalculateTotalVATAmount_Invalid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m, VAT = 15 });

            var orderCalcSvc = new DefaultOrderCalculationService();
            var subTotal = 0.0m;
            var netTotal = 0.0m;

            // Act
            foreach (var item in items)
            {
                var total = item.Quantity * item.Price;
                var totalPlusVat = total * (1 + item.VAT / 100);
                subTotal += totalPlusVat;
                netTotal += total;
            }
            var expected = subTotal - netTotal;
            var submittedTotalVATAmount = 0.0m;

            // Assert
            Assert.Throws<OrderCalculationException>(
                () => orderCalcSvc.VerifyAndTotalVATAmount(
                    items, 10.0m, submittedTotalVATAmount));
        }
        public void Test_VerifyAndCalculateTotalToPay_Invalid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m, VAT = 15 });

            var orderCalcSvc = new DefaultOrderCalculationService();
            var expected = 0.0m;
            decimal serviceCharge = 0.0m;

            // Act
            foreach (var item in items)
            {
                var total = item.Quantity * item.Price;
                var totalPlusVat = total * (1 + item.VAT / 100);
                expected += totalPlusVat;
            }
            expected += serviceCharge;
            var submittedTotalToPay = 0.0m;

            // Assert
            Assert.Throws<OrderCalculationException>(
                () => orderCalcSvc.VerifyAndCalculateTotalToPay(
                    items, serviceCharge, submittedTotalToPay));
        }
        public void Test_VerifyAndCalculateNetTotal_Invalid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m });

            var orderCalcSvc = new DefaultOrderCalculationService();
            var expected = 0.0m;

            // Act
            foreach (var item in items)
            {
                expected += (item.Price * item.Quantity);
            }
            var submittedNetTotal = 0.0m;

            // Assert
            Assert.Throws<OrderCalculationException>(
                () => orderCalcSvc.VerifyAndCalculateNetTotal(items, submittedNetTotal));
        }
        public void Test_VerifyAndCalculateSubtotal_Valid()
        {
            // Arrange
            List<ItemDetails> items = new List<ItemDetails>();
            items.Add(new ItemDetails { Quantity = 5, Price = 10.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 2, Price = 100.0m, VAT = 15 });
            items.Add(new ItemDetails { Quantity = 10, Price = 15.0m, VAT = 15 });

            var orderCalcSvc = new DefaultOrderCalculationService();
            var expected = 0.0m;

            // Act
            foreach (var item in items)
            {
                var total = item.Quantity * item.Price;
                var totalPlusVat = total * (1 + item.VAT / 100);
                expected += totalPlusVat;
            }
            var submittedSubTotal = expected;
            var actual = orderCalcSvc.VerifyAndCalculateSubtotal(items, submittedSubTotal);

            // Assert
            Assert.AreEqual(expected, actual);
        }