Rhino Mocks - 流畅的模拟 - Expect.Call 问题

发布于 2024-09-01 18:45:49 字数 793 浏览 4 评论 0原文

我正在尝试使用 Rhino.Mocks 的流畅模拟风格,并使用以下代码来处理名为“factories”的模拟 IDictionary 对象:

With.Mocks(_Repository).Expecting(() =>
        {
            Expect.Call(() => factories.ContainsKey(Arg<String>.Is.Anything));
            LastCall.Return(false);

            Expect.Call(() => factories.Add(Arg<String>.Is.Anything, Arg<Object>.Is.Anything));
        }).Verify(() =>
        {
            _Service = new ObjectRequestService(factories);
            _Service.RegisterObjectFactory(Valid_Factory_Key, factory);
        });

现在,我能够设置 ContainsKey 调用的返回值的唯一方法是在下面的行中使用 LastCall.Return(true) 。

我确信我在这里混合了样式,因为 Expect.Call() 有一个 .Return(Expect.Action) 方法,但我不知道如何正确使用它来返回布尔值?

有人可以帮忙吗?希望问题足够清楚 - 如果有人需要更多信息,请告诉我!

干杯, 本

I'm trying to use the fluent mocking style of Rhino.Mocks and have the following code that works on a mock IDictionary object called 'factories':

With.Mocks(_Repository).Expecting(() =>
        {
            Expect.Call(() => factories.ContainsKey(Arg<String>.Is.Anything));
            LastCall.Return(false);

            Expect.Call(() => factories.Add(Arg<String>.Is.Anything, Arg<Object>.Is.Anything));
        }).Verify(() =>
        {
            _Service = new ObjectRequestService(factories);
            _Service.RegisterObjectFactory(Valid_Factory_Key, factory);
        });

Now, the only way I have been able to set the return value of the ContainsKey call is to use LastCall.Return(true) on the following line.

I'm sure I'm mixing styles here as Expect.Call() has a .Return(Expect.Action) method but I can't figure out how I am suppose to use it correctly to return a boolean value?

Can anyone help out? Hope the question is clear enough - let me know if anyone needs more info!

Cheers,
Ben

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

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

发布评论

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

评论(1

且行且努力 2024-09-08 18:45:49

我相信下面这行会给你想要的:

Expect.Call(factories.ContainsKey(Arg<string>.Is.Anything)).Return(false);

I believe the following line will give you want you want:

Expect.Call(factories.ContainsKey(Arg<string>.Is.Anything)).Return(false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文