Пример #1
0
        public async Task <UpdateResult <Job> > UpdateOrder(Job job, OrderModel orderModel, string mode)
        {
            if (job.Order.Type != orderModel.Type)
            {
                throw new InvalidOperationException("Updating with a different ordermodel for this job");
            }

            // FIXME: Finding a resolver here would help here dude
            switch (orderModel.Type)
            {
            case OrderTypes.Delivery:
            case OrderTypes.ClassifiedDelivery:
            {
                var orderCalculationService         = new DefaultOrderCalculationService();
                var serviceChargeCalculationService = new DefaultDeliveryServiceChargeCalculationService();
                var orderProcessor = new DeliveryOrderProcessor(
                    orderCalculationService,
                    serviceChargeCalculationService);
                orderProcessor.ProcessOrder(orderModel);
                var jobUpdater = new DeliveryJobUpdater(job);
                jobUpdater.UpdateJob(orderModel, mode);
                job = jobUpdater.Job;
                break;
            }
            }

            var result = await UpdateJob(job);

            return(new UpdateResult <Job>(result.MatchedCount, result.ModifiedCount, job));
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public async Task<ReplaceOneResult> UpdateOrder(Job job, OrderModel orderModel)
        {
            if (job.Order.Type != orderModel.Type)
            {
                throw new InvalidOperationException("Updating with a different ordermodel for this job");
            }

            // FIXME: Finding a resolver here would help here dude
            switch (orderModel.Type)
            {
                case OrderTypes.Delivery:
                case OrderTypes.ClassifiedDelivery:
                    {
                        var orderCalculationService = new DefaultOrderCalculationService();
                        var serviceChargeCalculationService = new DefaultDeliveryServiceChargeCalculationService();
                        var orderProcessor = new DeliveryOrderProcessor(
                            orderCalculationService,
                            serviceChargeCalculationService);
                        orderProcessor.ProcessOrder(orderModel);
                        var jobUpdater = new DeliveryJobUpdater(job);
                        jobUpdater.UpdateJob(orderModel);
                        job = jobUpdater.Job;
                        break;
                    }
            }

            var result = await UpdateJob(job);
            return result;
        }