Callback()
delegate expression must match the signature of the mocked methodProperty | Value |
---|---|
Rule ID | PosInfoMoq2004 |
Title | Constructor arguments cannot be passed for interface mocks. |
Category | Compilation |
Default severity | Error |
Constructor arguments has been passed to a mocked interface.
It is not possible to pass contructor arguments to mocked interface. Is only possible with non-sealed class or abstract class.
[Fact]
public void Test()
{
var service1 = new Mock<IService>("Argument 1", 2); // No constructor arguments can be passed to mocked interface.
var service2 = new Mock<IService>(MockBehavior.Strict, "Argument 1", 2); // Same if we use the MockBehavior.
}
public interface IService
{
}
To fix a violation of this rule, be sure to pass parameters to mocked abstract class.
Do not suppress an error from this rule. If bypassed, the execution of the unit test will be failed with a MoqException
thrown with the “Constructor arguments cannot be passed for interface mocks.” message.