Created
November 1, 2010 12:29
-
-
Save xerxesb/658086 to your computer and use it in GitHub Desktop.
Raise.Event<AsyncEventArgs>() fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Booyah.ShouldJustWork : FailedSystem.InvalidOperationException : Collection was modified; enumeration operation may not execute. | |
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) | |
at System.Collections.Generic.List`1.Enumerator.MoveNextRare() | |
at System.Collections.Generic.List`1.Enumerator.MoveNext() | |
at NSubstitute.Routing.Handlers.RaiseEventHandler.Handle(ICall call) in d:\Git\NSubstitute\Source\NSubstitute\Routing\Handlers\RaiseEventHandler.cs: line 27 | |
at NSubstitute.Routing.Route.<>c__DisplayClass3.<Handle>b__0(ICallHandler x) in d:\Git\NSubstitute\Source\NSubstitute\Routing\Route.cs: line 18 | |
at System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource x) | |
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() | |
at System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) | |
at NSubstitute.Routing.Route.Handle(ICall call) in d:\Git\NSubstitute\Source\NSubstitute\Routing\Route.cs: line 18 | |
at NSubstitute.Core.CallRouter.Route(ICall call) in d:\Git\NSubstitute\Source\NSubstitute\Core\CallRouter.cs: line 51 | |
at NSubstitute.Proxies.CastleDynamicProxy.CastleForwardingInterceptor.Intercept(IInvocation invocation) in d:\Git\NSubstitute\Source\NSubstitute\Proxies\CastleDynamicProxy\CastleForwardingInterceptor.cs: line 20 | |
at Castle.DynamicProxy.AbstractInvocation.Proceed() in c:\TeamCity\buildAgent\work\f0c43d96621436a8\src\Castle.Core\DynamicProxy\AbstractInvocation.cs: line 163 | |
at Castle.Proxies.IFooProxy.add_ActionComplete(EventHandler`1 value) | |
at Cochlear.SimpleFit.UnitTests.Services.ComfortCheck.Activity.ComfortCheckActivityFixtures.Booyah.ShouldJustWork() in Booyah.cs: line 44 | |
------------- | |
[TestFixture] | |
public class Booyah | |
{ | |
public interface IFoo | |
{ | |
event EventHandler<AsyncCompletedEventArgs> ActionComplete; | |
} | |
public class Bar | |
{ | |
private readonly IFoo _foo; | |
public Bar(IFoo foo) | |
{ | |
_foo = foo; | |
} | |
public void Subscribe() | |
{ | |
_foo.ActionComplete += HandleActionComplete; | |
} | |
private void HandleActionComplete(object sender, AsyncCompletedEventArgs e) | |
{ | |
_foo.ActionComplete -= HandleActionComplete; | |
} | |
} | |
[Test] | |
public void ShouldJustWork() | |
{ | |
var foo = Substitute.For<IFoo>(); | |
var bar = new Bar(foo); | |
bar.Subscribe(); | |
foo.ActionComplete += Raise.Event(new AsyncCompletedEventArgs(null, false, null)); | |
foo.ReceivedWithAnyArgs().ActionComplete -= null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment