Example #1
0
        public PostageResult CalculatePostageFor(Basket basket)
        {
            if (basket == null)
            {
                throw new ArgumentNullException("basket");
            }

            var postages = postageRepository.GetAll();

            var postZone = basket.Country.PostZone;

            var totalWeight = (int)basket.BasketItems
                              .Sum(bi => bi.TotalWeight);

            var postageToApply = postages
                                 .Where(p => totalWeight <= p.MaxWeight && p.IsActive)
                                 .OrderBy(p => p.MaxWeight)
                                 .FirstOrDefault();

            var postageDescription = string.Format("for {0}", basket.Country.Name);

            if (postageToApply == null)
            {
                return(PostageResult.WithDefault(postZone, postageDescription));
            }

            var multiplier = postZone.Multiplier;
            var total      = new Money(Math.Round(postageToApply.Price.Amount * multiplier, 2, MidpointRounding.AwayFromZero));

            return(PostageResult.WithPrice(total, postageDescription));
        }
        public void Should_be_able_to_add_an_adjustment_to_an_order()
        {
            var order = new Order();

            order.AddLine("widget 1", 1, new Money(12.34M), "abc", 102, "-");
            order.AddLine("gadget 1", 2, new Money(3.55M), "def", 101, "-");
            order.AddLine("gadget 1", 2, new Money(3.55M), "def", 101, "-");
            order.Postage = PostageResult.WithPrice(new Money(1.33M), "for London");

            var expectedAdjustedTotal = order.Total + new Money(-4.50M);

            var adjustment = new OrderAdjustment
            {
                Description = "4.50 off for slight scuffing",
                Amount      = new Money(-4.50M)
            };

            order.AddAdjustment(adjustment);

            order.Adjustments[0].ShouldBeTheSameAs(adjustment);
            adjustment.Order.ShouldBeTheSameAs(order);
            order.Adjustments[0].Description.ShouldEqual("4.50 off for slight scuffing");

            order.Total.ShouldEqual(expectedAdjustedTotal);
        }
	    public void OrderFromCheckoutViewData_should_calculate_the_correct_postage()
	    {
	        var postage = new PostageResult();

	        postageService.Stub(x => x.CalculatePostageFor(basket)).Return(postage);

            var order = checkoutService.OrderFromCheckoutViewData(checkoutViewData, new ModelStateDictionary());

	        order.Postage.ShouldBeTheSameAs(postage);
	    }
Example #4
0
        public void OrderFromCheckoutViewData_should_calculate_the_correct_postage()
        {
            var postage = new PostageResult();

            postageService.Stub(x => x.CalculatePostageFor(basket)).Return(postage);

            var order = checkoutService.OrderFromCheckoutViewData(checkoutViewData, new ModelStateDictionary());

            order.Postage.ShouldBeTheSameAs(postage);
        }
Example #5
0
        public void TotalWithPostage_should_return_postageResult_postage()
        {
            var postageCost = new Money(5.66M);
            var itemPrice   = new Money(101.43M);

            var order = new Order
            {
                Postage = PostageResult.WithPrice(postageCost, "postage desc")
            };

            order.AddLine("line1", 1, itemPrice, "", 1, "");

            var expectedTotalWithPostage = postageCost + itemPrice;

            order.TotalWithPostage.ShouldEqual(expectedTotalWithPostage.ToStringWithSymbol());
        }
        public void Index_should_return_postage_view()
        {
            const int basketId = 89;

            var basket = BasketTests.Create350GramBasket();

            basketRepository.Stub(b => b.GetById(basketId)).Return(basket);

            var postageResult = PostageResult.WithPrice(new Money(34.56M), "postage description");

            postageService.Stub(p => p.CalculatePostageFor(basket)).Return(postageResult);

            postageDetailController.Index(basketId)
            .ReturnsViewResult()
            .ForView("Index")
            .WithModel <PostageResultViewData>()
            .AssertAreEqual("�.56", vd => vd.PostageTotal)
            .AssertAreEqual("postage description", vd => vd.Description)
            .AssertAreEqual("�5.58", vd => vd.TotalWithPostage)
            .AssertAreSame(basket.Country, vd => vd.Country);
        }
Example #7
0
 public ShopViewData WithTotalPostage(PostageResult postageResult)
 {
     this.PostageResult = postageResult;
     return(this);
 }
Example #8
0
 public ShopViewData WithTotalPostage(PostageResult postageResult)
 {
     this.PostageResult = postageResult;
     return this;
 }