I am trying to write a unit test to verify the subscription to PostAuthenticateRequest event in the HttpApplication class using NSubstitute. Here is what I have:ionvar flag = false;var context = Substitute.For<System.Web.HttpApplication>();context.PostAuthenticateRequest += (sender, args) => flag = true;context.PostAuthenticateRequest += Raise.Event();Assert.IsTrue(flag);The test failed. The Raise.Event() didn't trigger the delegate. I tried Raise.EventWith(this, new EventArgs()) and Raise.EventWith(new object(), new EventArgs()) to no avail.What did I do wrong?
--
You received this message because you are subscribed to the Google Groups "NSubstitute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nsubstitute...@googlegroups.com.
To post to this group, send email to nsubs...@googlegroups.com.
Visit this group at http://groups.google.com/group/nsubstitute?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks for the quick reply. So how can I use NSubstitute to mock the subscription to this event?
var activatedWasCalled = false;
this._vm.Activated += (sender, args) => activatedWasCalled = true;
this._vm.Activated += Raise.EventWith( new ActivationEventArgs() );
this._vm.Activated += Raise.EventWith( new object(), new ActivationEventArgs() );
Assert.IsTrue( activatedWasCalled );
but activatedWasCalled continues to be false.
Any ideas?
Visit this group at http://groups.google.com/group/nsubstitute.