Пример #1
0
        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",
                ReferenceInvoiceId = "SMPL-1NV01C31D"
            };

            // 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);
        }
Пример #2
0
        public void Test_CalculateServiceCharge_Weight_Less_Than_Threshold()
        {
            var items = new List <ItemDetails>();

            items.Add(new ItemDetails {
                Weight = 0.1m
            });
            items.Add(new ItemDetails {
                Weight = 0.3m
            });

            // Act
            var deliveryChargeCalcSvc = new DefaultDeliveryServiceChargeCalculationService();
            var actual   = deliveryChargeCalcSvc.CalculateServiceCharge(items);
            var expected = 150.0m;

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