Answer the question
In order to leave comments, you need to log in
How to pass a private method to a thread in a test?
I have private bool Load(int i){}
to pass it in the test to a thread or task, but how do I do it?
I'm creating methodinfo as a private method. I can pass a method to the task without return and parameters like this
task t = new Task((action)methodinfo.createdelegate(typeof(action)))
Answer the question
In order to leave comments, you need to log in
Type t = typeof(..);
MethodInfo mi = t.GetMethod("***", BindingFlags.Instance | BindingFlags.NonPublic);
ParametrizedThreadStart parametrizedThreadStart = mew ParametrizedThreadStart ((object o)=>{
mi.Invoke((..)o, new object[] {0});
});
Thread t = new Thread(parametrizedThreadStart);
string str;
using (StringWriter wr = new StringWriter())
{
TextWriter s= Console.Out;
Console. SetOut(wr);
t.Start(..);
t.Join();
str = wr.ToString();
Console.Setout(s);
}
Assert.AreEquals(regex.ismatch(str, @****), true);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question