Ejemplo n.º 1
0
 Args.AppliedDiscount AppliedDiscount(
     Product product, BasketDiscount basketDiscount, int times, decimal basketItemNewPrice) =>
 new Args.AppliedDiscount
 {
     ProductId  = product.Id,
     DiscountId = basketDiscount.Id,
     NumberOfBasketItemsThatShouldReceiveIt = times,
     BasketItemPrice = basketItemNewPrice
 };
Ejemplo n.º 2
0
        public async Task Run()
        {
            var butter = Product(1, 0.8m);
            var milk   = Product(2, 1.15m);
            var bread  = Product(3, 1);

            var twoButtersDiscount = new BasketDiscount
            {
                Id = 1,
                RequiredProductId         = butter.Id,
                TargetProductId           = bread.Id,
                RequiredPerOneDiscounted  = 2,
                TargetProductDiscountedBy = 0.5m
            };

            var threeMilksDiscount = new BasketDiscount
            {
                Id = 2,
                RequiredProductId         = milk.Id,
                TargetProductId           = milk.Id,
                RequiredPerOneDiscounted  = 3,
                TargetProductDiscountedBy = 1
            };

            var otherDiscounts = new[]
            {
                new BasketDiscount
                {
                    Id = 3,
                    RequiredProductId         = butter.Id,
                    TargetProductId           = butter.Id,
                    RequiredPerOneDiscounted  = 5,
                    TargetProductDiscountedBy = 2
                },
                new BasketDiscount
                {
                    Id = 4,
                    RequiredProductId         = Product(6, -1).Id,
                    TargetProductId           = butter.Id,
                    RequiredPerOneDiscounted  = 5,
                    TargetProductDiscountedBy = 2
                },
            };

            void AddBaseArgs(Args a)
            {
                a.Products  = new[] { butter, milk, bread, Product(4, -1), Product(5, -1) };
                a.Discounts = new[] { twoButtersDiscount, threeMilksDiscount }.Concat(otherDiscounts);
            }

            await RunWithArgs(a =>
            {
                AddBaseArgs(a);
                a.BasketItems         = new[] { BasketItem(bread), BasketItem(butter), BasketItem(milk) };
                a.AppliedDiscounts    = new Args.AppliedDiscount[0];
                a.ExpectedBasketPrice = 2.95m;
            });

            await RunWithArgs(a =>
            {
                AddBaseArgs(a);
                a.BasketItems      = new[] { BasketItem(butter), BasketItem(butter), BasketItem(bread), BasketItem(bread) };
                a.AppliedDiscounts = new[]
                {
                    AppliedDiscount(bread, twoButtersDiscount, 1, 0.5m),
                };
                a.ExpectedBasketPrice = 3.10m;
            });

            await RunWithArgs(a =>
            {
                AddBaseArgs(a);
                a.BasketItems      = GenerateSequence(() => BasketItem(milk), 4);
                a.AppliedDiscounts = new[]
                {
                    AppliedDiscount(milk, threeMilksDiscount, 1, 0)
                };
                a.ExpectedBasketPrice = 3.45m;
            });

            await RunWithArgs(a =>
            {
                AddBaseArgs(a);
                a.BasketItems = GenerateSequence(() => BasketItem(milk), 8)
                                .Append(BasketItem(butter))
                                .Append(BasketItem(butter))
                                .Append(BasketItem(bread))
                ;
                a.AppliedDiscounts = new[]
                {
                    AppliedDiscount(bread, twoButtersDiscount, 1, 0.5m),
                    AppliedDiscount(milk, threeMilksDiscount, 2, 0)
                };
                a.ExpectedBasketPrice = 9.00m;
            });
        }