public void MoreThanOneMethodWithSameSizeWorks()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultDomesticShippingMethod      = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var defaultInternationalShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 10);
            var largeDomesticShippingMethod        = ShippingHelpers.BuildSizeBasedShippingMethod(price: 5, size: "L", priority: 1);
            var largeInternationalShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 15, size: "L", priority: 1);
            var methods = new IShippingMethod[] {
                defaultDomesticShippingMethod,
                defaultInternationalShippingMethod,
                largeDomesticShippingMethod,
                largeInternationalShippingMethod
            };

            Assert.IsFalse(defaultDomesticShippingMethod.ComputePrice(cart, methods, null, null, null).Any());
            Assert.IsFalse(defaultInternationalShippingMethod.ComputePrice(cart, methods, null, null, null).Any());
            Assert.AreEqual(5, largeDomesticShippingMethod.ComputePrice(cart, methods, null, null, null).First().Price);
            Assert.AreEqual(15, largeInternationalShippingMethod.ComputePrice(cart, methods, null, null, null).First().Price);
        }
Exemple #2
0
        public void FixedShippingPriceMakesItIntoPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    ShippingCost = 2, Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var mediumShippingMethod  = ShippingHelpers.BuildUspsShippingMethod(size: "M", priority: 1);
            var largeShippingMethod   = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 2);
            var shippingMethods       = new IShippingMethod[]
            { defaultShippingMethod, mediumShippingMethod, largeShippingMethod };
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.IsFalse(
                defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca).Any());
            Assert.IsFalse(
                mediumShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca).Any());
            Assert.AreEqual(7,
                            largeShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                             wca).First().Price);
        }
        public void DefaultShippingMethodWorksIfNoProductWithSize()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub()),
                new ShoppingCartQuantityProduct(2, new ProductStub())
            };
            var defaultShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);

            Assert.AreEqual(3, defaultShippingMethod.ComputePrice(cart, new IShippingMethod[] { defaultShippingMethod }, null, null, null).First().Price);
        }
Exemple #4
0
        public void DefaultShippingMethodWorksIfNoProductWithSize()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub()),
                new ShoppingCartQuantityProduct(2, new ProductStub())
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(3,
                            defaultShippingMethod.ComputePrice(cart, new IShippingMethod[] { defaultShippingMethod },
                                                               Country.UnitedStates, "90220", wca).First().Price);
        }
        public void ProductsOverMaximumWeightGetIgnored()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1
                })
            };
            var shippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, maximumWeight: 3);

            Assert.IsFalse(shippingMethod.ComputePrice(cart, new IShippingMethod[] { shippingMethod }, null, null, null).Any());
        }
        public void NoSuitableShippingMethodYieldsEmptySet()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 1
                })
            };
            var shippingMethods = new[] {
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, minimumWeight: 0.4, maximumWeight: 0.6),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 7, minimumWeight: 1.1)
            };

            Assert.IsFalse(ShippingService.GetShippingOptions(shippingMethods, cart, null, null, null).Any());
        }
Exemple #7
0
        public void MarkupMakesItIntoPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub())
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.Markup = 4;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(7,
                            defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                               wca).First().Price);
        }
        public void LargeObjectShippingMethodSelectedIfAnyLargeObject()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub()),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Size = "L"
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var largeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3, size: "L", priority: 1);
            var shippingMethods       = new IShippingMethod[] { defaultShippingMethod, largeShippingMethod };

            Assert.IsFalse(defaultShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).Any());
            Assert.AreEqual(3, largeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
        public void ProductsInIntervalIncurMethodPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 4
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2
                })
            };
            var shippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, minimumWeight: 5, maximumWeight: 10);
            var prices         = shippingMethod.ComputePrice(cart, new IShippingMethod[] { shippingMethod }, null, null, null).ToList();

            Assert.That(prices.Count, Is.EqualTo(1));
            Assert.That(prices.First().Price, Is.EqualTo(3));
        }
        public void ProductsWithFixedShippingCostIncurJustThat()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 21, ShippingCost = 3
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, ShippingCost = 4
                })
            };
            var shippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var prices         = shippingMethod.ComputePrice(cart, new IShippingMethod[] { shippingMethod }, null, null, null).ToList();

            Assert.That(prices.Count, Is.EqualTo(1));
            Assert.That(prices.First().Price, Is.EqualTo(11));
        }
        public void DigitalProductsDontIncurShippingCosts()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2, ShippingCost = 10, IsDigital = true
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, ShippingCost = 20, IsDigital = true
                })
            };
            var shippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var prices         = shippingMethod.ComputePrice(cart, new IShippingMethod[] { shippingMethod }, null, null, null).ToList();

            Assert.That(prices.Count, Is.EqualTo(1));
            Assert.That(prices.First().Price, Is.EqualTo(0));
        }
        public void NoShippingMethodPriceAppliedIfAllProductsHaveFixedShipping()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2, Size = "L", ShippingCost = 1
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, ShippingCost = 3
                })
            };
            var weightShippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var sizeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var shippingMethods      = new IShippingMethod[] { weightShippingMethod, sizeShippingMethod };

            Assert.AreEqual(7, weightShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
            Assert.AreEqual(7, sizeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
        public void DefaultWeightAndSizeMethodsBothGetSelectedIfRelevant()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2, Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1
                })
            };
            var weightShippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var sizeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var shippingMethods      = new IShippingMethod[] { weightShippingMethod, sizeShippingMethod };

            Assert.AreEqual(3, weightShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
            Assert.AreEqual(3, sizeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
        public void OneSuitableShippingMethodGetsSelected()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2
                })
            };
            var shippingMethods = new[] {
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, minimumWeight: 0, maximumWeight: 1),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 7, minimumWeight: 1, maximumWeight: 5),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 11, minimumWeight: 5)
            };
            var validMethods = ShippingService.GetShippingOptions(shippingMethods, cart, null, null, null).ToList();

            Assert.AreEqual(1, validMethods.Count());
            Assert.AreEqual(7, validMethods.First().Price);
        }
        public void DuplicateMethodDoesNotYieldDuplicateOptions()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3
                })
            };

            var shippingMethod1 = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var shippingMethod2 = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);

            var shippingMethods = new[] { shippingMethod1, shippingMethod2 };

            var validMethods = ShippingService.GetShippingOptions(shippingMethods, cart, null, null, null).ToList();

            Assert.AreEqual(1, validMethods.Count());
        }
        public void OverlappingMethodsGetSelected()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 1
                })
            };
            var shippingMethods = new[] {
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, minimumWeight: 0, maximumWeight: 1),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 4, minimumWeight: 0.5, maximumWeight: 1.5),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 7, minimumWeight: 1, maximumWeight: 5),
                ShippingHelpers.BuildWeightBasedShippingMethod(price: 11, minimumWeight: 5)
            };
            var validMethods = ShippingService.GetShippingOptions(shippingMethods, cart, null, null, null).ToList();

            Assert.AreEqual(3, validMethods.Count());
            Assert.AreEqual(14, validMethods.Sum(m => m.Price));
        }
Exemple #17
0
        public void AboveMinimumTotalQuantityHits()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod(
                minimumQuantity: 2);
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.That(prices.Count(), Is.EqualTo(1));
        }
Exemple #18
0
        public void LargeObjectShippingMethodNotSelectedIfNoLargeObject()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "M"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub())
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var largeShippingMethod   = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 1);
            var shippingMethods       = new IShippingMethod[] { defaultShippingMethod, largeShippingMethod };
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(3,
                            defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                               wca).First().Price);
            Assert.IsFalse(
                largeShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca).Any());
        }
Exemple #19
0
        public void MoreThanMaximumDistinctQuantityMisses()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod(
                maximumQuantity: 1,
                countDistinct: true);
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.That(prices, Is.Empty);
        }
        public void GetShippingOptionsEnumeratesOptions()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3
                })
            };

            var shippingMethod1 = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);

            shippingMethod1.Name                  = "Shipping method 1";
            shippingMethod1.ShippingCompany       = "Vandelay Import/Export";
            shippingMethod1.ExcludedShippingAreas = "a,b";
            shippingMethod1.IncludedShippingAreas = "c,d,e";

            var shippingMethod2 = ShippingHelpers.BuildWeightBasedShippingMethod(price: 7);

            shippingMethod2.Name                  = "Shipping method 2";
            shippingMethod2.ShippingCompany       = "Northwind Shipping";
            shippingMethod2.ExcludedShippingAreas = "f,g,h";
            shippingMethod2.IncludedShippingAreas = "i,j";

            var shippingMethods = new[] { shippingMethod1, shippingMethod2 };

            var validMethods = ShippingService.GetShippingOptions(shippingMethods, cart, null, null, null).ToList();

            Assert.AreEqual(2, validMethods.Count());
            var firstOption = validMethods.First();

            Assert.That(firstOption.Description, Is.EqualTo(shippingMethod1.Name));
            Assert.That(firstOption.Price, Is.EqualTo(3));
            Assert.That(firstOption.ShippingCompany, Is.EqualTo(shippingMethod1.ShippingCompany));
            Assert.That(String.Join(",", firstOption.ExcludedShippingAreas), Is.EqualTo(shippingMethod1.ExcludedShippingAreas));
            Assert.That(String.Join(",", firstOption.IncludedShippingAreas), Is.EqualTo(shippingMethod1.IncludedShippingAreas));
            var secondOption = validMethods.Skip(1).First();

            Assert.That(secondOption.Description, Is.EqualTo(shippingMethod2.Name));
            Assert.That(secondOption.Price, Is.EqualTo(7));
            Assert.That(secondOption.ShippingCompany, Is.EqualTo(shippingMethod2.ShippingCompany));
            Assert.That(String.Join(",", secondOption.ExcludedShippingAreas), Is.EqualTo(shippingMethod2.ExcludedShippingAreas));
            Assert.That(String.Join(",", secondOption.IncludedShippingAreas), Is.EqualTo(shippingMethod2.IncludedShippingAreas));
        }
Exemple #21
0
        public void InternationalSelectsInternationalPrices()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub()),
                new ShoppingCartQuantityProduct(2, new ProductStub())
            };
            var domesticShippingMethod      = ShippingHelpers.BuildUspsShippingMethod();
            var internationalShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            internationalShippingMethod.Markup        = 7;
            internationalShippingMethod.International = true;
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            var internationalPrices = ShippingService.GetShippingOptions(
                new IShippingMethod[] { domesticShippingMethod, internationalShippingMethod },
                cart, "France", "78400", wca).ToList();

            Assert.That(internationalPrices.Count, Is.EqualTo(1));
            Assert.That(internationalPrices.First().Price, Is.EqualTo(10));
        }
Exemple #22
0
        public void WithNoMaximumWeightAnythingGoes()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 30.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 20.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.WeightPaddingInOunces = 10;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(3,
                            defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                               wca).First().Price);
        }
Exemple #23
0
        public void WeightAboveMaximumWeightFails()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.WeightPaddingInOunces = 1;
            defaultShippingMethod.MaximumWeightInOunces = 6.9;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.That(prices, Is.Empty);
        }
Exemple #24
0
        public void WeightAtMaximumWeightPasses()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),                                                                    // For the moment, weight is in pounds here
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.WeightPaddingInOunces = 1;
            defaultShippingMethod.MaximumWeightInOunces = 8;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.AreEqual(3, prices.First().Price);
        }
        public void FixedShippingPriceMakesItIntoPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    ShippingCost = 2, Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var mediumShippingMethod  = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3, size: "M", priority: 1);
            var largeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3, size: "L", priority: 2);
            var shippingMethods       = new IShippingMethod[] { defaultShippingMethod, mediumShippingMethod, largeShippingMethod };

            Assert.IsFalse(defaultShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).Any());
            Assert.IsFalse(mediumShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).Any());
            Assert.AreEqual(7, largeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
        public void ComplexOrderGivesRightShippingCost()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 1.5
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, ShippingCost = 4
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, IsDigital = true
                }),
                new ShoppingCartQuantityProduct(3, new ProductStub {
                    Weight = 3
                })
            };
            var shippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3, minimumWeight: 10, maximumWeight: 11);
            var prices         = shippingMethod.ComputePrice(cart, new IShippingMethod[] { shippingMethod }, null, null, null).ToList();

            Assert.That(prices.Count, Is.EqualTo(1));
            Assert.That(prices.First().Price, Is.EqualTo(8 + 3));
        }
        public void FlatRateIsFlat()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 1.5
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, IsDigital = true
                }),
                new ShoppingCartQuantityProduct(3, new ProductStub {
                    Weight = 3
                })
            };
            var shippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var prices         = shippingMethod.ComputePrice(cart, new IShippingMethod[] { shippingMethod }, null, null, null).ToList();

            Assert.That(prices.Count, Is.EqualTo(1));
            Assert.That(prices.First().Price, Is.EqualTo(3));
        }
Exemple #28
0
        public void MoreThanOneMethodWithSameSizeWorks()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultDomesticShippingMethod      = ShippingHelpers.BuildUspsShippingMethod();
            var defaultInternationalShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var largeDomesticShippingMethod        = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 1);
            var largeInternationalShippingMethod   = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 1);
            var methods = new IShippingMethod[] {
                defaultDomesticShippingMethod,
                defaultInternationalShippingMethod,
                largeDomesticShippingMethod,
                largeInternationalShippingMethod
            };
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.IsFalse(
                defaultDomesticShippingMethod.ComputePrice(cart, methods, Country.UnitedStates, "90220", wca).Any());
            Assert.IsFalse(
                defaultInternationalShippingMethod.ComputePrice(cart, methods, Country.UnitedStates, "90220", wca)
                .Any());
            Assert.AreEqual(3,
                            largeDomesticShippingMethod.ComputePrice(cart, methods, Country.UnitedStates, "90220",
                                                                     wca).First().Price);
            Assert.AreEqual(3,
                            largeInternationalShippingMethod.ComputePrice(cart, methods, Country.UnitedStates,
                                                                          "90220", wca).First().Price);
        }