public void PayIntervalShouldMatchPaycheckCount() { var expectedPaycheckCounts = new List <int>() { 12 /*monthly*/, 26 /*biweekly*/, 52 /*weekly*/ }; expectedPaycheckCounts.ForEach(expectedPaycheckCount => { var employee = new Employee(1, "Alan", "Smith"); var salary = new Salary() { PerPeriod = 1000, Interval = (PayInterval)expectedPaycheckCount }; var benefit = new Benefit() { Beneficiary = employee, GrossCost = 1000 }; var benefitPackage = new BenefitPackage(); benefitPackage.Benefits.Add(benefit); var mockSalaryLogic = new Mock <ISalaryLogic>(); mockSalaryLogic.Setup(x => x.GetItem(employee)).Returns(salary); var mockBenefitLogic = new Mock <IBenefitPackageLogic>(); mockBenefitLogic.Setup(x => x.GetItem(employee)).Returns(benefitPackage); var payrollLogic = new PayrollLogic(mockSalaryLogic.Object, mockBenefitLogic.Object); Payroll payroll = payrollLogic.Calculate(employee); Assert.AreEqual(expectedPaycheckCount, payroll.PaySchedule.Count); }); }
protected void computePayroll(Object sender, EventArgs events) { try{ double hours = double.Parse(hoursWorkedInput.Text); double rate = double.Parse(payRateInput.Text); int dependents = int.Parse(dependentsComboBox.Text); bool health = false; if (yesRadioButton.Checked == true) { health = true; } string name = string.Concat(firstnameinput.Text.ToString().ToUpper(), " ", secondnameinput.Text.ToString().ToUpper()); double regular = PayrollLogic.computeRegularPay(hours, rate); double overtime = PayrollLogic.computeOvertimePay(hours, rate); double gross = PayrollLogic.computeGrossPay(regular, overtime); double withhold = PayrollLogic.computeWithholdTax(dependents, gross); double healthFee = PayrollLogic.computeHealth(dependents, health); double ssFee = PayrollLogic.computeSocialSecurity(gross); double netPay = PayrollLogic.computeNetPay(gross, withhold, healthFee, ssFee); nameOutput.Text = name; regularPayOutput.Text = string.Format("{0:F2}", regular); overtimePayOutput.Text = string.Format("{0:F2}", overtime); grossPayOutput.Text = string.Format("{0:F2}", gross); withholdTaxOutput.Text = string.Format("{0:F2}", withhold); healthOutput.Text = string.Format("{0:F2}", healthFee); socialSecutiryOutput.Text = string.Format("{0:F2}", ssFee); netPayOutput.Text = string.Format("{0:F2}", netPay); }catch (Exception e) { MessageBox.Show("Error in input: Try Again!"); } }
public void SalaryShouldMatchPayScheduleSummation() { var employee = new Employee(1, "Alan", "Smith"); var salary = new Salary() { PerPeriod = 1000, Interval = PayInterval.Weekly }; var benefit = new Benefit() { Beneficiary = employee, GrossCost = 1000 }; var benefitPackage = new BenefitPackage(); benefitPackage.Benefits.Add(benefit); var mockSalaryLogic = new Mock <ISalaryLogic>(); mockSalaryLogic.Setup(x => x.GetItem(employee)).Returns(salary); var mockBenefitLogic = new Mock <IBenefitPackageLogic>(); mockBenefitLogic.Setup(x => x.GetItem(employee)).Returns(benefitPackage); var payrollLogic = new PayrollLogic(mockSalaryLogic.Object, mockBenefitLogic.Object); Payroll payroll = payrollLogic.Calculate(employee); Assert.AreEqual(payroll.Salary.Yearly, payroll.PaySchedule.Sum(x => x.GrossPay)); Assert.AreEqual(payroll.NetYearlySalary, payroll.PaySchedule.Sum(x => x.NetPay)); }