Exemplo n.º 1
0
        public void GivenOrderItemWithSurchargePercentageForPartyProductCategoryRevenueQuantityBreak_WhenDeriving_ThenUseSurchargeComponentsForPartyProductCategoryRevenueQuantityBreak()
        {
            const decimal quantityOrdered1 = 3;
            const decimal percentage1 = 5;
            const decimal percentage2 = 10;

            var break1 = new RevenueQuantityBreakBuilder(this.DatabaseSession).WithFrom(50).WithThrough(99).Build();
            var break2 = new RevenueQuantityBreakBuilder(this.DatabaseSession).WithFrom(100).Build();

            new SurchargeComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for quantity break 1")
                .WithRevenueQuantityBreak(break1)
                .WithProductCategory(this.productCategory)
                .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")
                .WithRevenueQuantityBreak(break2)
                .WithProductCategory(this.productCategory)
                .WithPercentage(percentage2)
                .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.Quantity = 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.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGoodBasePrice.Price, item1.CalculatedUnitPrice);
            Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice);

            this.productCategoryRevenueHistory.Quantity = 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.productCategoryRevenueHistory.Quantity = 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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void GivenOrderItemWithDiscountAmountForPartyAncestorProductCategoryRevenueQuantityBreak_WhenDeriving_ThenUseDiscountComponentsForAncestorRevenueQuantityBreak()
        {
            const decimal quantityOrdered1 = 3;
            const decimal amount1 = 1;
            const decimal amount2 = 3;

            var break1 = new RevenueQuantityBreakBuilder(this.DatabaseSession).WithFrom(5).WithThrough(9).Build();
            var break2 = new RevenueQuantityBreakBuilder(this.DatabaseSession).WithFrom(10).Build();

            new DiscountComponentBuilder(this.DatabaseSession)
                .WithSpecifiedFor(this.internalOrganisation)
                .WithDescription("discount good for revenue break 1")
                .WithRevenueQuantityBreak(break1)
                .WithProductCategory(this.ancestorProductCategory)
                .WithPrice(amount1)
                .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 break 2")
                .WithRevenueQuantityBreak(break2)
                .WithProductCategory(this.ancestorProductCategory)
                .WithPrice(amount2)
                .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.ancestorProductCategoryRevenueHistory.Quantity = 2;

            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.ancestorProductCategoryRevenueHistory.Quantity = 5;
            this.order.OnDerive();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(amount1, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGoodBasePrice.Price - amount1, item1.CalculatedUnitPrice);
            Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice);

            this.ancestorProductCategoryRevenueHistory.Quantity = 11M;
            this.order.OnDerive();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(this.currentGoodBasePrice.Price, item1.UnitBasePrice);
            Assert.AreEqual(amount2, item1.UnitDiscount);
            Assert.AreEqual(0, item1.UnitSurcharge);
            Assert.AreEqual(this.currentGoodBasePrice.Price - amount2, item1.CalculatedUnitPrice);
            Assert.AreEqual(this.goodPurchasePrice.Price, item1.UnitPurchasePrice);
        }