I have a class that contains a public method, that relies on a internal method in order to properly return its value.
Let's consider the following class and test file:
public class ClassUnderTest
{
public string NotMockedPublicMethod()
{
return MockedMethod();
}
virtual public string MockedMethod()
{
return "original";
}
}
The following test case would work:
var mock = new Mock<ClassUnderTest> { CallBase = true };
mock.Setup(m => m.MockedMethod()).Returns("mocked");
Assert.AreEqual("mocked", mock.Object.NotMockedPublicMethod());
But let's say this MockedMethod()
of mine has no utility externally. The problem is that marking this method as internal
(even using InternalsVisibleTo()
properly):
virtual internal string MockedMethod()
will make the exactly same test fails with the message Assert.AreEqual failed. Expected:<mocked>. Actual:<original>
.
Is this a Moq bug or some limitation?