Exemplo n.º 1
0
 public void If_parcel_is_too_heavy_Then_even_fits_will_get_error(
     decimal maxWeight,
     [Frozen] IPackageRepository packageRepo,
     ParcelAdvisor advisor)
 {
     Mock.Get(packageRepo).Setup(r => r.GetMaxWeight()).Returns(maxWeight);
     // just slightly too heavy!
     Assert.Throws <InvalidOperationException>(() => advisor.Advise(new Parcel(1, 1, 1, maxWeight + 1)), "too heavy");
 }
Exemplo n.º 2
0
        public void If_packages_are_not_available_Then_gets_error(
            Parcel parcel,
            [Frozen] IPackageRepository packageRepo,
            ParcelAdvisor advisor)
        {
            Mock.Get(packageRepo).Setup(p => p.GetPackages()).Returns(() => null);

            Assert.Throws <InvalidOperationException>(() => advisor.Advise(parcel), "no package");
        }
Exemplo n.º 3
0
        public void If_parcel_is_too_large_Then_gets_error(
            decimal maxWeight,
            [Frozen] IPackageRepository packageRepo,
            ParcelAdvisor advisor)
        {
            Mock.Get(packageRepo).Setup(p => p.GetPackages()).Returns(packages);
            Mock.Get(packageRepo).Setup(p => p.GetMaxWeight()).Returns(maxWeight);

            // just slightly too large!
            Assert.Throws <InvalidOperationException>(() => advisor.Advise(new Parcel(381, 550, 200, maxWeight - 1)), "no package");
        }
Exemplo n.º 4
0
        public void Can_advise_tight_fits_regardless_of_order_of_dimensions(
            int d1,
            int d2,
            int d3,
            int cost,
            decimal maxWeight,
            [Frozen] IPackageRepository packageRepo,
            ParcelAdvisor advisor)
        {
            Mock.Get(packageRepo).Setup(p => p.GetPackages()).Returns(packages.Shuffle());
            Mock.Get(packageRepo).Setup(p => p.GetMaxWeight()).Returns(maxWeight);

            // shuffle
            var allowedWeight = maxWeight - 1;
            var dimensions = new[] { d1, d2, d3 }.Shuffle().ToArray();

            var parcel = new Parcel(dimensions[0], dimensions[1], dimensions[2], allowedWeight);

            var package = advisor.Advise(parcel);

            // cost is 10 times of actual for sake of unit testing
            Assert.That(package.Cost, Is.EqualTo(cost / 10M));
        }
Exemplo n.º 5
0
 public void Must_be_given_a_valid_parcel(ParcelAdvisor advisor)
 {
     Assert.Throws <ArgumentNullException>(() => advisor.Advise(null));
 }