コード例 #1
0
        public void Calculate_WhenProvidedNull_ReturnsEmpty()
        {
            var calculator = new BenefitsWithDiscountsCalculator();

            var result = calculator.Calculate(null);

            result.ShouldBeEmpty();
        }
コード例 #2
0
        public void Calculate_WhenProvidedEmployee_WithEmptyName_DoesNotReturnStandardBenefitDeduction()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee();

            var result = calculator.Calculate(employee).ToList();

            result.ShouldBeEmpty();
        }
コード例 #3
0
        public void Calculate_WhenProvidedEmployeesAndOrDependents_ReturnsExpectedTotal(Employee employee, decimal expectedTotal)
        {
            var calculator = new BenefitsWithDiscountsCalculator();

            var result      = calculator.Calculate(employee).ToList();
            var actualTotal = result.Sum(x => x.PerAnnum);

            actualTotal.ShouldEqual(expectedTotal);
        }
コード例 #4
0
        public void Calculate_WhenEmployeeNotElegibleForLetterADiscount_DoesNotReturnNameDiscount()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee
            {
                FirstName = "Bill"
            };

            var result = calculator.Calculate(employee).ToList();

            var standardBenefit = result.FirstOrDefault(x => x.Description == BenefitsWithDiscountsCalculator.Descriptions.NameStartsWithADiscount);

            standardBenefit.ShouldBeNull();
        }
コード例 #5
0
        public void Calculate_WhenProvidedEmployee_WithNonEmptyName_ReturnsStandardBenefitDeduction()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee
            {
                FirstName = "first",
                LastName  = "name"
            };

            var result = calculator.Calculate(employee).ToList();

            var standardBenefit = result.FirstOrDefault(x => x.Description == BenefitsWithDiscountsCalculator.Descriptions.EmployeeStandardBenefitDeduction);

            standardBenefit.ShouldNotBeNull();
        }
コード例 #6
0
        public void Calculate_WhenEmployeeHasDependents_AndNamesAreEmpty_DoesNotReturnBenefitDeductionPerDependent()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee
            {
                FirstName  = "Bill",
                Dependents = new List <Person>
                {
                    new Person(),
                    new Person()
                }
            };

            var result = calculator.Calculate(employee);

            var dependentDeduction = result.Where(x => x.Description == BenefitsWithDiscountsCalculator.Descriptions.DependentStandardBenefitDeduction).ToList();

            dependentDeduction.ShouldBeEmpty();
        }
コード例 #7
0
        public void Calculate_WhenDependentElegibleForLetterADiscount_ReturnsNameDiscount()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee
            {
                FirstName  = "Bill",
                Dependents = new List <Person>
                {
                    new Person
                    {
                        FirstName = "Alice"
                    }
                }
            };

            var result = calculator.Calculate(employee);

            var nameDiscount = result.Where(x => x.Description == BenefitsWithDiscountsCalculator.Descriptions.NameStartsWithADiscount).ToList();

            nameDiscount.ShouldNotBeNull();
        }
コード例 #8
0
        public void Calculate_WhenEmployeeHasDependents_AndNamesAreNotEmpty_ReturnsBenefitDeductionPerDependent()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee
            {
                FirstName  = "Bill",
                Dependents = new List <Person>
                {
                    new Person {
                        FirstName = "John"
                    },
                    new Person {
                        FirstName = "Jill"
                    }
                }
            };

            var result = calculator.Calculate(employee);

            var dependentDeduction = result.Where(x => x.Description == BenefitsWithDiscountsCalculator.Descriptions.DependentStandardBenefitDeduction).ToList();

            dependentDeduction.Count.ShouldEqual(employee.Dependents.Count);
        }
コード例 #9
0
        public void Calculate_WhenNameStartsWithADiscountIsAvailable_ReturnsLineItemsWithCorrectTotal()
        {
            var calculator = new BenefitsWithDiscountsCalculator();
            var employee   = new Employee
            {
                FirstName = "Ann"
            };

            var result = calculator.Calculate(employee).ToList();

            var expectedBenefitDeduction         = -BenefitsWithDiscountsCalculator.EmployeeBenefitDeduction;
            var expectedNameDiscountPerAnnum     = expectedBenefitDeduction * BenefitsWithDiscountsCalculator.NameStartsWithLetterADiscountMultiplier;
            var expectedNameDiscountPerPayPeriod = expectedNameDiscountPerAnnum.FromAnnumToPayPeriods(Constants.NumberOfPayPeriodsPerYear).ToList();
            var nameDiscount = result.FirstOrDefault(x => x.Description == BenefitsWithDiscountsCalculator.Descriptions.NameStartsWithADiscount);

            nameDiscount.PerAnnum.ShouldEqual(expectedNameDiscountPerAnnum);

            nameDiscount.PerPayPeriod.Count.ShouldEqual(expectedNameDiscountPerPayPeriod.Count);

            for (var i = 0; i < expectedNameDiscountPerPayPeriod.Count; i++)
            {
                nameDiscount.PerPayPeriod[i].ShouldEqual(expectedNameDiscountPerPayPeriod[i]);
            }
        }