2012-01-17 44 views
0

我在填充沒有ref關鍵字的數組參數時遇到問題。Rhino Mocks:在沒有「ref」關鍵字的存根中填充數組參數

對於該簽名:

int ReceiveData(ref byte[] data) 

工作的:

byte[] dataParameter = new byte[8]; 
byte[] testData = new byte[] { 1, 2, 3, 4 }; 
this.mockObject.Stub(t => t.ReceiveData(ref dataParameter)).OutRef(testData).Return(4); 

調用 「receiveData的」 後,將 「數據」 參數具有值{1,2,3,4}。 我應該怎麼做,以填補該簽名的數據參數:

int ReceiveData(byte[] data) 

OUTREF()這是行不通的。任何想法? 謝謝...

回答

0

我只是有一個類似的問題,並找到我的解決方案與'回調'方法。在我的情況下,輸入緩衝區參數沒有被聲明爲'ref',所以可能不適合你,但我認爲它應該可以工作。

例如;

mockObject.Expect(x => x.ReceiveData(Arg<byte[]>.Is.NotNull)).Callback((byte[] buffer) => 
{ 
    Array.Copy(outBytes, 0, buffer, 0, outBytes.Length); 
    return true; 
}).Return(10); // return some number of bytes received, and set the bytes in the callback