I am trying to write unit tests for a private method with a string[]
as parameter. Invoking a private method works with the PrivateObject
class, however it did not when I tried invoking it with string[]
.
The test returns
System.NullReferenceException: Object reference not set to an instance of an object
on invocation.
This is the class which contains the method I need to invoke:
public class Program{
public Program(){}
private void TestCommand(string[] command){}
}
I tried the following:
Program program = new Program();
PrivateObject privateObject = new PrivateObject(program);
object[] parameters = new object[1] {
new string[2] {
"add",
"rando"
}
};
/* doesn't work either
object[][] parameters = new object[1][];
parameters[0] = new string[2];
parameters[0][0] = "add";
parameters[0][1] = "rando";*/
privateObject.Invoke("TestCommand", parameters);