Пример #1
0
        private static void RunDiscountScenario()
        {
            var basicInfo     = "{\"name\": \"Dishant\",\"email\": \"[email protected]\",\"creditHistory\": \"good\",\"country\": \"india\",\"loyalityFactor\": 3,\"totalPurchasesToDate\": 10000}";
            var orderInfo     = "{\"totalOrders\": 5,\"recurringItems\": 2}";
            var telemetryInfo = "{\"noOfVisitsPerMonth\": 10,\"percentageOfBuyingToVisit\": 15}";

            var     converter = new ExpandoObjectConverter();
            dynamic input1    = JsonConvert.DeserializeObject <ExpandoObject>(basicInfo, converter);
            dynamic input2    = JsonConvert.DeserializeObject <ExpandoObject>(orderInfo, converter);
            dynamic input3    = JsonConvert.DeserializeObject <ExpandoObject>(telemetryInfo, converter);

            var inputs = new dynamic[]
            {
                input1,
                input2,
                input3
            };

            var repository      = new RulesRepository();
            var discountService = new DiscountService(repository);
            var discountOffered = discountService.CalculateDiscount(inputs);
            var discountMessage = discountOffered == 0m
                ? "The user is not eligible for any discount."
                : $"Discount offered is {discountOffered * 100}% over MRP.";

            Console.WriteLine(discountMessage);
        }
Пример #2
0
        private static void RunRetirementScenario()
        {
            var repository = new RulesRepository();
            var service    = new RetirementService(repository);
            var employee   = new Employee {
                LengthOfServiceInDays = 25, IsOverridden = true
            };
            var isEligible = service.IsEligible(employee);

            Console.WriteLine($"Eligible for Retirement?:  {isEligible}");
        }