Reputation: 53323
How can I write this simple Record-and-replay based test in AAA Syntax with Rhino Mocks framework?
public interface IStudentReporter
{
void PrintStudentReport(List<IStudent> students);
List<IStudent> GetUnGraduatedStudents(List<IStudent> students);
void AddStudentsToEmptyClassRoom(IClassRoom classroom, List<IStudent>
}
[Test]
public void PrintStudentReport_ClassRoomPassed_StudentListOfFive()
{
IClassRoom classRoom = GetClassRoom(); // Gets a class with 5 students
MockRepository fakeRepositoery = new MockRepository();
IStudentReporter reporter = fakeRepositoery
.StrictMock<IStudentReporter>();
using(fakeRepositoery.Record())
{
reporter.PrintStudentReport(null);
// We decalre constraint for parameter in 0th index
LastCall.Constraints(List.Count(Is.Equal(5)));
}
reporter.PrintStudentReport(classRoom.Students);
fakeRepositoery.Verify(reporter);
}
Upvotes: 0
Views: 208
Reputation: 53323
Ok. I found the way:
[Test]
public void PrintStudentReport_ClassRoomPassed_StudentListOfFive_WithAAA()
{
//Arrange
IClassRoom classRoom = GetClassRoom(); // Gets a class with 5 students
IStudentReporter reporter = MockRepository.GenerateMock<IStudentReporter>();
//Act
reporter.PrintStudentReport(classRoom.Students);
//Assert
reporter
.AssertWasCalled(r => r.PrintStudentReport(
Arg<List<IStudent>>
.List.Count(Is.Equal(5)))
);
}
Upvotes: 0