private PolicyBonus[] CalculatePolicyBonus(Policy[] policies, FacebookBonusSettings settings)
        {
            var resultPolicyBonus = new PolicyBonus[policies.Length];
            int count             = 0;
            int total             = 0;
            int temp = 0;

            foreach (Policy policy in SortPoliciesWithConditionSpecifiedInSettings(policies, settings))
            {
                temp = CalculateBonusIntensivePoints(policy.Premium, settings.BonusPercentage);
                var elementPolicyBonus = new PolicyBonus()
                {
                    PolicyNumber  = policy.PolicyNumber,
                    BonusInPoints = temp
                };

                if (IsTotalBiggerThanMaxiumPointAndIsMaxiumBiggerThan0(total + temp, settings.MaximumBonus))
                {
                    temp  = Convert.ToInt32(settings.MaximumBonus) - total;
                    total = Convert.ToInt32(settings.MaximumBonus);
                    elementPolicyBonus.BonusInPoints = temp;
                }
                else
                {
                    total += temp;
                }
                resultPolicyBonus[count] = elementPolicyBonus;
                count++;
            }
            return(resultPolicyBonus);
        }
        private FacebookBonus CalculateFacebookBonus(Policy[] policies, FacebookBonusSettings settings)
        {
            var resultFacebookBonus = new FacebookBonus();
            int inputPoliciesLength = policies.Length;

            resultFacebookBonus.PolicyBonuses = new PolicyBonus[inputPoliciesLength];
            resultFacebookBonus.PolicyBonuses = CalculatePolicyBonus(policies, settings);

            return(resultFacebookBonus);
        }
        private static void Main(string[] args)
        {
            var secondPolicy = new Policy()
            {
                PolicyNumber = "P001", Premium = 200, StartDate = new DateTime(2016, 05, 06)
            };
            var firstPolicy = new Policy()
            {
                PolicyNumber = "P002", Premium = 100, StartDate = new DateTime(2017, 08, 11)
            };
            var thirdPolicy = new Policy()
            {
                PolicyNumber = "P003", Premium = 100, StartDate = new DateTime(2017, 09, 12)
            };

            var settings = new FacebookBonusSettings()
            {
                BonusPercentage = 3,
                MaximumBonus    = 10,
                PolicySorter    = new AscendingOrderOfPoliciesStartDate()
            };

            var calculationInput = new FacebookBonusCalculationInput()
            {
                PoliciesOfCustomer = new Policy[] { firstPolicy, secondPolicy, thirdPolicy },
                Settings           = settings
            };

            var facebookBonusCalculator = new FacebookBonusCalculator();

            FacebookBonus facebookBonus = facebookBonusCalculator.Calculate(calculationInput);
            PolicyBonus   policyBonus   = facebookBonus.PolicyBonuses[0];

            Console.WriteLine(policyBonus.PolicyNumber + " " + policyBonus.BonusInPoints);
            var expectedPolicyBonus = new PolicyBonus()
            {
                PolicyNumber = "P001", BonusInPoints = 6
            };

            Console.WriteLine("\n" + facebookBonus.PolicyBonuses.Contains(expectedPolicyBonus));

            Console.ReadLine();
        }
        private static IEnumerable <Policy> SortPoliciesWithConditionSpecifiedInSettings(IEnumerable <Policy> policiesOfCustomer, FacebookBonusSettings settings)
        {
            IPolicySortService policySortService = new DescendingOrderOfPoliciesNumber();

            if (settings.PolicySorter != null)
            {
                policySortService = settings.PolicySorter;
            }
            policiesOfCustomer = policySortService.Sort(policiesOfCustomer);
            return(policiesOfCustomer);
        }