コード例 #1
0
		public void DiscountAmountRegressionTest20140116()
		{
			IOC.IntegrationTest();
			var product = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(6000, 1, 19, new DiscountProduct { DiscountType = DiscountType.Amount, DiscountValue = 2000 });
			var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(product);
			var oldLine = order.OrderLines.Single();
			var basket = Basket.CreateBasketFromOrderInfo(order);

			Assert.AreEqual(4000, order.OrderLineTotalInCents);
			Assert.AreEqual(4000, basket.OrderAmount.ValueInCents());
			Assert.AreEqual(4000, basket.OrderAmount.BeforeDiscount.ValueInCents());
			Assert.AreEqual(0, basket.OrderAmount.Discount.ValueInCents());


			IOC.IntegrationTest();
			var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(25);
			IOC.OrderDiscountRepository.SetupFake(discount);
			//DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(order, discount);
			order.OrderDiscountsFactory = () => IO.Container.Resolve<IOrderDiscountService>().GetApplicableDiscountsForOrder(order, order.Localization).ToList();
			order.ResetDiscounts();

			Assert.AreEqual(4000, order.OrderLineTotalInCents);

			Assert.AreEqual(4000, order.OrderLines.Single().ProductInfo.PriceInCents);

			Assert.AreEqual(1000, IOC.DiscountCalculationService.Actual().Resolve().DiscountAmountForOrder(discount, order));
			order.ResetDiscounts();

			Assert.AreEqual(1000, order.DiscountAmountInCents);
			Assert.AreEqual(4000, order.OrderLineTotalInCents);
			Assert.AreEqual(3000, basket.OrderAmount.ValueInCents());
			Assert.AreEqual(4000, basket.OrderAmount.BeforeDiscount.ValueInCents());

			Assert.AreEqual(4000, basket.OrderAmount.BeforeDiscount.WithVat.ValueInCents);
			Assert.AreEqual(3361, basket.OrderAmount.BeforeDiscount.WithoutVat.ValueInCents);

			Assert.AreEqual(4000, oldLine.Amount.ValueInCents());
			Assert.AreEqual(4000, oldLine.Amount.BeforeDiscount.ValueInCents());
			Assert.AreEqual(0, oldLine.Amount.Discount.WithVat.ValueInCents);
			Assert.AreEqual(0, oldLine.Amount.Discount.ValueInCents());


			var price = new SummedPrice(new[] { oldLine.Amount }, true, 19, StoreHelper.CurrentLocalization, IO.Container.Resolve<IVatCalculationStrategy>());
			Assert.AreEqual(4000, price.ValueInCents);
			price = new SummedPrice(new[] { oldLine.Amount }, true, 19, StoreHelper.CurrentLocalization, IO.Container.Resolve<IVatCalculationStrategy>());
			Assert.AreEqual(4000, price.BeforeDiscount.ValueInCents());
			price = new SummedPrice(new[] { oldLine.Amount }, true, 19, StoreHelper.CurrentLocalization, IO.Container.Resolve<IVatCalculationStrategy>());
			Assert.AreEqual(0, price.Discount.ValueInCents());

			var line = basket.OrderLines.Single();
			Assert.AreEqual(4000, line.Amount.ValueInCents());
			Assert.AreEqual(4000, line.Amount.BeforeDiscount.ValueInCents());
			Assert.AreEqual(0, line.Amount.Discount.ValueInCents());

			Assert.AreEqual(1000, basket.OrderAmount.Discount.ValueInCents());
			Assert.AreEqual(840, basket.OrderAmount.Discount.WithoutVat.ValueInCents); 
			Assert.AreEqual(1000, basket.OrderAmount.Discount.WithVat.ValueInCents);

		}
コード例 #2
0
		public void TestSummedPrice()
		{
			IOC.UnitTest();
			var basePriceMock = new Mock<IDiscountedRangedPrice>();
			var price = new SummedPrice(new[] { basePriceMock.Object }, true, 19, StoreHelper.CurrentLocalization, IOC.VatCalculationStrategy.Resolve());

			var a = price.Discount;

			basePriceMock.VerifyGet(m => m.Discount);
		}