コード例 #1
0
        public void NewChoiceShippingOptionTest()
        {
            var newChoiceShippingOption = new NewChoiceShipping()
            {
                NewChoiceCosts = new[]
                {
                    new NewChoiceShippingCost()
                    {
                        DestinationRegion =
                            NewChoiceShippingCost.Regions.UK,
                        Amount = .5m
                    },
                    new NewChoiceShippingCost()
                    {
                        DestinationRegion =
                            NewChoiceShippingCost.Regions.Europe,
                        Amount = 1.0m
                    }
                },
            };

            var shippingAmount = newChoiceShippingOption.GetAmount(new LineItem()
            {
                DeliveryRegion = NewChoiceShippingCost.Regions.Europe
            }, new Basket());

            Assert.That(shippingAmount, Is.EqualTo(1.0m));

            shippingAmount = newChoiceShippingOption.GetAmount(new LineItem()
            {
                DeliveryRegion = NewChoiceShippingCost.Regions.UK
            }, new Basket());
            Assert.That(shippingAmount, Is.EqualTo(0.5m));
        }
コード例 #2
0
        public void BasketShippingTotalTest()
        {
            var perRegionShippingOption = new PerRegionShipping()
            {
                PerRegionCosts = new[]
                {
                    new RegionShippingCost()
                    {
                        DestinationRegion =
                            RegionShippingCost.Regions.UK,
                        Amount = 0.5m
                    },
                    new RegionShippingCost()
                    {
                        DestinationRegion =
                            RegionShippingCost.Regions.Europe,
                        Amount = 1.0m
                    }
                },
            };

            var newChoiceShippingOption = new NewChoiceShipping()
            {
                NewChoiceCosts = new[]
                {
                    new NewChoiceShippingCost()
                    {
                        DestinationRegion =
                            NewChoiceShippingCost.Regions.UK,
                        Amount = .5m
                    },
                    new NewChoiceShippingCost()
                    {
                        DestinationRegion =
                            NewChoiceShippingCost.Regions.Europe,
                        Amount = 1.0m
                    }
                },
            };


            var flatRateShippingOption = new FlatRateShipping {
                FlatRate = 1.1m
            };

            var basket = new Basket()
            {
                LineItems = new List <LineItem>
                {
                    new LineItem()
                    {
                        DeliveryRegion = RegionShippingCost.Regions.UK,
                        Shipping       = perRegionShippingOption
                    },
                    new LineItem()
                    {
                        DeliveryRegion = RegionShippingCost.Regions.Europe,
                        Shipping       = perRegionShippingOption
                    },
                    new LineItem()
                    {
                        Shipping = flatRateShippingOption
                    },

                    new LineItem()
                    {
                        DeliveryRegion = NewChoiceShippingCost.Regions.UK,
                        Shipping       = newChoiceShippingOption
                    },
                    new LineItem()
                    {
                        DeliveryRegion = NewChoiceShippingCost.Regions.Europe,
                        Shipping       = newChoiceShippingOption
                    },
                    new LineItem()
                    {
                        DeliveryRegion = NewChoiceShippingCost.Regions.Europe,
                        Shipping       = newChoiceShippingOption
                    },
                }
            };

            var calculator = new ShippingCalculator();

            decimal basketShipping = calculator.CalculateShipping(basket);

            Assert.That(basketShipping, Is.EqualTo(4.6m));
        }