public void IsSet()
        {
            var order = new OrderCarrier();

            using (CalculatorContext.Use(order))
            {
                Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier());
            }

            Assert.Null(CalculatorContext.GetCurrentOrderCarrier());
        }
Example #2
0
        public void SetContext()
        {
            var order = new OrderCarrier();

            var deliveryCostCalculator = Substitute.For <IDeliveryCostCalculator>();

            deliveryCostCalculator.When(r => r.CalculateFromCarrier(order, Arg.Any <SecurityToken>()))
            .Do(ci => Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier()));
            var feesCalculator = Substitute.For <IFeesCalculator>();

            feesCalculator.When(r => r.CalculateFromCarrier(order, Arg.Any <SecurityToken>()))
            .Do(ci => Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier()));
            var orderTotalCalculator = Substitute.For <IOrderTotalCalculator>();

            orderTotalCalculator.When(r => r.CalculateFromCarrier(order, Arg.Any <SecurityToken>()))
            .Do(ci => Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier()));
            var campaignCalculator = Substitute.For <ICampaignCalculator>();

            campaignCalculator.When(r => r.CalculateFromCarrier(order, Arg.Any <SecurityToken>()))
            .Do(ci => Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier()));
            var vatCalculator = Substitute.For <IVatCalculator>();

            vatCalculator.When(r => r.CalculateFromCarrier(order, Arg.Any <SecurityToken>()))
            .Do(ci => Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier()));
            var orderGrandTotalCalculator = Substitute.For <IOrderGrandTotalCalculator>();

            orderGrandTotalCalculator.When(r => r.Calculate(order, Arg.Any <SecurityToken>()))
            .Do(ci => Assert.Same(order, CalculatorContext.GetCurrentOrderCarrier()));

            var sut = new OrderCalculators.OrderCalculator(
                deliveryCostCalculator,
                feesCalculator,
                orderTotalCalculator,
                campaignCalculator,
                vatCalculator,
                orderGrandTotalCalculator);

            sut.Calculate(order, true, null);

            Assert.Null(CalculatorContext.GetCurrentOrderCarrier());
            deliveryCostCalculator.Received().CalculateFromCarrier(order, Arg.Any <SecurityToken>());
            feesCalculator.Received().CalculateFromCarrier(order, Arg.Any <SecurityToken>());
            orderTotalCalculator.Received().CalculateFromCarrier(order, Arg.Any <SecurityToken>());
            campaignCalculator.Received().CalculateFromCarrier(order, Arg.Any <SecurityToken>());
            vatCalculator.Received().CalculateFromCarrier(order, Arg.Any <SecurityToken>());
            orderGrandTotalCalculator.Received().Calculate(order, Arg.Any <SecurityToken>());
        }
        public virtual void CalculateOrderRowTotal(OrderRowCarrier orderRowCarrier)
        {
            var      order    = CalculatorContext.GetCurrentOrderCarrier();
            Currency currency = null;

            if (order != null)
            {
                currency = currencyService.Get(order.CurrencyID);
            }

            if (currency == null)
            {
                currency = new Currency(string.Empty);
            }

            CalculateOrderRowTotal(orderRowCarrier, currency);
        }
Example #4
0
        private Currency GetCurrency(OrderCarrier orderCarrier)
        {
            if (orderCarrier == null)
            {
                orderCarrier = CalculatorContext.GetCurrentOrderCarrier();
            }
            Currency currency = null;

            if (orderCarrier != null)
            {
                currency = currencyService.Get(orderCarrier.CurrencyID);
            }
            if (currency == null)
            {
                currency = new Currency(string.Empty);
            }
            return(currency);
        }