I have a class that contains a public method that relies on an internal method to correctly return its value.
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 will 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 that this MockedMethod() mine is not useful from the outside. The problem is that marking this method as internal (even if InternalsVisibleTo() used correctly):
virtual internal string MockedMethod()
will cause the exact same test to complete with the message Assert.AreEqual failed. Expected:<mocked>. Actual:<original> Assert.AreEqual failed. Expected:<mocked>. Actual:<original> Assert.AreEqual failed. Expected:<mocked>. Actual:<original> .
Is this a Moq bug or some limitation?
source share