title: Can I set private readonly instance variable?
body: <p>I'd like to know if somehow it is possible to set <code>private readonly</code> class variable via reflection or something?</p>
  
  <p>Consider the following class:</p>
  
  <pre><code>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
      }
  }
  </code></pre>
  
  <p>I'm writing a unit test for <code>private static</code> method <code>CalculateStuff(int x, int y)</code>, which I'm able to call via reflection:</p>
  
  <pre><code>PrivateType pt = new PrivateType(typeof(AvatarService));
  int actialRes = (int)pt.InvokeStatic("CalculateStuff", parameters);
  </code></pre>
  
  <p>The problem is that, for my unit test to work, I don't want to set <code>m_variable</code> or set it to <code>null</code> on invoking the <code>static</code> function.</p>
  
  <p>So, is it possible with a constructor is parameterless ctor to not set <code>m_variable</code> or custom set to to something in the unit test?</p>
  
  <p><strong>Edit:</strong>
  Some details on <code>//call to some processing function</code>
  Here, a call is made to start the receiver of message queue.</p>
  
  <p>The class <code>TestService</code> 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 <code>TestSevice</code> class, which in turn calls <code>CalculateStuff</code>. And since I just want to test the core business logic, I don't want to start queue receiver(which imposes certain dependencies).</p>