Exemplo n.º 1
0
        public void QueryAsync_WhenExceptionInHandler_ShouldCatchIt()
        {
            var aggregator = InitAggregator();

            aggregator.SubscribeForAsyncResult <TestMessage>(async handler =>
            {
                await Task.Delay(10).ConfigureAwait(false);
                throw new TestException();
            });

            AggregateExceptionHelper.AssertInnerException <TestException>(aggregator.QueryAsync <TestMessage, string>(new TestMessage()));
        }
Exemplo n.º 2
0
        public void QueryAsync_WhenSubscribedForWrongReturnType_ShouldThrowInvalidCastException()
        {
            var aggregator = InitAggregator();

            aggregator.SubscribeForAsyncResult <TestMessage>(async handler =>
            {
                await Task.Delay(10).ConfigureAwait(false);
                return("Test");
            });

            AggregateExceptionHelper.AssertInnerException <InvalidCastException>(aggregator.QueryAsync <TestMessage, List <string> >(new TestMessage()));
        }
Exemplo n.º 3
0
        public void QueryWithResults_WhenCanceled_ShouldThrowOperationCanceledException()
        {
            var aggregator = InitAggregator();
            var expected   = new List <string> {
                "Test", "Test2"
            };

            aggregator.SubscribeForAsyncResult <TestMessage>(async message =>
            {
                message.CancellationToken.ThrowIfCancellationRequested();
                await Task.Delay(100).ConfigureAwait(false);
                return(expected[1]);
            });

            var ts = new CancellationTokenSource();

            ts.Cancel();

            var subscription = aggregator.QueryWithResults <TestMessage, string>(new TestMessage(), cancellationToken: ts.Token);

            AggregateExceptionHelper.AssertInnerException <TaskCanceledException>(subscription);
        }
Exemplo n.º 4
0
        public void QueryWithResults_WhenLongRun_ShouldTimeOut()
        {
            var aggregator = InitAggregator();
            var expected   = new List <string> {
                "Test", "Test2"
            };

            aggregator.SubscribeForAsyncResult <TestMessage>(async handler =>
            {
                await Task.Delay(100).ConfigureAwait(false);
                return(expected[1]);
            });

            aggregator.SubscribeForAsyncResult <TestMessage>(async handler =>
            {
                await Task.Delay(100).ConfigureAwait(false);
                return(expected[0]);
            });

            var subscription = aggregator.QueryWithResults <TestMessage, string>(new TestMessage(), behaviors: new BehaviorChain().WithTimeout(TimeSpan.FromMilliseconds(10)));

            AggregateExceptionHelper.AssertInnerException <TimeoutException>(subscription);
        }