title: object reference not set to an instance when functions call in unit test(intellitest)
body: <p>i have problem when i call any function within my unit test controller class,
  when i run the test, its give error</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>i am not sure what i am missing here or i do not know i do call function in unit test, i am using intellitest using visual studio 2015 enterprise edition</p>
  
  <p>here my code</p>
  
  <ol>
  <li><p>/// This class contains parameterized unit tests for AccountFinFilesController</p>
  
  <pre><code>[TestClass]
  [PexClass(typeof(AccountFinFilesController))]
  [PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
  [PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
  public partial class AccountFinFilesControllerTest
  {
  
      /// &lt;summary&gt;Test stub for .ctor(ISmallBizRepository)&lt;/summary&gt;
      [PexMethod]
      public AccountFinFilesController ConstructorTest(ISmallBizRepository repo)
      {
          AccountFinFilesController target = new AccountFinFilesController(repo);
          return target;
          // TODO: add assertions to method AccountFinFilesControllerTest.ConstructorTest(ISmallBizRepository)
      }
  
      /// &lt;summary&gt;Test stub for Delete(Guid, Guid)&lt;/summary&gt;
      [PexMethod]
      public HttpResponseMessage DeleteTest(
          [PexAssumeUnderTest]AccountFinFilesController target,
          Guid id,
          Guid deletedby
      )
      {
          HttpResponseMessage result = target.Delete(id, deletedby);
          return result;
          // TODO: add assertions to method AccountFinFilesControllerTest.DeleteTest(AccountFinFilesController, Guid, Guid)
      }
  
      /// &lt;summary&gt;Test stub for GetAccountFinFilesTable(Guid, Guid)&lt;/summary&gt;
      [PexMethod]
      public IQueryable GetAccountFinFilesTableTest(
          [PexAssumeUnderTest]AccountFinFilesController target,
          Guid firmid,
          Guid id
      )
      {
          IQueryable result = target.GetAccountFinFilesTable(firmid, id);
          Assert.IsNotNull(result);
          return result;
          // TODO: add assertions to method AccountFinFilesControllerTest.GetAccountFinFilesTableTest(AccountFinFilesController, Guid, Guid)
      }
  
      /// &lt;summary&gt;Test stub for GetAccountFinFilesTable(Guid)&lt;/summary&gt;
      [PexMethod]
      public IQueryable GetAccountFinFilesTableTest01([PexAssumeUnderTest]AccountFinFilesController target, Guid firmid)
      {
  
          IQueryable result = target.GetAccountFinFilesTable(Guid.Parse("75165ae3-cbae-e511-b0bf-00259076695a"));
          Assert.IsNotNull(result);
          return result;
          // TODO: add assertions to method AccountFinFilesControllerTest.GetAccountFinFilesTableTest01(AccountFinFilesController, Guid)
      }
  
      /// &lt;summary&gt;Test stub for Post(AccountFinFilesTable, Guid, Guid)&lt;/summary&gt;
      [PexMethod]
      public HttpResponseMessage PostTest(
          [PexAssumeUnderTest]AccountFinFilesController target,
          AccountFinFilesTable obj,
          Guid firmid,
          Guid createdby
      )
      {
          HttpResponseMessage result = target.Post(obj, firmid, createdby);
          return result;
          // TODO: add assertions to method AccountFinFilesControllerTest.PostTest(AccountFinFilesController, AccountFinFilesTable, Guid, Guid)
      }
  
      /// &lt;summary&gt;Test stub for Put(AccountFinFilesTable)&lt;/summary&gt;
      [PexMethod]
      public HttpResponseMessage PutTest([PexAssumeUnderTest]AccountFinFilesController target, AccountFinFilesTable obj)
      {
          HttpResponseMessage result = target.Put(obj);
          return result;
          // TODO: add assertions to method AccountFinFilesControllerTest.PutTest(AccountFinFilesController, AccountFinFilesTable)
      }
  }
  </code></pre></li>
  <li><p>WebAPI controller class</p>
  
  <pre><code>  public class AccountFinFilesController : BaseApiController
    {
      private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
      public AccountFinFilesController(ISmallBizRepository repo)
          : base(repo)
      {
      }
  
      // GET api/AccountFinFiles
      /// &lt;summary&gt;
      /// GetAccountFinFilesTable
      /// &lt;/summary&gt;
      /// &lt;param name="firmid"&gt;&lt;/param&gt;
      /// &lt;param name="id"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      [HttpGet]
      public IQueryable GetAccountFinFilesTable(Guid firmid, Guid id)
      {
          log.Info("GetAccountFinFilesTable API -- firmid=" + firmid + "&amp;id=" + id);
          return TheRepository.GetAccountFinFile(firmid, id);
      }
  
      /// &lt;summary&gt;
      /// GetAccountFinFilesTable
      /// &lt;/summary&gt;
      /// &lt;param name="firmid"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      [HttpGet]
      public IQueryable GetAccountFinFilesTable(Guid firmid)
      {
              log.Info("GetAccountFinFilesTable API -- firmid=" + firmid);
              return TheRepository.GetAccountFinFile(firmid);
      }
  
      /// &lt;summary&gt;
      /// update AccountFinFilesTable
      /// &lt;/summary&gt;
      /// &lt;param name="account_finfilestabledm"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      [HttpPut]
      public HttpResponseMessage Put(AccountFinFilesTable obj)
      {
          try
          {
              var updatedEntity = TheModelFactory.Parse(obj);
  
              if (updatedEntity == null)
              {
                  log.Error(MessagesHelper.recordnotfound + "File_ID: " + obj.File_ID);
                  Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read AccountFinFilesTable from body");
              }
  
              var originalEntity = TheRepository.GetAccountFinFileByPrimaryKey(obj.File_ID);
  
              if (originalEntity == null || originalEntity.File_ID != obj.File_ID)
              {
                  log.Error(MessagesHelper.recordnotfound + "File_ID: " + obj.File_ID);
                  return Request.CreateResponse(HttpStatusCode.NotModified, "AccountFinFilesTable record not found");
              }
              else
              {
                  updatedEntity.File_ID = obj.File_ID;
              }
  
              if (TheRepository.Update(originalEntity, updatedEntity) &amp;&amp; TheRepository.SaveAll())
              {
                  log.Info(MessagesHelper.updatesuccess + "File_ID: " + obj.File_ID);
                  return Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(updatedEntity));
              }
              else
              {
                  log.Error(MessagesHelper.updateerror + "File_ID: " + obj.File_ID);
                  return Request.CreateResponse(HttpStatusCode.NotModified, "Could not update to the database.");
              }
  
          }
          catch (Exception ex)
          {
              log.Error(ex.Message + " " + obj.File_ID);
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
          }
  
      }
  
      /// &lt;summary&gt;
      /// add new record to AccountFinFilesTable
      /// &lt;/summary&gt;
      /// &lt;param name="account_finfilestabledm"&gt;&lt;/param&gt;
      /// &lt;param name="firmid"&gt;&lt;/param&gt;
      /// &lt;param name="createdby"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      [HttpPost]
      public HttpResponseMessage Post(AccountFinFilesTable obj, Guid firmid, Guid createdby)
      {
          try
          {
              obj.FirmId = firmid;
              obj.ClientId = createdby;
              obj.CreatedDate = DateTime.UtcNow;
  
              var entity = TheModelFactory.Parse(obj);
  
              if (entity == null)
              {
                  log.Error(MessagesHelper.recordnotfound + " " + firmid + " " + createdby);
                  return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read AccountFinFilesTable from body");
              }
              else
              {
                  if (TheRepository.Insert(entity) &amp;&amp; TheRepository.SaveAll())
                  {
                      log.Info(MessagesHelper.savesuccess + " " + firmid + " " + createdby);
                      return Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity));
                  }
                  else
                  {
                      log.Error(MessagesHelper.saverror + " " + firmid + " " + createdby);
                      return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database.");
                  }
              }
  
          }
          catch (Exception ex)
          {
              log.Error(ex.Message + " " + firmid + " " + createdby);
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
          }
      }
  
      /// &lt;summary&gt;
      /// delete record from AccountFinFilesTable
      /// &lt;/summary&gt;
      /// &lt;param name="account_finfilestabledm"&gt;&lt;/param&gt;
      /// &lt;param name="deletedby"&gt;&lt;/param&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      [HttpDelete]
      public HttpResponseMessage Delete(Guid id, Guid deletedby)
      {
          try
          {
              var entity = TheRepository.GetAccountFinFileByPrimaryKey(id);
  
              if (entity == null)
              {
                  log.Error(MessagesHelper.recordnotfound + "File_ID: " + id);
                  return Request.CreateResponse(HttpStatusCode.NotFound);
              }
  
              if (TheRepository.DeleteAccountFinFile(id, deletedby) &amp;&amp; TheRepository.SaveAll())
              {
                  log.Info(MessagesHelper.deletesuccess + "File_ID: " + entity.File_ID);
                  return Request.CreateResponse(HttpStatusCode.OK);
              }
              else
              {
                  log.Error(MessagesHelper.deleteerror + "File_ID: " + entity.File_ID);
                  return Request.CreateResponse(HttpStatusCode.BadRequest, "Could not delete the record.");
              }
  
          }
          catch (Exception ex)
          {
              log.Error(ex.Message + "File_ID: " + id);
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
          }
  
      }
  
  }
  </code></pre></li>
  <li><p>error</p></li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/NvGBt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NvGBt.png" alt="object reference not set to an instance of an object"></a></p>
  
  <p>please help/guide or provide me a complete solution according to my scenario, i will provide more detail if required. thanks for your valuable time and effort.</p>