예제 #1
0
        public void RaisesEventsToAllSubscribersSpecialized()
        {
            // arrange
            Event1 += EventHandlerExtensionsTestsEvent1;
            Event1 += AlwaysThrowException;

            var args = new MyEventArgs {
                ThrowExceptionAfterHitCount = 1
            };
            var errors = new List <Exception>();

            // ReSharper disable once ConvertToLocalFunction
            Action <Exception> handler = exception =>
            {
                lock (this)
                {
                    errors.Add(exception);
                }
            };

            // act
            Event1.AsyncRaiseSafe(this, args, handler).Wait(); //1 pass 1 fail
            Event1.AsyncRaiseSafe(this, args, handler).Wait(); //2 fail
            Event1.AsyncRaiseSafe(this, args, handler).Wait(); //2 fail

            Thread.Sleep(500);

            Assert.Equal(5, errors.Count);
            Assert.Equal(1, args.HitCount);

            args.HitCount = 0;

            // asset
            Event1.AsyncRaiseSafe(this, args, handler).Wait(); //pass

            Assert.Equal(1, args.HitCount);
        }