Question: I am using Moq framework to mock objects in my project. I want to save the user profile which is calling UserManager.SetPhoneNUmberAsync of AspNet.Identity.
Here is my code:

```
 public async Task<ActionResult> SaveProfile(DistributorViewModel distributorModel)
    {
        if (ModelState.IsValid)
        {
            string currentUserId = User.Identity.GetUserId();
            distributorModel.UserDetailViewModel.ModifiedDate = System.DateTime.Now;
            distributorModel.UserDetailViewModel.ModifiedBy =Guid.Parse( currentUserId);
            var isUpdated = this.distributorService.Update(distributorModel.UserDetailViewModel);

            IdentityResult result = await UserManager.SetPhoneNumberAsync(currentUserId, distributorModel.UserDetailViewModel.MobileNo);

            if (result.Succeeded && isUpdated)
            {
                Flash.Success(Messages.ProfileUpdatedSuccessfully);
            }
            else
            {
                Flash.Error(Messages.ProfileUpdationError);
            }
        }
        return RedirectToAction("Index", distributorModel);
    }

```

Its throwing error on UserManager.SetPhoneNumberAsync. 
How can I mock this method?

Answer: 
Something similar to this should work:

```
        var manager = new Mock<UserManager<ApplicationUser>();
        manager.Setup(m => m.SetPhoneNumberAsync(userId, "phoneNumber").ReturnsAsync(IdentityResult.Succeeded()).Verifiable();

```
You can also create class **IdentityResultMock** which inherited from **IdentityResult**. Than you can assign **Successed** property from **IdentityResultMock** because **IdentityResult** has protected constructor.

Please refer to my answer [here](https://stackoverflow.com/questions/26269104/how-to-construct-identityresult-with-success-true/38982103#38982103).