Skip to content

Check the Callback() method signature for the SetupAdd() and SetupRemove() methods. #50

@GillesTourreau

Description

@GillesTourreau

Category : Compilation
Level : Error

Check the Callback() method signatures for the SetupAdd() and SetupRemove() methods.

For example the following code is invalid:

[Fact]
public void RaiseTest()
{
    var mock = new Mock<IWithEvent>(MockBehavior.Strict);
    mock.SetupAdd(m => m.TheEvent += It.IsAny<EventHandler<string>>())
        .Callback((string handler) =>
        {

        });
}

public interface IWithEvent
{
    event EventHandler<string> TheEvent;
}

The following code should work:

[Fact]
public void RaiseTest()
{
    var mock = new Mock<IWithEvent>(MockBehavior.Strict);
    mock.SetupAdd(m => m.TheEvent += It.IsAny<EventHandler<string>>())
        .Callback((EventHandler<string> handler) =>
        {

        });
}

public interface IWithEvent
{
    event EventHandler<string> TheEvent;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrule:compilationThis issue is related to a compilation rule.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions