C# 如何使用Rhino存根一个返回void且带有ref参数的方法

C# 如何使用Rhino存根一个返回void且带有ref参数的方法,c#,unit-testing,rhino-mocks,stubbing,C#,Unit Testing,Rhino Mocks,Stubbing,如果带有ref参数的存根方法返回void,我无法找到一种方法,如下例所示: public interface Interface1 { void Method1(ref int i); } public class Class1 { static public void Main() { MockRepository mockRepository = new MockRepository(); Interface1 interface1 = mockReposi

如果带有ref参数的存根方法返回void,我无法找到一种方法,如下例所示:

public interface Interface1 {
    void Method1(ref int i);
}

public class Class1 {
    static public void Main() {
    MockRepository mockRepository = new MockRepository();
    Interface1 interface1 = mockRepository.Stub<Interface1>();
    int i = 1;
    //SetupResult.For(interface1.Method1(ref i)).OutRef(1);  Can't compile
    interface1.Method1(ref i);
    LastCall.Repeat.Any();
    mockRepository.ReplayAll();
    int j = 0;
    interface1.Method1(ref j);
    if(j == 1) Console.WriteLine("OK");
}
公共接口1{
无效方法1(参考int i);
}
公共班级1{
静态公共void Main(){
MockRepository MockRepository=新建MockRepository();
Interface1 Interface1=mockRepository.Stub();
int i=1;
//SetupResult.For(interface1.Method1(ref i)).OutRef(1);无法编译
接口1.方法1(参考i);
LastCall.Repeat.Any();
mockRepository.ReplayAll();
int j=0;
接口1.方法1(参考j);
如果(j==1)控制台写入线(“OK”);
}
你知道吗

谢谢,
Stenio

Rhino Mocks 3.5为约束提供了一个新接口,替换了.OutRef()和其他接口。请参阅:

Interface1 Interface1=MockRepository.generateSub();
int i=1;
interface1.Stub(x=>x.Method1(ref Arg.ref(Is.Anything(),i.Dummy));
int j=0;
接口1.方法1(参考j);
如果(j==1)控制台写入线(“OK”);

无论如何,对于在ref/out参数中返回某些内容的方法来说,这是相当多的语法糖分。我想知道声明性方法是否会更好,不是吗?我可能不会更改它,但它不是我的库。:)
Interface1 interface1 = MockRepository.GenerateStub<Interface1>();
int i = 1;
interface1.Stub(x => x.Method1(ref Arg<int>.Ref(Is.Anything(), i).Dummy);
int j = 0;
interface1.Method1(ref j);
if (j == 1) Console.WriteLine("OK");