Example #1
0
 public override void RecieveEvents(Func <IExceptionArgs, Task> exceptionCallback,
                                    Func <IBusEvent, CancellationToken, Task> handlerCallback)
 {
     _handlerCallback   = handlerCallback;
     _exceptionCallback = exceptionCallback;
     _busClient.SubscribeAsync <BusEventBase>(HandleMessage, cfg => cfg
                                              .WithRoutingKey(QueueName));
 }
        public async Task Should_Call_Subscribe_Error_Handler_On_Exception_In_Subscribe_Handler()
        {
            /* Setup */
            var exception   = new Exception("Oh oh, something when wrong!");
            var realHandler = new DefaultStrategy(null, new NamingConventions(), null, null, null);

            _errorHandler
            .Setup(e => e.ExecuteAsync(
                       It.IsAny <Func <Task> >(),
                       It.IsAny <Func <Exception, Task> >()
                       ))
            .Callback((Func <Task> h, Func <Exception, Task> e) => realHandler.ExecuteAsync(h, e));

            _errorHandler
            .Setup(e => e.OnSubscriberExceptionAsync(
                       It.IsAny <IRawConsumer>(),
                       It.IsAny <SubscriptionConfiguration>(),
                       It.IsAny <BasicDeliverEventArgs>(),
                       exception
                       ))
            .Returns(Task.FromResult(true))
            .Verifiable();
            var recieveTcs = new TaskCompletionSource <BasicMessage>();

            _client.SubscribeAsync <BasicMessage>((message, context) =>
            {
                recieveTcs.SetResult(message);
                throw exception;
            }, c => c.WithNoAck());

            /* Test */
            _client.PublishAsync <BasicMessage>();
            await recieveTcs.Task;

            /* Assert */
            _errorHandler.VerifyAll();
        }