如何使用 Rhino Mocks 框架在 AAA 语法中编写这个简单的基于 Record-and-replay 的测试?
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);
}