2009-07-01 102 views
7

我有一个对象正在测试,使一个相当复杂的数据访问对象的调用。它看起来就像AssertWasCalled在犀牛模拟

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

在我的测试结构,我有对象的嘲笑版本,我想测试得到的DoSomething调用somestring ==“值1”和someObject.porpertyA ==“值2”。

我不能使用简单的AssertWasCalled()重载,因为我不知道(或关心)someOtherObject。我注意到另一个重载需要一个设置约束的动作,但我从来没有见过使用它。

回答

18

海贼王:

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

看过那部作品greaat。我发现唯一有用的其他东西是使用Arg .Matches(y => y.property ==什么);用于检查参数对象上的值。 – captncraig 2009-07-01 19:40:11

4

看看documentation for constraints

我怀疑你想:蛋糕

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