Add Assert.RaisesAny and Assert.RaisesAnyAsync non-generic for EventArgs #2773
Closed
Description
Discussed in #2772
Originally posted by tencek September 5, 2023
I know there's public static RaisedEvent<T> Raises<T>(...)
in EventAsserts.cs but that only works for the EventHandler<TEventArgs>
, AFAIK.
My event is of plain EventHandler
type and I'd like to verify it was raised.
I ended up implementing it a bit dummy way on my own, here's the code:
public class Testing
{
public static void RaisesEvent(
Action<EventHandler> attach,
Action<EventHandler> detach,
Action testCode)
{
bool isEventRaised = false;
var eventHandler = new EventHandler(delegate
{
isEventRaised = true;
});
attach(eventHandler);
testCode();
detach(eventHandler);
Assert.True(isEventRaised);
}
}
Is there a way to achieve that using a standard xunit tools?
If not, would you consider adding it?