title: Call private class method not being initialized in constructor
body: <p>I am writing a unit test and one of the issues that I encounter is null exception on a private class that is not part of DI or not being initialized on constructor parameters. Anyone can help me? Here's my code. My problem is that how to mock PPortalSessionVariables class.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public class EducatorController : BaseController
  {
      //Note: PPortalSessionVariables class should NOT be part of IOC
      private readonly IPPortalSessionVariables _ppsessionVariable = new PPortalSessionVariables();
      private readonly IEducatorService _educatorService;
  
      public EducatorController(IEducatorService educatorService)
      {
          _educatorService = educatorService;
      }
  
      public ActionResult Index()
      {
          //during test null exception occurs on _ppsessionVariable.CurrentChild.Id
          var model = _educatorService.GetEducatorsForChild(Convert.ToInt64(_ppsessionVariable.CurrentChild.Id));
          return View(model);
      }
  }
  </code></pre>
  
  <p><strong>Test Class:</strong></p>
  
  <pre><code>[TestClass]
  public class EducatorControllerTests
  {
      public EducatorController CreateController(Mock&lt;IEducatorService&gt; educatorService = null)
      {
          educatorService = educatorService ?? new Mock&lt;IEducatorService&gt;();
          HttpContext.Current = HttpMockHelpers.FakeHttpContextCurrent();
          var controller = new EducatorController(educatorService.Object);
          controller.SetFakeControllerContext("?site=2");
          return controller;
      }
  
      [TestMethod]
      public void Index_Get_ReturnIndexView()
      {
          var ppsessionVariable = new Mock&lt;IPPortalSessionVariables&gt;();
          var controller = CreateController();
          var child = new ChildModel();
          child.Id = 0;
          ppsessionVariable.Setup(x =&gt; x.CurrentChild).Returns(child);
          var result = controller.Index() as ViewResult;
          Assert.IsNotNull(result);
      }
  }
  </code></pre>