跳轉至內容

如何使用 Rhino Mocks/Out 和 Ref 引數

25% developed
來自 Wikibooks,開放世界的開放書籍

兩者outref引數都支援。

Expect語句的末尾,新增.OutRef(outOrRefParam0, outOrRefParam1,...)如下所示。

int theRef = 42;
int theOut = 0;
Expect.Call(obj.MyMethod(ref theRef, 0, out theOut)).Return(True).OutRef(13, 666);

或者,如果您使用的是 lambda 風格的期望

 obj.Expect(x => x.MyMethod(ref theRef, 0, out theOut)).Return(True).OutRef(13, 666);

中的變數/物件OutRef()與方法呼叫的順序相同,忽略任何不是outref.

華夏公益教科書