hmm... the user was actually calling the first of below overloaded Returns by mistake.
IReturnsResult<TMock> Returns(Func<TResult> valueFunction)
IReturnsResult<TMock> Returns(TResult value)
My test shows Moq actually executes the delegate, not returning the delegate, which won't be type compatible.
public interface IA
{
string MakeString();
}
public static void MoqReturns()
{
var mock = new Mock<IA>();
mock.Setup(x => x.MakeString()).Returns(ReturnSomeString);
Assert.AreEqual("SomeString", mock.Object.MakeString());
}
private static string ReturnSomeString()
{
return "SomeString";
}
Cheers,
Kenneth