在 NBehave 中使用具有多个场景的 Mock

发布于 2024-07-25 17:49:55 字数 505 浏览 7 评论 0原文

我使用 NBehave 来写出我的故事,并使用 Rhino Mocks 来模拟被测系统的依赖关系。

但是,当从一个场景转移到下一个场景时,我在重置模拟依赖项中的预期行为时遇到问题。

我只想断言我的存储库上的 save 方法在两种情况下被调用:

dependancyRepository.AssertWasCalled( ear =>
    ear.Save(
        Arg<IDependancy>.Is.Equal(dependency)
    )
)

但这在每种情况下都被调用,并且在我的第二种情况下失败,因为 Rhino Mocks 期望它只被调用一次。 我不想被迫使用明确的期望,但看起来我也会有。

有一些 NBehave 与 Rhino Mocks 的示例,但我无法提供具有多种场景的示例。 有一些具有 NBehave 和多个场景,但没有模拟。

还有其他人遇到这个问题吗?

干杯

I'm using NBehave to write out my stories and using Rhino Mocks to mock out dependencies of the System(s) Under Test.

However I'm having a problem resetting expected behaviour in my mock dependencies when moving from one scenario to the next.

I only want to assert that the save method on my repository was called in two scenarios:

dependancyRepository.AssertWasCalled( ear =>
    ear.Save(
        Arg<IDependancy>.Is.Equal(dependency)
    )
)

But this is being called in each scenario and fails in my second scenario because the Rhino Mocks expects it be called just once. I don't want to be forced to use an explicit expections but it kinda looks like I'll have too.

There are a few examples out there of NBehave with Rhino Mocks but I can't one that has multiple scenarios. And there are a few with NBehave and multiple Scenarios but no mocks.

Anybody else run into this issue?

Cheers

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

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

发布评论

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

评论(2

阳光①夏 2024-08-01 17:49:56

在相关场景的 then 子句中进行 AssertWasCalled 调用,而不是在任何其他场景中进行调用。

Make the AssertWasCalled call during your Then clause of the relevant scenario, and not in any others.

红衣飘飘貌似仙 2024-08-01 17:49:55

如果您不想断言 .Save(...) 在每个场景中都被调用,则不要为每个场景设置该期望,而仅针对您期望调用它的场景进行设置。

如果这不能回答您的问题,请提供更多信息来澄清您的问题; 目前尚不清楚你想做什么。

If you don't want want to assert that .Save(...) was called in each scenario, then don't set up that expectation for each scenario, set it up only for the scenarios where you expect it to be called.

If this doesn't answer your question, please clarify your question with more information; it's unclear what you're trying to do.

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