public void BeforeDiscount_ShouldRemoveDiscountCalculation() { IOC.UnitTest(); var price = Price.CreateDiscountedRanged(1000, Enumerable.Empty <Range>(), true, 0, null, i => i / 2, null); Assert.AreEqual(500, price.ValueInCents()); var beforeDiscount = price.BeforeDiscount; Assert.AreEqual(1000, beforeDiscount.ValueInCents()); }
public void ExtensiveCreateDiscountedPriceRangeTest_FirstDiscount() { // Product 400 euro // 10% Vat // PricesIncludingVat = false // Discount = 1000 Assert.AreEqual(1100, Price.CreateDiscountedRanged(40000, null, false, 10m, null, i => i - 1000, null).Discount.WithVat.ValueInCents); Assert.AreEqual(1000, Price.CreateDiscountedRanged(40000, null, false, 10m, null, i => i - 1000, null).Discount.WithoutVat.ValueInCents); Assert.AreEqual(42900, Price.CreateDiscountedRanged(40000, null, false, 10m, null, i => i - 1000, null).WithVat.ValueInCents); Assert.AreEqual(39000, Price.CreateDiscountedRanged(40000, null, false, 10m, null, i => i - 1000, null).WithoutVat.ValueInCents); }
public void DiscountAmountCalculationRegressionTest() { IOC.IntegrationTest(); _source = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1)); var discount = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(50); DefaultFactoriesAndSharedFunctionality.SetDiscountsOnOrderInfo(_source, discount); var price = Price.CreateDiscountedRanged(BasketTotalBeforeDiscount(), null, _source.PricesAreIncludingVAT, _source.AverageOrderVatPercentage, null, i => i - _source.DiscountAmountInCents, _source.Localization); Assert.AreEqual(500, IO.Container.Resolve <IDiscountCalculationService>().DiscountAmountForOrder(discount, _source)); Assert.AreEqual(500, _source.DiscountAmountInCents); Assert.AreEqual(500, price.WithVat.ValueInCents); Assert.AreEqual(500, price.Discount.WithVat.ValueInCents); }
public void HavingAnActiveFreeShippingDiscount_ShouldReflectThatOnOrderParts() { IOC.OrderDiscountRepository.SetupNewMock().Setup(m => m.GetAll(It.IsAny <ILocalization>())).Returns(new List <IOrderDiscount> { new OrderDiscount { DiscountType = DiscountType.FreeShipping, MinimalOrderAmount = 10000, Localization = StoreHelper.CurrentLocalization, RequiredItemIds = new List <int>(), MemberGroups = new List <string>(), AffectedOrderlines = new List <int>() } }); var order = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo( DefaultFactoriesAndSharedFunctionality.CreateProductInfo(40000, 1, 10m)); IOC.OrderService.Resolve().UseDatabaseDiscounts(order); //var orderDiscountService = IOC.OrderDiscountService.Resolve(); //var orderDiscounts = orderDiscountService.GetAll(new StubLocalization()); //var discount = orderDiscounts.Single(); //Assert.AreEqual(DiscountType.FreeShipping, discount.Type); //var filteredOrderDiscounts = orderDiscounts.Where(orderDiscount => !orderDiscount.Disabled && 40000 >= orderDiscount.MinimumOrderAmount.ValueInCents() && (!orderDiscount.RequiredItemIds.Any() /*|| _orderService.OrderContainsItem(order, orderDiscount.RequiredItemIds)*/) && (!orderDiscount.CounterEnabled || orderDiscount.Counter > 0)); //Assert.AreEqual(1, filteredOrderDiscounts.Count()); //var applicableDiscounts = orderDiscountService.GetApplicableDiscountsForOrder(order, order.Localization); //Assert.True(applicableDiscounts.Any()); //Assert.AreEqual(DiscountType.FreeShipping, applicableDiscounts.Single().Type); Assert.NotNull(order.OrderDiscountsFactory); Assert.True(order.OrderDiscounts.Any()); //Assert.False(order.OrderDiscountsWithoutFreeShipping.Any()); Assert.True(order.FreeShipping); var shippingProviderMethod = new ShippingProviderMethod { PriceInCents = 1000 }; var adaptor = new ShippingMethodFulfillmentAdaptor(shippingProviderMethod, true, StoreHelper.CurrentLocalization, order); // freeshipping so chardgedshippingcosts should be 0 Assert.AreEqual(0, order.ChargedShippingCostsInCents); Assert.AreEqual(0, adaptor.Amount.WithVat.ValueInCents); Assert.AreEqual(1000, adaptor.Amount.BeforeDiscount.WithVat.ValueInCents); Assert.AreEqual(1000, adaptor.Amount.Discount.WithVat.ValueInCents); Assert.AreEqual(0, adaptor.Amount.WithVat.ValueInCents); //Assert.AreEqual(1000, adaptor.Amount.BeforeDiscount.WithVat.ValueInCents);// wtf var discountedRanged = Price.CreateDiscountedRanged(shippingProviderMethod.PriceInCents, null, true, order.AverageOrderVatPercentage, null, i => (order.FreeShipping) ? 0 : i, StoreHelper.CurrentLocalization); Assert.AreEqual(0, discountedRanged.WithVat.ValueInCents); Assert.AreEqual(1000, discountedRanged.BeforeDiscount.WithVat.ValueInCents); }
public void WeNeedToFixMultipleUsagesOfTheSamePrice() { // todo: CreateDiscountedRanged is broken depending on order how things are called // todo: replace CreateDiscountedRanged with simpleprice?!? var amount = 40000; var discount = 1000; var price = Price.CreateDiscountedRanged(amount, null, false, 10, null , i => i - discount, null); Assert.AreEqual(40000, price.BeforeDiscount.WithoutVat.ValueInCents); Assert.AreEqual(3900, price.Vat.ValueInCents); Assert.AreEqual(42900, price.WithVat.ValueInCents); Assert.AreEqual(39000, price.WithoutVat.ValueInCents); }
public void CreateDiscountedRanged() { var amount = 40000; var discount = 1000; Assert.AreEqual(40000, Price.CreateDiscountedRanged(amount, null, false, 10, null , i => i - discount, null).BeforeDiscount.WithoutVat.ValueInCents); Assert.AreEqual(3900, Price.CreateDiscountedRanged(amount, null, false, 10, null , i => i - discount, null).Vat.ValueInCents); Assert.AreEqual(42900, Price.CreateDiscountedRanged(amount, null, false, 10, null , i => i - discount, null).WithVat.ValueInCents); Assert.AreEqual(39000, Price.CreateDiscountedRanged(amount, null, false, 10, null , i => i - discount, null).WithoutVat.ValueInCents); }
public void TestingDefaultRangeAndUsingRangesWithCount() { IOC.UnitTest(); UwebshopRequest.Current.OrderInfo = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(); const int orderCount = 15; var ranges = new List <Range> { new Range { From = 1, To = 10, PriceInCents = 500 }, new Range { From = 10, To = 20, PriceInCents = 300 } }; var price = Price.CreateDiscountedRanged(1000, ranges, true, 0, o => orderCount, i => i, null); Assert.AreEqual(500, price.ValueInCents()); var ranged = price.Ranged; Assert.AreEqual(300, ranged.ValueInCents()); }