Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking a function which uses out parameters

I have a function which uses out parameters. How can I mock this function?

My function is:

GetProperties(out string name, out string path, out string extension);

In my original code, I am doing this:

string Name;
string Path;
string Extension;
MyObject.GetProperties(out Name, out Path, out Extension);

Now, how I can mock this?

like image 644
fhnaseer Avatar asked Jul 19 '12 07:07

fhnaseer


1 Answers

You should assign out variable's value before calling the method like this:

string Name = "name";
string Path = "path";
string Extension = "extension";
mock.Setup(item => item.GetProperties(out Name, out Path, out Extension))
    .Returns(someReturnValue);

Although I would prefer returning these values in your return type, instead of using so many out parameters.

like image 156
Ufuk Hacıoğulları Avatar answered Oct 14 '22 03:10

Ufuk Hacıoğulları