public async Task ShouldNotThrowIfNotCancelled(
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                Func <Task> func = () => worker.Run(cancellationToken);

                await func.Should().NotThrowAsync <OperationCanceledException>();
            }
            public async Task ShouldThrowIfCancelled(
                [Target] DefaultRequestWorker worker
                )
            {
                var         cancellationToken = new CancellationToken(true);
                Func <Task> func = () => worker.Run(cancellationToken);

                await func.Should().ThrowAsync <OperationCanceledException>();
            }
            public async Task ShouldReceiveMessages(
                [Frozen] IRequestMessageRelay relay,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                await worker.Run(cancellationToken);

                await relay.Received().Receive(Is(cancellationToken));
            }
            public async Task ShouldCreateANewTransaction(
                [Frozen, Substitute] ITransactionFactory transactionFactory,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                await worker.Run(cancellationToken);

                transactionFactory.Received().CreateTransaction();
            }
            public async Task ShouldStartAndStopATraceWithMessageTraceHeader(
                RequestMessage message,
                [Frozen] IRequestMessageRelay relay,
                [Frozen] ITracingService tracing,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                relay.Receive(Any <CancellationToken>()).Returns(new[] { message });
                await worker.Run(cancellationToken);

                Received.InOrder(() =>
                {
                    tracing.Received().StartTrace(Is(message.RequestDetails.TraceHeader));
                    tracing.Received().AddAnnotation(Is("event"), Is("rest-call"));
                    tracing.Received().EndTrace();
                });
            }
            public async Task ShouldInvokeAllReceivedMessagesThenCompleteTransactions(
                RequestMessage message1,
                RequestMessage message2,
                IScope scope1,
                IScope scope2,
                IRequestInvoker invoker1,
                IRequestInvoker invoker2,
                ITransaction transaction1,
                ITransaction transaction2,
                [Frozen] ITransactionFactory transactionFactory,
                [Frozen] IRequestMessageRelay relay,
                [Frozen] IScopeFactory scopeFactory,
                [Target] DefaultRequestWorker worker,
                CancellationToken cancellationToken
                )
            {
                transactionFactory.CreateTransaction().Returns(transaction1, transaction2);
                scope1.GetService <IRequestInvoker>().Returns(invoker1);
                scope2.GetService <IRequestInvoker>().Returns(invoker2);
                scopeFactory.CreateScope().Returns(scope1, scope2);

                relay.Receive(Any <CancellationToken>()).Returns(new[] { message1, message2 });
                await worker.Run(cancellationToken);

                Received.InOrder(async() =>
                {
                    transactionFactory.Received().CreateTransaction();
                    scopeFactory.Received().CreateScope();
                    scope1.Received().GetService <IRequestInvoker>();
                    await invoker1.Received().Invoke(Is(message1), Is(cancellationToken));
                    transaction1.Received().Complete();

                    transactionFactory.Received().CreateTransaction();
                    scopeFactory.Received().CreateScope();
                    scope2.Received().GetService <IRequestInvoker>();
                    await invoker2.Received().Invoke(Is(message2), Is(cancellationToken));
                    transaction2.Received().Complete();
                });
            }