Как я могу написать этот простой тест в синтаксисе AAA с платформой Rhino Mocks?
Как я могу написать этот простой тест на основе записи и воспроизведения в синтаксисе AAA с платформой Rhino Mocks?
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);
}
1 ответ
Хорошо. Я нашел способ:
[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)))
);
}