C# 如何使用Rhino Mocks框架以AAA语法编写这个简单的测试?

C# 如何使用Rhino Mocks框架以AAA语法编写这个简单的测试?,c#,.net,unit-testing,rhino-mocks,arrange-act-assert,C#,.net,Unit Testing,Rhino Mocks,Arrange Act Assert,如何使用Rhino Mocks框架以AAA语法编写这个简单的基于记录和回放的测试 public interface IStudentReporter { void PrintStudentReport(List<IStudent> students); List<IStudent> GetUnGraduatedStudents(List<IStudent> students); void AddStudentsToEmpty

如何使用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);
      }
公共接口是用户报告程序
{
无效打印学生报告(列出学生);
列出毕业生(列出学生);
void AddStudentsToEmptyClassRoom(IClassRoom教室,列表
}
[测试]
public void PrintStudentReport\u ClassRoomPassed\u StudentListOfFive()
{
IClassRoom教室=Get教室();//获取一个有5名学生的班级
MockRepository fakeRepositoery=新建MockRepository();
IStudentReporter reporter=FAKEREPORTOERY
.stricmock();
使用(fakeRepositoery.Record())
{
reporter.PrintStudentReport(空);
//我们为第0个索引中的参数设置了约束
约束(List.Count(Is.Equal(5));
}
记者:PrintStudentReport(教室、学生);
虚假报道。核实(记者);
}
好的。我找到了方法:

[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)))
                         );
}
[测试]
public void PrintStudentReport\u ClassRoomPassed\u StudentListOfFive\u with AAA()
{
//安排
IClassRoom教室=Get教室();//获取一个有5名学生的班级
IStudentReporter reporter=MockRepository.GenerateMock();
//表演
记者:PrintStudentReport(教室、学生);
//断言
记者
.AssertWasCalled(r=>r.PrintStudentReport(
Arg
.List.Count(等于(5)))
);
}

我认为你应该在这里使用
generateSub
。如果你想使用
,你只需要
GenerateMock
。期待
。请参阅关于的用户指南(尽管老实说,整个页面也有点混乱…我指的是它所说的部分)“在大多数情况下,您应该更喜欢使用存根。只有在测试复杂交互时,我才建议您使用模拟对象。”)