public void DiscountAmountRegressionTest20140408() { IOC.IntegrationTest(); var product1 = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(400, 10); var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(product1); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(10, DiscountOrderCondition.OnTheXthItem, 2); //IOC.OrderDiscountRepository.SetupFake(discount.ToDiscountOrder()); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(order, discount); var basket = new BasketOrderInfoAdaptor(order); var basketLine = basket.OrderLines.Single(); Console.WriteLine(basketLine.Amount.Discount.WithVat.ToCurrencyString()); Console.WriteLine(basketLine.Amount.BeforeDiscount.WithVat.ToCurrencyString()); Console.WriteLine(basketLine.Amount.WithVat.ToCurrencyString()); var line = order.OrderLines.First(); Console.WriteLine(line.Amount.Discount.WithVat.ToCurrencyString()); Console.WriteLine(line.Amount.BeforeDiscount.WithVat.ToCurrencyString()); Console.WriteLine(line.Amount.WithVat.ToCurrencyString()); Assert.AreEqual(50, basketLine.Amount.Discount.WithVat.ValueInCents); Assert.AreEqual(4000, basketLine.Amount.BeforeDiscount.WithVat.ValueInCents); Assert.AreEqual(3950, basketLine.Amount.WithVat.ValueInCents); Assert.AreEqual(50, line.Amount.Discount.WithVat.ValueInCents); Assert.AreEqual(4000, line.Amount.BeforeDiscount.WithVat.ValueInCents); Assert.AreEqual(3950, line.Amount.WithVat.ValueInCents); }
public void AmountDiscountExcludingVat() { IOC.IntegrationTest(); IOC.SettingsService.ExclVat(); var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1, 10); var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(500, DiscountOrderCondition.None, 0); IOC.OrderDiscountRepository.SetupFake(discount); order.OrderDiscountsFactory = () => IO.Container.Resolve <IOrderDiscountService>().GetApplicableDiscountsForOrder(order, order.Localization).ToList(); order.ResetDiscounts(); Assert.AreEqual(1100, order.GetAmount(true, false, true)); Assert.AreEqual(1000, order.GetAmount(false, false, true)); Assert.AreEqual(550, order.GetAmount(true, true, true)); Assert.AreEqual(500, order.GetAmount(false, true, true)); var price = new SimplePrice(order, order.Localization); Assert.AreEqual(1100, price.BeforeDiscount.WithVat.ValueInCents); Assert.AreEqual(1000, price.BeforeDiscount.WithoutVat.ValueInCents); Assert.AreEqual(100, price.BeforeDiscount.Vat.ValueInCents); Assert.AreEqual(550, price.WithVat.ValueInCents); Assert.AreEqual(500, price.WithoutVat.ValueInCents); Assert.AreEqual(50, price.Vat.ValueInCents); Assert.AreEqual(550, price.Discount.WithVat.ValueInCents); Assert.AreEqual(500, price.Discount.WithoutVat.ValueInCents); }
public void GrandTotalWithOrderDiscoun214t() { IOC.OrderService.Actual(); var productInfo = new ProductInfo { Id = 1234, IsDiscounted = false, Vat = 0, OriginalPriceInCents = 1000, Ranges = new List <Range>() }; IOC.CMSEntityRepository.SetupNewMock().Setup(m => m.GetByGlobalId(1234)).Returns(new UwbsNode { Id = 1234, NodeTypeAlias = Product.NodeAlias }); var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(10, DiscountOrderCondition.None, 0); discount.AffectedOrderlines = new List <int> { 1234 }; DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); Assert.AreEqual(10, orderInfo.DiscountAmountInCents); Assert.AreEqual(990, orderInfo.GrandtotalInCents); Assert.AreEqual(990, orderInfo.OrderTotalInCents); Assert.AreEqual(0, orderInfo.AverageOrderVatPercentage); Assert.AreEqual(990, orderInfo.SubtotalInCents); }
public void Setup() { IOC.IntegrationTest(); _orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); _orderDiscount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(195, DiscountOrderCondition.None, 0); }
public void ThatPercentDiscountIsAppliedToCorrectNumberOfItemsFixedDiscount(int setSize, int itemCount, int expectedNumberOfDiscounts) { var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, itemCount); var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(50, DiscountOrderCondition.PerSetOfXItems, setSize); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); Assert.AreEqual(itemCount * 1000 - expectedNumberOfDiscounts * 50, orderInfo.OrderTotalInCents); }
public void AmountLargerThanOrderAmount() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(1234, DiscountOrderCondition.None, 0); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); var actual = _discountCalculationService.DiscountAmountForOrder(discount, orderInfo); Assert.AreEqual(1000, actual); }
public void RecreateBug20121127() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(21306, 2, 21), DefaultFactoriesAndSharedFunctionality.CreateProductInfo(3995, 1, 0)); var defaultOrderDiscountWithAmount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(50000, DiscountOrderCondition.None, 0); Assert.NotNull(defaultOrderDiscountWithAmount.AffectedProductTags); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, defaultOrderDiscountWithAmount, DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(25)); Assert.AreEqual(46607, orderInfo.DiscountAmountInCents); Assert.AreEqual(46607, orderInfo.DiscountAmountWithVatInCents); //Assert.AreEqual(0, orderInfo.OrderLineTotalWithVatInCents); // Assert.AreEqual(46607, orderInfo.OrderLineTotalInCents); Assert.AreEqual(0, orderInfo.OrderTotalInCents); }
public void AddingACouponToAnIncompleteOrderAfterDeserialization_ShouldApplyCouponDiscount() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(100, DiscountOrderCondition.None, 0); discount.CouponCode = "coupon"; DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); Assert.AreEqual(0, orderInfo.DiscountAmountInCents); // fake deserialization (for sake of speed) orderInfo.DiscountService = new DiscountService(new ListRepository <IOrderDiscount>(orderInfo.OrderDiscounts.Select(disc => new OrderDiscount(disc)))); Assert.AreEqual(0, orderInfo.DiscountAmountInCents); orderInfo.CouponCodes.Add("coupon"); Assert.AreEqual(100, orderInfo.DiscountAmountInCents); }
public void AddingACouponToAnIncompleteOrderAfterDeserialization_ShouldApplyCouponDiscount() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(100, DiscountOrderCondition.None, 0); discount.CouponCode = "coupon"; DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); Assert.AreEqual(0, orderInfo.DiscountAmountInCents); Assert.AreEqual(0, orderInfo.DiscountAmountInCents); Assert.False(orderInfo.LegacyDataReadBackMode); orderInfo.SetCouponCode("coupon"); //Assert.False(orderInfo._discountAmountInCents.HasValue); Assert.AreEqual(100, orderInfo.DiscountAmountInCents); }
public void AmountDiscountIncludingVat() { IOC.IntegrationTest(); var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1, 10); var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(500, DiscountOrderCondition.None, 0); IOC.OrderDiscountRepository.SetupFake(discount); order.OrderDiscountsFactory = () => IO.Container.Resolve <IOrderDiscountService>().GetApplicableDiscountsForOrder(order, order.Localization).ToList(); order.ResetDiscounts(); var absoluteDiscountAmount = 500; var AverageOrderVatPercentage = 10m; var vatAmountFromWithVat = VatCalculator.VatAmountFromWithVat(absoluteDiscountAmount, AverageOrderVatPercentage); //var vatAmountFromWithoutVat = VatCalculator.VatAmountFromWithoutVat(absoluteDiscountAmount, AverageOrderVatPercentage); Assert.AreEqual(45, vatAmountFromWithVat); // berekende discount vat = 45,45454545.. // correct zou zijn 500 - 454 = 46 (zie hieronder) // full amount: 909 // discounted amount: 455 // discount: 909 - 455 = 454 // 'discount vat': 500 - 454 = 46 Assert.AreEqual(1000, order.GetAmount(true, false, true)); Assert.AreEqual(909, order.GetAmount(false, false, true)); Assert.AreEqual(500, order.GetAmount(true, true, true)); Assert.AreEqual(455, order.GetAmount(false, true, true)); var price = new SimplePrice(order, order.Localization); Assert.AreEqual(1000, price.BeforeDiscount.WithVat.ValueInCents); Assert.AreEqual(909, price.BeforeDiscount.WithoutVat.ValueInCents); Assert.AreEqual(91, price.BeforeDiscount.Vat.ValueInCents); Assert.AreEqual(500, price.WithVat.ValueInCents); Assert.AreEqual(455, price.WithoutVat.ValueInCents); Assert.AreEqual(45, price.Vat.ValueInCents); Assert.AreEqual(500, price.Discount.WithVat.ValueInCents); Assert.AreEqual(454, price.Discount.WithoutVat.ValueInCents); }
public void DiscountShouldGiveSameAmountForOrderAfterDeserialization() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(234, DiscountOrderCondition.None, 0); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); var orderData = orderInfo.ToOrderData(); var convertedOrderInfo = OrderInfo.CreateOrderInfoFromOrderData(orderData); var convertedDiscount = new uWebshop.Domain.OrderDTO.OrderDiscount(StoreHelper.CurrentLocalization, discount, orderInfo); //Assert.AreEqual(234, orderInfo.DiscountAmountInCents); //Assert.AreEqual(234, convertedOrderInfo.DiscountAmountInCents); var discountCalculator = IOC.DiscountCalculationService.Actual().Resolve(); Assert.AreEqual(234, discountCalculator.DiscountAmountForOrder(discount, orderInfo)); Assert.AreEqual(234, discountCalculator.DiscountAmountForOrder(discount, convertedOrderInfo)); Assert.AreEqual(234, discountCalculator.DiscountAmountForOrder(convertedDiscount, orderInfo)); Assert.AreEqual(234, discountCalculator.DiscountAmountForOrder(convertedDiscount, convertedOrderInfo)); }
public void RecreateBug20130117_() { var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(12990, 1); productInfo.Id = TestProductService.ProductId1; var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(10000, DiscountOrderCondition.None, 0); discount.CouponCode = "coup"; DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, discount); orderInfo.SetCouponCode("coup"); Assert.AreEqual(10000, orderInfo.DiscountAmountInCents); Assert.AreEqual(10000, orderInfo.DiscountAmountWithVatInCents); Assert.AreEqual(2990, orderInfo.OrderTotalInCents); IOC.OrderUpdatingService.Resolve().AddOrUpdateOrderLine(orderInfo, 0, TestProductService.ProductId1, "update", 1, new List <int>()); Assert.AreEqual(10000, orderInfo.DiscountAmountInCents); Assert.AreEqual(10000, orderInfo.DiscountAmountWithVatInCents); Assert.AreEqual(2990, orderInfo.OrderTotalInCents); }
public void bla() { IOC.IntegrationTest(); IOC.CouponCodeService.SetupNewMock().Setup(m => m.GetAllForDiscount(1234)).Returns(new List <Coupon> { new Coupon(1234, "code", 7), }); var a = IOC.DiscountCalculationService.Actual().Resolve(); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(1000, DiscountOrderCondition.None, 0); discount.Id = 1234; DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(null, discount); var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(2199, 2)); order.CouponCodesData.Add("code"); var actual = a.DiscountAmountForOrder(discount, order); Assert.AreEqual(1000, actual); Assert.NotNull(order.OrderDiscountsFactory); var discountlist = IOC.OrderDiscountService.Resolve().GetApplicableDiscountsForOrder(order, order.Localization); Assert.AreEqual(1, discountlist.Count()); var d = order.Discounts.FirstOrDefault(); Assert.NotNull(d); var basket = Basket.CreateBasketFromOrderInfo(order); var disc = basket.Discounts.FirstOrDefault(); Assert.NotNull(disc); Assert.AreEqual("code", disc.CouponCode); }
public void CombinedTooLargeAmountAndPercentageOrderLineTotalInCentsShouldBeNull() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(1234, DiscountOrderCondition.None, 0), DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(50)); Assert.AreEqual(1000, orderInfo.DiscountAmountInCents); Assert.AreEqual(1000, orderInfo.OrderLineTotalWithVatInCents); Assert.AreEqual(0, orderInfo.GrandtotalInCents); Assert.AreEqual(0, orderInfo.OrderTotalInCents); }
public void CombinedAmountAndPercentage() { var orderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(orderInfo, DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(234, DiscountOrderCondition.None, 0), DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(50)); Assert.AreEqual(734, orderInfo.DiscountAmountInCents); }