简体   繁体   English

AssertWasCalled在犀牛嘲笑中

[英]AssertWasCalled in rhino mocks

I have an object under test that makes a fairly complicated call to a data access object. 我有一个正在测试的对象,它对数据访问对象进行了相当复杂的调用。 IT looks something like 它看起来像

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

In my test structure I have a mocked version of object and I want to test that Dosomething got called with somestring == "value1" and someObject.porpertyA == "value2". 在我的测试结构中,我有一个模拟版本的对象,我想测试Dosomething被调用somestring ==“value1”和someObject.porpertyA ==“value2”。

I can't use the simple AssertWasCalled() overload because I don;t know about (or care about) someOtherObject. 我不能使用简单的AssertWasCalled()重载,因为我不知道(或关心)someOtherObject。 I notice another overload that takes an an action for setup constraints, but I've never seen it used. 我注意到另一个重载需要一个设置约束的动作,但我从未见过它。

Piece of cake: 小菜一碟:

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)
             )
);

Have a look at the documentation for constraints . 查看有关约束文档

I suspect you want: 我怀疑你想要:

Expect.Call(object.DoSomething(null, null, null, null)
      .IgnoreArguments() // Ignore those nulls
      .Constraints(Is.Equal("value1"),
                   Property.Value("PropertyA", "value2"),
                   Is.Anything(),
                   Is.Anything())
      .Return(whateverItShouldReturn);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM