Skip to content

Check the arguments of the Raise()/RaiseAsync() method arguments. #51

@GillesTourreau

Description

@GillesTourreau

When calling the Raise() or RaiseAsync() method, check the parameters send to the events.

Category : Compilation
Level : Error

For example, the following code is invalid, because the TheEvent expected two arguments (object and string).

[Fact]
public void RaiseTest()
{
    var mock = new Mock<IWithEvent>(MockBehavior.Strict);
    
    mock.Raise(m => m.TheEvent += null, null, 1234);
}

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

The following code is valid:

[Fact]
public void RaiseTest()
{
    var mock = new Mock<IWithEvent>(MockBehavior.Strict);
    
    mock.Raise(m => m.TheEvent += null, null, "1234");
}

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

This rule will prevent the issue devlooped/moq#1568 (and the related PR devlooped/moq#1571).

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions