I'd like to know if somehow it is possible to set private readonly
class variable via reflection or something?
Consider the following class:
public class TestSevice
{
private readonly someClassType m_variable;
public TestService()
{
m_variable = //call to some processing function
}
private static int CalculateStuff(int x, int y)
{
//some processing and return
}
}
I'm writing a unit test for private static
method CalculateStuff(int x, int y)
, which I'm able to call via reflection:
PrivateType pt = new PrivateType(typeof(AvatarService));
int actialRes = (int)pt.InvokeStatic("CalculateStuff", parameters);
The problem is that, for my unit test to work, I don't want to set m_variable
or set it to null
on invoking the static
function.
So, is it possible with a constructor is parameterless ctor to not set m_variable
or custom set to to something in the unit test?
Edit:
Some details on //call to some processing function
Here, a call is made to start the receiver of message queue.
The class TestService
is instantiated on the start of worker role, and hence the queue receiver is started in the ctor. The message queue receiver then calls a wrapper function in TestSevice
class, which in turn calls CalculateStuff
. And since I just want to test the core business logic, I don't want to start queue receiver(which imposes certain dependencies).