c# - 犀牛模拟中的 AssertWasCalled

标签 c# unit-testing rhino-mocks

我有一个正在测试的对象,它对数据访问对象进行了相当复杂的调用。它看起来像

object.DoSomething(somestring,someObject,someOtherObject,someOtherOtherObject)

在我的测试结构中,我有一个对象的模拟版本,我想测试是否使用 somestring == "value1"和 someObject.porpertyA == "value2"调用了 Dosomething。

我不能使用简单的 AssertWasCalled() 重载,因为我不知道(或关心)someOtherObject。我注意到另一个对设置约束采取操作的重载,但我从未见过它被使用。

最佳答案

小菜一碟:

yourstub.AssertWasCalled(
             x => x.DoSomething(
                Arg<string>.Is.Equal("value1"), 
                Arg<someObjectType>.Is.Equal(value2), 
                Arg<someOtherObjectType>.Is.Anything,   <======== NOTE THIS!
                Arg<someOtherOtherObjectType>.Is.Equal(value3)
             )
);

关于c# - 犀牛模拟中的 AssertWasCalled,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1070186/

相关文章:

django - 需要在 pytest 工厂中覆盖 django auto_now_add

c# - 如何从 C# UNity 中写入的 JSON 格式的文件中删除特殊字符或不需要的符号?

unit-testing - 如何在golang中构建模拟类?

c# - 如何在 GitHub 中处理大文件并仍然允许 AppVeyor 构建

c# - Rhino Mock Partial Stub 必须是公共(public)方法吗?

asp.net-mvc - 如何使用 Rhino Mocks 模拟 HttpContext.Application

C# - 内部成员的命名约定

c# - 如何强制用户不通过 asp.net mvc 2 应用程序中的 url 输入跳过页面?

c# - 引用 Entity Framework 中表的架构名称

c# - Rhino Mocks Stub 返回时的不同实例