Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide a user defined delegate with out parameters in Microsoft Moles

I wanted to bypass an internal method call and hence have mocked it. The mocked method delegate looks like:

public Microsoft.Moles.Framework.MolesDelegates.OutOutFunc<string,string,string,
byte[]> GetlineStringStringOutStringOut { set; }

Now, in my test when I try to access this mocked method like:

GetlineStringStringOutStringOut = (a,b,c) => {return bytearray};

an error occurs saying parameter 2 and 3 must be declared with out keyword but when I declare them with out keyword it's doesn't compile at all. I read other SO questions and answers and it seems it can't be done.

Is it possible to provide user defined delegate for this? If yes, please give an example.

EDIT:

I tried to declare my own delegate of same signature as mocked delegate

static delegate byte[] MyFunc<String, String, String>
(string a, out string b, out string c);

but I'm not sure how can I call this while calling the mocked delegate method?

like image 767
Rahul Avatar asked Dec 12 '11 10:12

Rahul


1 Answers

You need to assign values to b and c variables before returning from your lambda and also specify the parameters types explicitly, something like this:

GetlineStringStringOutStringOut = (string a, out string b, out string c) => 
{ 
    b = c = string.Empty;

    return new byte[] { };
};
like image 159
João Angelo Avatar answered Oct 03 '22 12:10

João Angelo