public void GivenOrderItemWithBasePriceForPartyProductCategoryRevenueValueBreak_WhenDeriving_ThenUseBasePriceForProductCategoryRevenueValueBreak() { const decimal quantityOrdered1 = 3; const decimal priceIs1 = 1; const decimal priceIs3 = 3; var break1 = new RevenueValueBreakBuilder(this.DatabaseSession).WithFromAmount(50).WithThroughAmount(99).WithProductCategory(this.productCategory).Build(); var break2 = new RevenueValueBreakBuilder(this.DatabaseSession).WithFromAmount(100).WithProductCategory(this.productCategory).Build(); new BasePriceBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("baseprice good for revenue break 1") .WithRevenueValueBreak(break1) .WithProductCategory(this.productCategory) .WithPrice(priceIs1) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); new BasePriceBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("baseprice good for revenue break 2") .WithRevenueValueBreak(break2) .WithProductCategory(this.productCategory) .WithPrice(priceIs3) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); this.productCategoryRevenueHistory.Revenue = 20M; var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantityOrdered(quantityOrdered1).Build(); this.order.AddSalesOrderItem(item1); this.DatabaseSession.Derive(true); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); this.productCategoryRevenueHistory.Revenue = 50M; this.order.OnDerive(); this.DatabaseSession.Derive(true); Assert.AreEqual(priceIs1, item1.UnitBasePrice); this.productCategoryRevenueHistory.Revenue = 110M; this.order.OnDerive(); this.DatabaseSession.Derive(true); Assert.AreEqual(priceIs3, item1.UnitBasePrice); }
public void GivenOrderItemWithBetterDiscountForRevenueValueBreakThenForRevenueQuantityBreak_WhenDeriving_ThenUseDiscountForRevenueValueBreak() { const decimal quantityOrdered1 = 3; const decimal valueDiscount1 = 4; const decimal valueDiscount2 = 5; const decimal quantityDiscount1 = 1; const decimal quantityDiscount2 = 3; var valueBreak1 = new RevenueValueBreakBuilder(this.DatabaseSession).WithFromAmount(50).WithThroughAmount(99).Build(); var valueBreak2 = new RevenueValueBreakBuilder(this.DatabaseSession).WithFromAmount(100).Build(); var quantityBreak1 = new RevenueQuantityBreakBuilder(this.DatabaseSession).WithFrom(2).WithThrough(9).Build(); var quantityBreak2 = new RevenueQuantityBreakBuilder(this.DatabaseSession).WithFrom(10).Build(); new DiscountComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for revenue value break 1") .WithRevenueValueBreak(valueBreak1) .WithProductCategory(this.productCategory) .WithPrice(valueDiscount1) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); new DiscountComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for revenue value break 2") .WithRevenueValueBreak(valueBreak2) .WithProductCategory(this.productCategory) .WithPrice(valueDiscount2) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); new DiscountComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for revenue quantity break 1") .WithRevenueQuantityBreak(quantityBreak1) .WithProductCategory(this.productCategory) .WithPrice(quantityDiscount1) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); new DiscountComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for revenue quantity break 2") .WithRevenueQuantityBreak(quantityBreak2) .WithProductCategory(this.productCategory) .WithPrice(quantityDiscount2) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.InstantiateObjects(this.DatabaseSession); this.productCategoryRevenueHistory.Revenue = 20M; this.productCategoryRevenueHistory.Quantity = 1; this.order.OnDerive(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantityOrdered(quantityOrdered1).Build(); this.order.AddSalesOrderItem(item1); this.DatabaseSession.Derive(true); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); Assert.AreEqual(0, item1.UnitDiscount); Assert.AreEqual(0, item1.UnitSurcharge); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); this.productCategoryRevenueHistory.Revenue = 50M; this.productCategoryRevenueHistory.Quantity = 3; this.order.OnDerive(); this.DatabaseSession.Derive(true); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); Assert.AreEqual(valueDiscount1, item1.UnitDiscount); Assert.AreEqual(0, item1.UnitSurcharge); Assert.AreEqual(this.currentGoodBasePrice.Price - valueDiscount1, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); this.productCategoryRevenueHistory.Revenue = 110M; this.productCategoryRevenueHistory.Quantity = 10; this.order.OnDerive(); this.DatabaseSession.Derive(true); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); Assert.AreEqual(valueDiscount2, item1.UnitDiscount); Assert.AreEqual(0, item1.UnitSurcharge); Assert.AreEqual(this.currentGoodBasePrice.Price - valueDiscount2, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); }
public void GivenOrderItemWithSurchargePercentageForPartyRevenueValueBreak_WhenDeriving_ThenUseSurchargeComponentsForPartyRevenueValueBreak() { const decimal quantityOrdered1 = 3; const decimal percentage1 = 5; const decimal percentage2 = 10; var break1 = new RevenueValueBreakBuilder(this.DatabaseSession).WithFromAmount(50).WithThroughAmount(99).Build(); var break2 = new RevenueValueBreakBuilder(this.DatabaseSession).WithFromAmount(100).Build(); new SurchargeComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for quantity break 1") .WithRevenueValueBreak(break1) .WithProduct(this.good) .WithPercentage(percentage1) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); new SurchargeComponentBuilder(this.DatabaseSession) .WithSpecifiedFor(this.internalOrganisation) .WithDescription("discount good for quantity break 2") .WithRevenueValueBreak(break2) .WithProduct(this.good) .WithPercentage(percentage2) .WithFromDate(DateTime.UtcNow.AddMinutes(-1)) .WithThroughDate(DateTime.UtcNow.AddYears(1).AddDays(-1)) .Build(); this.DatabaseSession.Derive(true); this.DatabaseSession.Commit(); this.DatabaseSession.Derive(true); this.InstantiateObjects(this.DatabaseSession); this.partyRevenueHistory.Revenue = 20M; this.order.OnDerive(); var item1 = new SalesOrderItemBuilder(this.DatabaseSession).WithProduct(this.good).WithQuantityOrdered(quantityOrdered1).Build(); this.order.AddSalesOrderItem(item1); this.DatabaseSession.Derive(true); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); Assert.AreEqual(0, item1.UnitSurcharge); Assert.AreEqual(0, item1.UnitDiscount); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); this.partyRevenueHistory.Revenue = 50M; this.order.OnDerive(); this.DatabaseSession.Derive(true); var amount1 = decimal.Round((this.currentGoodBasePrice.Price * percentage1) / 100, 2); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); Assert.AreEqual(amount1, item1.UnitSurcharge); Assert.AreEqual(0, item1.UnitDiscount); Assert.AreEqual(this.currentGoodBasePrice.Price + amount1, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); this.partyRevenueHistory.Revenue = 110M; this.order.OnDerive(); this.DatabaseSession.Derive(true); var amount2 = decimal.Round((this.currentGoodBasePrice.Price * percentage2) / 100, 2); Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice); Assert.AreEqual(amount2, item1.UnitSurcharge); Assert.AreEqual(0, item1.UnitDiscount); Assert.AreEqual(this.currentGoodBasePrice.Price + amount2, item1.CalculatedUnitPrice); Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice); }