Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
A-Kjeldgaard opened this issue Oct 4, 2022 · 0 comments · Fixed by #2010
Closed

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

A-Kjeldgaard opened this issue Oct 4, 2022 · 0 comments · Fixed by #2010

Comments

@A-Kjeldgaard
Copy link
Contributor

A-Kjeldgaard commented Oct 4, 2022

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants