Пример #1
0
        public void Async_HappyCase()
        {
            bool      asyncSubscription = false;
            Exception ex = null;

            EventBus.Subscribe <Exception>((e) => ex = e);
            Delegate <TestEvent> handler = (TestEvent args) => { Thread.Sleep(1); asyncSubscription = true; };

            EventBus.Subscribe(handler.Async());
            EventBus.Publish(new TestEvent(), this);
            Assert.IsFalse(asyncSubscription);
            waitFor(() => asyncSubscription);
            Assert.IsNull(ex);
        }
Пример #2
0
        public void Async_ExceptionInHandler_ThrowsException()
        {
            bool      asyncSubscription = false;
            Exception ex = null;

            EventBus.Subscribe <Exception>((e) => ex = e);
            Delegate <TestEvent> handler = (TestEvent args) => { throw new InvalidOperationException(); };

            EventBus.Subscribe(
                handler.Async()
                );
            EventBus.Publish <TestEvent>(new TestEvent(), this);
            Assert.IsFalse(asyncSubscription);

            waitFor(() => ex != null);

            Assert.IsFalse(asyncSubscription);
            Assert.AreEqual(ex.GetType(), typeof(InvalidOperationException));
        }
Пример #3
0
 public static Task <object> DynamicInvokeAsync(this Delegate action, params object[] parameters) => action.Async(parameters, (d, p) => d.DynamicInvoke(p));