0

如果它们返回 void,我找不到使用 ref 参数存根方法的方法,如下例所示:

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

你有什么主意吗?

谢谢, 斯泰尼奥

4

1 回答 1

1

Rhino Mocks 3.5 有一个新的约束接口,取代了 .OutRef() 等。请参阅文档

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");
于 2012-02-17T04:08:38.583 回答