如果返回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");
}
你有什么想法吗?
谢谢, 施特尼奥
答案 0 :(得分:1)
Rhino Mocks 3.5有一个新的约束接口,取代了.OutRef()等。请参阅documentation:
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");