2012-02-16 50 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