使用Rhino模拟时,可以返回一个新的List
MockRepository mock = new MockRepository();
IPersonRepository person = mock.Stub<IPersonRepository>();
using(mock.Record())
{
person.GetPersonByFKId(1);
IList<Person> people= new List<Person>();
people.Add(new Person(100, "Ted", 200));
LastCall.Return(people);
}
Address add = new Address (person);
person.GetPeopleWithAddressField("Ted");//FAIL it will try to ref people
//list and it is always null
上面的语法是否有效?我用Stub和Dynamic Mock试过它,人们总是空的。不确定我做错了什么。
答案 0 :(得分:3)
是的,您可以返回新的列表。但是,使用AAA语法会更容易:
IPersonRepository person = MockRepository.GenerateStub<IPersonRepository>();
IList<Person> people = new List<Person>();
people.Add(new Person(100, "Ted", 200));
person.Stub(p => p.GetPersonByFKId(1)).Return(people);