Skip to content

Check the optional arguments in the Callback() method. #58

Description

@GillesTourreau

It is possible to add default value in the interface with C#.
For the Setup() method, it is OK, but for the Callback() we must explicitly check that the optional argument exists.

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        var mock = new Mock<ISampleInterface>();
        mock.Setup(m => m.TestMethodWithOptionalParam(It.IsAny<int>()))
                 .Callback((int a) => { });           // This compile, but Moq raise an ArgumentException, because the call back method does not contains the 'optionalParam' argument.
    }

    public interface ISampleInterface
    {
        void TestMethodWithOptionalParam(int requiredParam, int optionalParam = 42);
    }
}

Fix this behavior in the PosInfoMoq2003 rule.

This is linked to the #57 issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions