Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tests for visitor pattern blog post
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
namespace visitor.pattern.specs
{
[TestFixture]
public class when_calculating_a_hourly_employees_wages
{
private HourlyEmployee jacob;
private EmployeePaycheckVisitor employeePaycheckVisitor;
[Test]
public void Should_be_able_to_view_how_many_hours_worked_and_pay_amount_received()
{
jacob = new HourlyEmployee(“Bob”, 35.00m);
jacob.addTimeWorked(120);
jacob.addSickDaysUsed(1);
jacob.addVacationDaysUsed(2);
employeePaycheckVisitor = new EmployeePaycheckVisitor();
Employee e = jacob;
e.accept(employeePaycheckVisitor);
Assert.That(employeePaycheckVisitor.EarnedWages, Is.EqualTo(3920.00m));
Assert.That(employeePaycheckVisitor.SickDayDeductions, Is.EqualTo(280.00m));
Assert.That(employeePaycheckVisitor.PaycheckSummaryLine, Is.EqualTo(“Bob has worked 120 ” +
“hours as an hourly employee and has earned $3,920.00 (Sick Days: 1/$280.00 Vacation Days: 2?));
}
[Test]
public void Should_be_able_to_view_how_many_hours_worked_and_pay_amount_received_for_another_hourly_employee()
{
jacob = new HourlyEmployee(“Jacob”, 50.45m);
jacob.addTimeWorked(12);
jacob.addSickDaysUsed(0);
jacob.addVacationDaysUsed(5);
employeePaycheckVisitor = new EmployeePaycheckVisitor();
Employee e = jacob;
e.accept(employeePaycheckVisitor);
Assert.That(employeePaycheckVisitor.EarnedWages, Is.EqualTo(605.40m));
Assert.That(employeePaycheckVisitor.SickDayDeductions, Is.EqualTo(0.00m));
Assert.That(employeePaycheckVisitor.PaycheckSummaryLine, Is.EqualTo(“Jacob has worked 12 hours ” +
as an hourly employee and has earned $605.40 (Sick Days: 0/$0.00 Vacation Days: 5?));
}
}
[TestFixture]
public class when_calculating_a_fulltime_employees_wages
{
private FulltimeEmployee jacob;
private EmployeePaycheckVisitor employeePaycheckVisitor;
[Test]
public void Should_be_able_to_view_how_many_hours_worked_amount_deducted_for_sick_days_and_pay_amount_received()
{
jacob = new FulltimeEmployee(“Bob”, 35000);
jacob.addBusinessDaysWorked(120);
jacob.addSickDaysUsed(1);
jacob.addVacationDaysUsed(2);
employeePaycheckVisitor = new EmployeePaycheckVisitor();
Employee e = jacob;
e.accept(employeePaycheckVisitor);
Assert.That(employeePaycheckVisitor.EarnedWages, Is.EqualTo(16018.85m));
Assert.That(employeePaycheckVisitor.SickDayDeductions, Is.EqualTo(135m));
Assert.That(employeePaycheckVisitor.PaycheckSummaryLine, Is.EqualTo(“Bob has worked 120 business ” +
“days as a fulltime employee and has earned $16,018.85 (Sick Days: 1/$135.00 Vacation Days: 2?));
}
[Test]
public void Should_be_able_to_view_how_many_hours_worked_amount_deducted_for_sick_days_and_pay_amount_received_for_another_hourly_employee()
{
jacob = new FulltimeEmployee(“Jacob”, 50000);
jacob.addBusinessDaysWorked(12);
jacob.addSickDaysUsed(0);
jacob.addVacationDaysUsed(5);
employeePaycheckVisitor = new EmployeePaycheckVisitor();
Employee e = jacob;
e.accept(employeePaycheckVisitor);
Assert.That(employeePaycheckVisitor.EarnedWages, Is.EqualTo(2307.69m));
Assert.That(employeePaycheckVisitor.SickDayDeductions, Is.EqualTo(0.00m));
Assert.That(employeePaycheckVisitor.PaycheckSummaryLine, Is.EqualTo(“Jacob has worked 12 business ” +
“days as a fulltime employee and has earned $2,307.69 (Sick Days: 0/$0.00 Vacation Days: 5?));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.