FakeItEasy: Support Raise.With for arbitrary delegates without requiring a typeparam in the call.

Update (@blairconrad): title changed after initial discussion among owners. I’ve left the original proposal here, but the goal of the issue has been expanded include support for all non-EventHandler delegates.


Documentation says you have to specify generic type for Raise.With in case you use a custom delegate. And as I understand by “custom delegate” it measn everything besides EventHandler (which is not that popular for handling events besides Windows Forms). Would be nice to add support for Action and Func delegates as most of events are designed using them. Now we have to write something likes this:

realtimeManager.ConnectionStateChanged += Raise.With<Action<ConnectionState>>(ConnectionState.Connected);

instead of

realtimeManager.ConnectionStateChanged += Raise.With(ConnectionState.Connected);

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28 (26 by maintainers)

Most upvoted comments

I have a POC for my dynamic idea. It lets you do this:

void Main()
{
    var foo = A.Fake<IFoo>();
    foo.Bar += (first, last) =>
    {
        Console.WriteLine($"Hello {first} {last}!");
    };
    foo.Bar += Raise.WithD("John", "Doe");
}

public delegate void MyHandler(string firstName, string lastName);
public interface IFoo
{
    event MyHandler Bar;
}

(note that I had to use a different name for With to avoid the ambiguity I mentioned above; obviously we would have to pick a better name)

Assignment to something other than a delegate or event with the correct signature throws an exception.