Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (session == null || !isEmployeeSet)
            {
                session = new DeductionCalculator();
                EnableEmployeePanel();
                DisableDependentsPanel();
                DisableSummaryPanel();
            }
            else
            {
                if (isEmployeeSet)
                {
                    EE_First_TextBox.Text = session.GetEmployeeFirstName();
                    EE_Last_TextBox.Text  = session.GetEmployeeLastName();
                    EnableDependentsPanel();
                }
            }

            if (!IsPostBack)
            {
                SetDefaultPayInfo();
                UpdateDependentsPanel();
                UpdateSummaryPanel();
            }
        }
Пример #2
0
        public void TestEmployeeDeductionWithDiscount()
        {
            var employee1 = new Employee("Anna", "Jones");
            var cost1     = DeductionCalculator.CalculateDeductionCost(employee1);

            Assert.IsTrue(cost1 == (decimal.Multiply(employeeDeduction, .10M)));
        }
Пример #3
0
        public void TestEmployeeDeduction()
        {
            var employee1 = new Employee("John", "Smith");
            var cost      = DeductionCalculator.CalculateDeductionCost(employee1);

            Assert.IsTrue(cost == 1000.0M);
        }
        public void verify_calculate_deduction_per_annum()
        {
            // Arrange
            var testPerson1 = new Person()
            {
                Type = PersonType.Employee, Name = "ATestPerson"
            };
            var testPerson2 = new Person()
            {
                Type = PersonType.Spouse, Name = "TestPerson"
            };

            var annualDeductionRate = A.Fake <IAnnualDeductionRate>();

            A.CallTo(() => annualDeductionRate.Get(testPerson1.Type)).Returns(ANNUAL_RATE);
            A.CallTo(() => annualDeductionRate.Get(testPerson2.Type)).Returns(ANNUAL_RATE);

            var discountCalculator = A.Fake <IDiscountCalculator>();

            A.CallTo(() => discountCalculator.GetDiscountRate(testPerson1)).Returns(DISCOUNT_RATE);
            A.CallTo(() => discountCalculator.GetDiscountRate(testPerson2)).Returns(0.0M);

            var objectUnderTest = new DeductionCalculator(annualDeductionRate, discountCalculator);

            // Act
            var deductionPerAnnum = objectUnderTest.CalculateDeductionPerAnnum(new List <Person>()
            {
                testPerson1, testPerson2
            });

            // Assert
            var expectedDeductionPerAnnum = (ANNUAL_RATE * (1 - DISCOUNT_RATE)) + (ANNUAL_RATE * (1 - 0.0M));

            Assert.IsTrue(deductionPerAnnum == expectedDeductionPerAnnum);
        }
        public void verify_100_percent_discount_calculation()
        {
            // Arrange
            var testPerson = new Person()
            {
                Type = PersonType.Employee, Name = "ATestPerson"
            };

            var annualDeductionRate = A.Fake <IAnnualDeductionRate>();

            A.CallTo(() => annualDeductionRate.Get(testPerson.Type)).Returns(ANNUAL_RATE);

            var discountCalculator = A.Fake <IDiscountCalculator>();

            A.CallTo(() => discountCalculator.GetDiscountRate(testPerson)).Returns(HUNDRED_PERCENT_DISCOUNT);

            var objectUnderTest = new DeductionCalculator(annualDeductionRate, discountCalculator);

            // Act
            var annualRatewithDiscount = objectUnderTest.CalculateDeductionWithDiscount(testPerson);

            // Assert
            var expectedAnnualRateWithDiscount = ANNUAL_RATE * (1 - HUNDRED_PERCENT_DISCOUNT);

            Assert.IsTrue(annualRatewithDiscount == expectedAnnualRateWithDiscount);
        }
Пример #6
0
        ////////////////////////////////
        /// EVENT HANDLERS /////////////
        ////////////////////////////////

        protected void Restart_Button_Click(object sender, EventArgs e)
        {
            session       = null;
            session       = new DeductionCalculator();
            isEmployeeSet = false;

            ResetEmployeePanel();
            EnableEmployeePanel();
            DisableDependentsPanel();
            DisableSummaryPanel();
            UpdateSummaryPanel();
        }
Пример #7
0
        public void TestEmployeeDeductionWithDependents()
        {
            decimal cost;
            var     employee1 = new Employee("Anna", "Jones");

            cost = DeductionCalculator.CalculateDeductionCost(employee1);
            Assert.IsTrue(employeeDeduction * .10M == cost);
            employee1.AddDependent(new Dependent(DependentType.Spouse, "John", "Doe"));

            DependentDeductionCalculator d = new DependentDeductionCalculator();

            cost = employeeDeduction * .10M + d.CalculateDeduction("John");

            Assert.IsTrue(cost == DeductionCalculator.CalculateDeductionCost(employee1));
        }
Пример #8
0
        public void TestEmployeeDeductionWithMultipleDependents()
        {
            decimal cost;
            decimal cost1;
            decimal cost2;
            DependentDeductionCalculator d = new DependentDeductionCalculator();
            var employee1 = new Employee("Anna", "Jones");

            cost = DeductionCalculator.CalculateDeductionCost(employee1);
            Assert.IsTrue(employeeDeduction * .10M == cost);
            employee1.AddDependent(new Dependent(DependentType.Spouse, "Amy", "Doe"));
            cost1 = d.CalculateDeduction("Amy");

            employee1.AddDependent(new Dependent(DependentType.Spouse, "Antoine", "Doe"));
            cost2 = d.CalculateDeduction("Antoine");


            Assert.IsTrue((employeeDeduction * .10M) + (2 * (dependentDeduction * .10M)) == DeductionCalculator.CalculateDeductionCost(employee1));
        }
Пример #9
0
        public ActionResult CalculateEmployeeDeductions(EmployeeEditViewModel employeeViewModel)
        {
            Employee employee = new Employee(employeeViewModel.FirstName, employeeViewModel.LastName);

            if (employeeViewModel.Dependents != null)
            {
                employeeViewModel.Dependents.ForEach(d => employee.AddDependent(new Dependent(d.DependentType, d.FirstName, d.LastName)));
            }

            decimal cost      = DeductionCalculator.CalculateDeductionCost(employee);
            decimal finalCost = DeductionCalculator.Compute(employee.GetSalary(), cost);

            return(Json(new
            {
                Salary = employee.GetSalary().ToString("C"),
                Deduction = $"{cost.ToString("C")}",
                Total = $"{finalCost.ToString("C")}"
            }));
        }