I have the following method:
public CustomObect MyMethod()
{
var lUser = GetCurrentUser();
if (lUser.HaveAccess)
{
//One behavior
}
else
{
//Other behavior
}
//return CustomObject
}
I want to mock IMyInterface.GetCurrentUser
, so that while calling MyMethod
I could get to one of the code paths to check it. How to do that with Moq?
I'm doing the following thing:
var moq = new Mock<IMyInterface>();
moq.Setup(x => x.GetCurrentUser()).Returns(lUnauthorizedUser);
//act
var lResult = moq.Object.MyMethod();
But for some reason lResult
is always null
, and when I'm trying to get into MyMethod
in debug, I'm always skipping to the next statement.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…