Skip to content

Expose IMonitor<T> in EventAssertions<T> #2008

@A-Kjeldgaard

Description

@A-Kjeldgaard

If I'm extending the fluent asertions library with some extension methods, it would be nice to be able to iterate through the underlying IMonitor<> of the EventAssertions<> class.

A Pseudo example:

public class Fixture
{
    public void Test()
    {
        //Arrange 
        var parameter = "Hello";
        var sut = new MyService();
        using var monitor = sut.Monitor();
        
        //Act
        sut.DoTheThing();
        
        //Assert
        monitor
        .Should()
        .NotRaiseMyEventWithParameter(parameter);
    }
}


public static class MyExtension
{
    public static IEventRecording NotRaiseMyEventWithParameter<T>(this EventAssertions<T> assertion, string parameter)
    {
        // Monitor not exposed  in the EventAssertions!!!!!
        var recordings = assertion.**Monitor**.GetRecordingFor(nameof(IMyInterface.MyEvent));
        
        //Do the assertion here
    }
}

It is possible to make the extensions method directly on the monitor object, but then the Should() method is not invoked, and semantically it does not fit in with the fluent interface structure.

monitor.ShouldNotRaiseMyEventWithParameter(parameter).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions