Exemplo n.º 1
0
        public async Task Should_Be_Able_To_Return_Nack()
        {
            using (var requester = ZyRabbitFactory.CreateTestClient())
                using (var responder = ZyRabbitFactory.CreateTestClient())
                {
                    /* Setup */
                    var firstTsc  = new TaskCompletionSource <BasicRequest>();
                    var secondTsc = new TaskCompletionSource <BasicRequest>();
                    var sent      = new BasicResponse {
                        Prop = "I'm from the second handler"
                    };

                    await responder.RespondAsync <BasicRequest, BasicResponse>(async request =>
                    {
                        firstTsc.TrySetResult(request);
                        return(Respond.Nack <BasicResponse>());
                    }
                                                                               );

                    await responder.RespondAsync <BasicRequest, BasicResponse>(async request =>
                    {
                        secondTsc.TrySetResult(request);
                        return(Respond.Ack(sent));
                    }
                                                                               );

                    /* Test */
                    var received = await requester.RequestAsync <BasicRequest, BasicResponse>(new BasicRequest());

                    await firstTsc.Task;
                    await secondTsc.Task;
                    /* Assert */
                    Assert.Equal(received.Prop, sent.Prop);
                }
        }