Unit test for a CreateUser() method using JustMock lite
I think you are not testing everything. The API should create a user but the only thing you assert is the ActionResult


Assert.AreEqual(actionResult.RouteValues["Action"], "Index");



So the method runs and the result is correct. But has it actually created a new user and add it to the repository? How about this operation?


var opStatus = _UserRepository.AddUser(newUser);



IMO you should also check the repository to see whether the API correctly added the new user to it. I don't know what interfaces the UserRepository might implement but for this

var UserRepository = Mock.Create&lt;IUserRepository&gt;();


assertions like these ones could be appropriate (just examples) or anything else that makes sense for the repository.

Assert.AreEqual(1, UserRepository.Count);
Assert.AreEqual(referenceUser, UserRepository.GetUser(abc));


What if someone had a problem with the repository and commented it out and actually forgot to add #if DEBUG or made any other changes ignoring the status-code?

public ActionResult Create(UserViewModel item)
{
    if (ModelState.IsValid)
    {
        var newUser = Mapper.Map&lt;UserViewModel, User&gt;(item);
        //Populates file name and content type to newUser
        UserHelper.PopulateFile(item.File, newUser);

        newUser.UserId = (int)_membershipService.GetUser().ProviderUserKey;

        // I temporarily disabled the repository because I didn't work for me.
        //var opStatus = _UserRepository.AddUser(newUser);
        //if (!opStatus.Status)
        //    throw new System.Web.Http.HttpResponseException(new   HttpResponseMessage(HttpStatusCode.InternalServerError));

        return RedirectToAction("Index");
    }
    else
        return View(item);
}


The test would still pass but the result would be wrong.