RhinoMocks的 - 不指定在AssertWasCalled所有参数 [英] RhinoMocks - Not specifying all parameters in AssertWasCalled

查看:147
本文介绍了RhinoMocks的 - 不指定在AssertWasCalled所有参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RhinoMocks的。现在我想断言某些函数被调用,但我只关心的参数之一。我可以做一个 AssertWasCalled 在这里我只给出一个说法?



在下面的例子中,我想忽略什么被送到SomeOtherFunction的第二个参数()。即我要检查SomeOtherFunction被称为与第一个参数123我不关心的第二个参数是什么。

  [测试] 
公共无效SomeTest()
{
VAR myMock = MockRepository。 GenerateMock< ISomeInterface>();
变种MyObj中=新MyClass的(myMock);
myObj.foo()

myMock.AssertWasCalled(出厂=> factory.SomeOtherFunction(123,空));
}


解决方案

您可以指定第二个参数为精氨酸< T> .Is.Anything ,则实际值被忽略



不过注意,用这个。你需要使用精氨酸的所有参数。你需要这意味着在第一个参数是:精氨酸< INT> .Is.Equal(123)


I am using RhinoMocks. Now I want to assert that some function was called, but I only care about one of the arguments. Can I do a AssertWasCalled where I only specify one argument?

In the following example I'd like the ignore what was sent to the second argument of SomeOtherFunction(). I.e. I want to check that SomeOtherFunction was called with first parameter 123 and I don't care what the second parameter was.

[Test]
public void SomeTest()
{
    var myMock = MockRepository.GenerateMock<ISomeInterface>();    
    var myObj = new MyClass(myMock); 
    myObj.foo()

    myMock.AssertWasCalled(factory => factory.SomeOtherFunction(123, null));  
}

解决方案

You can specify the 2nd argument as Arg<T>.Is.Anything, then the actual value gets ignored.

However note that using this you need to use Arg for all arguments. Which means you need to use on the first argument: Arg<int>.Is.Equal(123).

这篇关于RhinoMocks的 - 不指定在AssertWasCalled所有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆