title: Mocking - cannot instantiate proxy class of property?
body: <p>Inside my tests, here is my code:</p>
  
  <pre><code>[SetUp]
  public void Initialise()
  {
      mockOwinManager = new Mock&lt;IOwinManager&lt;ApplicationUser, ApplicationRole&gt;&gt;();
      mockSearch = new Mock&lt;ISearch&lt;ApplicationUser&gt;&gt;();
      mockMail = new Mock&lt;IRpdbMail&gt;();
      mockUserStore = new Mock&lt;IUserStore&lt;ApplicationUser&gt;&gt;();
  
      mockOwinManager.Setup(x =&gt; x.UserManager).Returns(() =&gt; new AppUserManager(mockUserStore.Object));
  
      sut = new UsersController(mockOwinManager.Object, mockSearch.Object, mockMail.Object);
  }
  </code></pre>
  
  <p>And then the test itself:</p>
  
  <pre><code>[Test]
  public void WhenPut_IfUserIsNullReturnInternalServerError()
  {
      //Arrange
      mockOwinManager.Setup(x =&gt; x.UserManager.FindByIdAsync(It.IsAny&lt;string&gt;())).Returns(() =&gt; null);
  
      //Act
      var response = sut.Put(new AppPersonUpdate());
  
      //Assert
      Assert.AreEqual(response.Result.StatusCode, HttpStatusCode.InternalServerError);
  }
  </code></pre>
  
  <p>But my arrange line throws the following error:</p>
  
  <blockquote>
    <p>Can not instantiate proxy of class: Microsoft.AspNet.Identity.UserManager`1[[SWDB.BusinessLayer.Identity.ApplicationUser, SWDB.BusinessLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
        Could not find a parameterless constructor.</p>
  </blockquote>
  
  <p>Why is this so, since in Setup I've set my mockOwinManager's UserManager property in what I'd like it to return already?</p>