2012-02-16 47 views
0

,如果他们在下面的例子返回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

犀牛制品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"); 
+0

它的工作原理!非常感谢你。 – stenio 2012-02-17 08:14:54

+0

无论如何,对于一个在ref/out参数中返回一些东西的方法来说,这是相当多的语法糖。我想知道一个陈述式的方法会不会更好,不是吗? – stenio 2012-02-17 17:25:18

+0

我可能不会改变它,但它不是我的图书馆。 :) – 2012-02-17 17:39:11