コード例 #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
ファイル: JobRepository.cs プロジェクト: NerdCats/TaskCat
        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;
        }