title: Testing usermanager creates a user but password hash property is null
body: <p>I am working with Microsoft.AspNetCore.Identity.UserManager and I'm trying to mock the creation of a new user. In fact, it does create a new user with username, email etc. but the password hash property is still null. </p>
  
  <p>This is how I set up mock usermanager with some additional setup:</p>
  
  <pre><code>        var store = new Mock&lt;IUserPasswordStore&lt;User&gt;&gt;();
  
          var validator = new UserValidator&lt;User&gt;();
          var passValidator = new PasswordValidator&lt;User&gt;();
  
          var mgr = new Mock&lt;UserManager&lt;User&gt;&gt;(store.Object, null, null, null, null, null, null, null, null);
          mgr.Object.UserValidators.Add(validator);
          mgr.Object.PasswordValidators.Add(passValidator);
          mgr.Object.PasswordHasher = new PasswordHasher&lt;User&gt;();
          mgr.Object.Options = AuthenticationRules.DefaultAuthenticationRules();
  
          List&lt;User&gt; users= new List&lt;User&gt;();
  
          mgr.Setup(x =&gt; x.DeleteAsync(It.IsAny&lt;User&gt;())).ReturnsAsync(IdentityResult.Success);
          mgr.Setup(x =&gt; x.CreateAsync(It.IsAny&lt;User&gt;(), It.IsAny&lt;string&gt;())).ReturnsAsync(IdentityResult.Success).Callback&lt;User, string&gt;((x, y) =&gt; users.Add(x));
          mgr.Setup(x =&gt; x.UpdateAsync(It.IsAny&lt;User&gt;())).ReturnsAsync(IdentityResult.Success);
  </code></pre>
  
  <p>The 'DefaultAuthenticationRules' returns this:</p>
  
  <pre><code>    public static IdentityOptions DefaultAuthenticationRules(IdentityOptions identityOptions = null)
      {
          if(identityOptions == null)
              identityOptions = new IdentityOptions();
  
          identityOptions.User.RequireUniqueEmail = true;
          identityOptions.Password.RequireNonAlphanumeric = false;
          identityOptions.Password.RequiredUniqueChars = 0;
  
          return identityOptions;
      }
  </code></pre>
  
  <p>I am then passing the mgr.Object to a method that handles the creation of the new user where 'Object' is _userManager</p>
  
  <pre><code>        var creationResult = await _userManager.CreateAsync(_user, _registrationModel.Password);
  
          if (!creationResult.Succeeded)
              return false;
  
          return true;
  </code></pre>
  
  <p>_registrationModel.Password IS populated. </p>
  
  <p>So now when the setup adding a new user in the callback to the list of users the user is populated without password hash. I am not exactly sure what I'm missing here. I'm missing something in mgr.Setup?</p>
  
  <p>Thanks in advance</p>