Skip to content

Monitor OccurredEvents ordering #1728

@JordanGottardoImagicle

Description

@JordanGottardoImagicle

Description

Monitor OccurredEvents ordering seems to be random and does not reflect the order in which events were raised.

Complete minimal example reproducing the issue

public class MyClass
{
    public event EventHandler FirstEvent;
    public event EventHandler SecondEvent;
    public event EventHandler ThirdEvent;

    public void RaiseFirstEvent()
    {
        FirstEvent?.Invoke(this, EventArgs.Empty);
    }

    public void RaiseSecondEvent()
    {
        SecondEvent?.Invoke(this, EventArgs.Empty);
    }

    public void RaiseThirdEvent()
    {
        ThirdEvent?.Invoke(this, EventArgs.Empty);
    }
}

[Test]
public void Test()
{
    var myObj = new MyClass();

    using (var monitor = myObj.Monitor())
    {
        myObj.RaiseFirstEvent();
        myObj.RaiseSecondEvent();
        myObj.RaiseThirdEvent();

        monitor.OccurredEvents[0].EventName.Should().Be(nameof(myObj.FirstEvent));
        monitor.OccurredEvents[1].EventName.Should().Be(nameof(myObj.SecondEvent));
        monitor.OccurredEvents[2].EventName.Should().Be(nameof(myObj.ThirdEvent));
    }
}

Expected behavior:

OccurredEvents ordering should be the same as the raised events

Actual behavior:

OccurredEvents ordering is random, and changes with every run

Versions

I'm using FluentAssertions 5.6.0.
.NET Framework version 4.8.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions