Пример #1
0
 private static void ReduceByOffer(CombinationProduct offer, List <Product> productsInTheBasket)
 {
     foreach (var product in offer.SubProductIds)
     {
         var productToRemove = productsInTheBasket.Find(p => p.ProductId == product);
         productsInTheBasket.Remove(productToRemove);
     }
 }
Пример #2
0
        private static bool IsOfferValid(CombinationProduct offer, List <Product> productsInTheBasket)
        {
            var productIds     = productsInTheBasket.Select(n => n.ProductId);
            var subProductsIds = offer.SubProductIds;

            bool isValid = new HashSet <ulong>(productIds).IsSupersetOf(subProductsIds);

            return(isValid);
        }
Пример #3
0
        public static void Test4()
        {
            Product p1 = new Product()
            {
                ProductId = 1, Price = 10
            };
            Product p2 = new Product()
            {
                ProductId = 2, Price = 20
            };
            Product p3 = new Product()
            {
                ProductId = 3, Price = 30
            };
            Product p4 = new Product()
            {
                ProductId = 4, Price = 40
            };

            CombinationProduct c1 = new CombinationProduct(
                productId: 5,
                price: 15,
                subProducts: new List <ulong> {
                1, 2
            });

            CombinationProduct c2 = new CombinationProduct(
                productId: 6,
                price: 35,
                subProducts: new List <ulong> {
                2, 3
            });

            var res = SalesPriceCalculator.GetPriceWithSpecialOffers(new List <CombinationProduct>()
            {
                c1, c2
            },
                                                                     new List <Product> {
                p1, p2, p2, p3, p3, p4
            });

            using (new AssertionScope())
            {
                res.Price.Should().Be(120);
                res.ProductIds.Should().Contain(new ulong[] { 5, 6, 3, 4 });
            }
        }
Пример #4
0
        public static void Test2()
        {
            Product p1 = new Product()
            {
                ProductId = 1, Price = 10
            };
            Product p2 = new Product()
            {
                ProductId = 2, Price = 20
            };

            CombinationProduct c1 = new CombinationProduct(
                productId: 4,
                price: 15,
                subProducts: new List <ulong> {
                1, 1
            });

            CombinationProduct c2 = new CombinationProduct(
                productId: 5,
                price: 24,
                subProducts: new List <ulong> {
                1, 2
            });

            var res = SalesPriceCalculator.GetPriceWithSpecialOffers(new List <CombinationProduct>()
            {
                c1, c2
            },
                                                                     new List <Product> {
                p1, p1, p1, p1, p2
            });

            using (new AssertionScope())
            {
                res.Price.Should().Be(49);
                res.ProductIds.Should().Contain(new ulong[] { 1, 4, 5 });
            }
        }