tests for visitor pattern blog post

  • Download Gist
visitor_pattern_tests_20081130_blogpost.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
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?));
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.