Hi, I need help with a testmethod im trying to write...
I need to test that a user can show his profile, however i encounter an error when i try to use my mocked GetProfileFromUserName method. The methods returns null. What I Dont understand is that i have a similar method named GetEmail, which basically does the same and works.
This is the code for retrieving the profile, which doesnt work:
mockUserRepository.Setup(gp => gp.GetProfileFromUserName(userProfile.UserName)).Returns(new Profile { ProfileID = userProfile.ProfileID });
And this is the code for retrieving the email, which works.
mockUserRepository.Setup(em => em.GetEmail(new MockIdentity("JohnDoe").Name)).Returns("[email protected]");
And this is a snippet of the method the mock calls and returns null on instead of a profile:
public ActionResult ShowProfile()
{
var profile = _userRepository.GetProfileFromUserName(User.Identity.Name);
What am i doing wrong? If i replace the userProfile.UserName in the GetProfileFromUserName to It.IsAny();