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

Raising delegate (non-EventHandler) events #33

Closed
dtchepak opened this issue Oct 19, 2010 · 2 comments
Closed

Raising delegate (non-EventHandler) events #33

dtchepak opened this issue Oct 19, 2010 · 2 comments
Labels
bug Reported problem with NSubstitute behaviour

Comments

@dtchepak
Copy link
Member

Event is declared as delegate (i.e. not an EventHandler). So can't use Raise.Action or Raise.Event.

    [Test]
    public void CanRaiseNotifyPropertyChangedEvent()
    {
        var sub = Substitute.For<INotifyPropertyChanged>();
        sub.PropertyChanged += Raise.Event(); // <---Won't compile
    }

Another example is: _AppDomain.UnhandledException event

@dtchepak
Copy link
Member Author

Can force an overload to be called that returns delegatecallwrapper:

    [Test]
    public void CanRaiseNotifyPropertyChangedEvent()
    {
        var sub = Substitute.For<INotifyPropertyChanged>();
        var wasRaised = false;
        sub.PropertyChanged += (sender, args) => wasRaised = true;
        sub.PropertyChanged += Raise.Event<PropertyChangedEventHandler>(this, new PropertyChangedEventArgs("test"));
        Assert.That(wasRaised);
    }

Probably need a more obvious way to calls these (possibly with arg defaults/detection?). Unfortunately generic constraints can't constrain to delegate types, so may need to introduce Raise.DelegateEvent(...) or similar.

Another option is to make the current arg defaulting more robust, and let the dev cast the delegate to the correct type (adding cast to EventHandlerWrapper).

@dtchepak
Copy link
Member Author

dtchepak commented Nov 1, 2010

Fixed over multiple commits, ending with 0b6739.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reported problem with NSubstitute behaviour
Projects
None yet
Development

No branches or pull requests

1 participant