Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("######################## Sample Promotion Engine Implementation ####################################");

            // Setting up Dependency Injection
            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IPromotionCalculationManager, PromotionCalculationManager>()
                                  .BuildServiceProvider();

            var promotionCalculationManager = serviceProvider.GetService <IPromotionCalculationManager>();

            SalesProductsLineItems salesProductsLineItems = new SalesProductsLineItems();

            salesProductsLineItems.SalesProductDetails.Add("A", 3);
            salesProductsLineItems.SalesProductDetails.Add("B", 5);
            salesProductsLineItems.SalesProductDetails.Add("C", 2);
            salesProductsLineItems.SalesProductDetails.Add("D", 2);

            Console.WriteLine("Product List:");
            foreach (var product in salesProductsLineItems.SalesProductDetails)
            {
                Console.WriteLine("Product Name: {0} => Product Count: {1}", product.Key, product.Value);
            }

            try
            {
                var promotionalPrice = promotionCalculationManager.ApplyPromotion(salesProductsLineItems).Result;
                Console.WriteLine("Total Price (With Promotion Applied): " + promotionalPrice);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception During Applying Promotion. Exception: " + ex.ToString());
            }
        }
Exemplo n.º 2
0
        public void Senario_B_Unit_Test()
        {
            // Arrange
            SalesProductsLineItems salesProductsLineItems = new SalesProductsLineItems();

            salesProductsLineItems.SalesProductDetails.Add("A", 5);
            salesProductsLineItems.SalesProductDetails.Add("B", 5);
            salesProductsLineItems.SalesProductDetails.Add("C", 1);

            var promotionCalculationManager = new PromotionCalculationManager();

            // Act
            var promotionalPrice = promotionCalculationManager.ApplyPromotion(salesProductsLineItems).Result;

            // Assert
            promotionalPrice.Should().Be(370);
        }
Exemplo n.º 3
0
        public async Task <float> ApplyPromotion(SalesProductsLineItems salesProductsLineItems)
        {
            ProductsList         products   = new ProductsList();
            PromotionsOfferRules promotions = new PromotionsOfferRules();

            Console.WriteLine("Total Price (Without Promotions): " + GetTotalPrice(salesProductsLineItems.SalesProductDetails));

            float promotionsDiscountOffers = 0;

            // Get The Promotional Dicount Price
            foreach (var promotion in promotions.promotionsRulesList)
            {
                var discountPrice = GetPromotionCouponDiscountPrice(promotion, salesProductsLineItems.SalesProductDetails);
                promotionsDiscountOffers = promotionsDiscountOffers + discountPrice;
            }

            float totalPrice = GetTotalPrice(salesProductsLineItems.SalesProductDetails);

            var promotionalPrice = promotionsDiscountOffers + totalPrice;

            return(await Task.FromResult(promotionalPrice));
        }