public void Can_Calculate_TotalCostOfBenefits_Some_Dependents_Names_Start_With_Discount_Letter()
        {
            var employee = new Employee();
            employee.Name = "Thomas";
            employee.Dependents = new Collection<Dependent>();

            var dependent1 = new Dependent();
            dependent1.Name = "Allison";
            employee.Dependents.Add(dependent1);

            var dependent2 = new Dependent();
            dependent2.Name = "Alfred";
            employee.Dependents.Add(dependent2);

            var dependent3 = new Dependent();
            dependent3.Name = "Rick";
            employee.Dependents.Add(dependent3);

            var result = _service.TotalCostOfBenefits(employee);

            // full-cost employee, full-cost dependent, 2 discounted dependents
            decimal expectedCost = 1000 + 500 + 450 + 450;

            Assert.AreEqual(result, expectedCost);
        }
        public void Can_Calculate_EmployeeCostOfBenefits_Name_Starts_With_Discount_Letter()
        {
            var employee = new Employee();
            employee.Name = "Alfred";

            var result = _service.CalculateEmployeeCostOfBenefits(employee);

            Assert.AreEqual(result, 900);
        }
        public decimal CalculateEmployeeCostOfBenefits(Employee employee)
        {
            if (!string.IsNullOrEmpty(employee.Name) && employee.Name.StartsWith(_discountLetter))
            {
                return _employeeCost*(1 - _discountPercentage);
            }

            return _employeeCost;
        }
        public decimal TotalCostOfBenefits(Employee employee)
        {
            var totalCost = CalculateEmployeeCostOfBenefits(employee);

            if (employee.Dependents != null && employee.Dependents.Any())
            {
                totalCost += employee.Dependents.Sum(x => CalculateDependentCostOfBenefits(x));
            }

            return totalCost;
        }