You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a problem only in master. In release v4.2.1312 it's not met.
You have a concrete class which implements an interface.The interface's members are implemented as NON-VIRTUAL in the concrete class. Then you create a mock of the concrete class. If the mock's object is passed as the concrete class, there is no problem to call the method - its concrete implementation is used. However, if you pass the object as the interface, then the method invocation is mocked and doesn't use the concrete implementation.
However, this behavior is unexpected when the original mock was created on the concrete type, it should work based on its interface not as it's used.
The problem is reproducible with the following code:
public class A : IA
{
public void Foo()
{
Debug.WriteLine("Foo() called.");
}
}
public interface IA
{
void Foo();
}
[TestFixture]
public class TestFixture
{
[Test]
public void Test()
{
Mock<A> mock = new Mock<A>(MockBehavior.Strict);
mock.Object.Foo();
((IA)mock.Object).Foo(); // throws Moq.MockException : IX.Foo() invocation failed with mock behavior Strict.
}
}
The text was updated successfully, but these errors were encountered:
This is a problem only in master. In release v4.2.1312 it's not met.
You have a concrete class which implements an interface.The interface's members are implemented as NON-VIRTUAL in the concrete class. Then you create a mock of the concrete class. If the mock's object is passed as the concrete class, there is no problem to call the method - its concrete implementation is used. However, if you pass the object as the interface, then the method invocation is mocked and doesn't use the concrete implementation.
However, this behavior is unexpected when the original mock was created on the concrete type, it should work based on its interface not as it's used.
The problem is reproducible with the following code:
public class A : IA
{
public void Foo()
{
Debug.WriteLine("Foo() called.");
}
}
The text was updated successfully, but these errors were encountered: