Rhino 模拟最后一次调用返回 IList?

发布于 2024-10-25 17:45:29 字数 666 浏览 1 评论 0原文

当使用 Rhino 模拟时,是否可以使其返回一个新列表

        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 尝试过,并且 people 始终为空。不确定我做错了什么。

When using Rhino mocks is it possible to make it return a new 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

Is the Syntax above valid? I have tried it with both Stub and Dynamic Mock and people is always null. Not sure what I am doing wrong.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺ぐ爱和你が 2024-11-01 17:45:30

是的,您可以返回一个新列表。不过,使用 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);

Yes, you can return a new List. It would be easier to use the AAA syntax though:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文