0
如何在帶有Rhino Mocks框架的AAA語法中編寫此簡單的基於記錄和重放的測試?如何使用Rhino Mocks框架在AAA語法中編寫此簡單測試?
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);
}
我想yould應該在這裏使用`GenerateStub`。如果你想使用`.Expect`,你只需要'GenerateMock`。查看關於[GenerateMock和GenerateStub之間的區別](http://www.ayende.com/wiki/Rhino+Mocks+3.5.ashx)的用戶指南(儘管老實說整個頁面也有點混亂。 ..我指的是它所說的部分:「在大多數情況下,你應該更喜歡使用存根,只有當你測試複雜的相互作用時,我纔會推薦使用模擬對象。」) – 2010-12-09 20:12:24