public async Task TransportRouting_FirstTrySucceed_Open()
        {
            var amqpTransportSettings = Substitute.For<ITransportSettings>();
            var mqttTransportSettings = Substitute.For<ITransportSettings>();
            var innerHandler = Substitute.For<IDelegatingHandler>();
            innerHandler.OpenAsync(Arg.Is(false)).Returns(TaskConstants.Completed);
            var sut = new RoutingDelegatingHandler((cs, ts) => innerHandler, null, new [] {amqpTransportSettings, mqttTransportSettings} );

            await sut.OpenAsync(false);
            
            await innerHandler.Received(1).OpenAsync(Arg.Is(false));
        }
        public async Task TransportRouting_TryOpenFailedWithSupportedExceptionTwoTimes_Fail()
        {
            var amqpTransportSettings = Substitute.For<ITransportSettings>();
            var mqttTransportSettings = Substitute.For<ITransportSettings>();
            var innerHandler = Substitute.For<IDelegatingHandler>();
            innerHandler.CloseAsync().Returns(TaskConstants.Completed);
            int openCallCounter = 0;
            innerHandler.OpenAsync(Arg.Is(false)).Returns(async ci =>
            {
                openCallCounter++;
                await Task.Yield();
                throw new TimeoutException();
            });
            var sut = new RoutingDelegatingHandler((cs, ts) => innerHandler, null, new [] {amqpTransportSettings, mqttTransportSettings} );

            await sut.OpenAsync(Arg.Is(false)).ExpectedAsync<IotHubCommunicationException>();

            await innerHandler.Received(2).CloseAsync();

            Assert.AreEqual(2, openCallCounter);
        }
        static async Task TransportRouting_TryOpenFailedWithSupportedExceptionFirstTimes_SuccessOnSecondTry(Func<Exception> exceptionFactory)
        {
            var amqpTransportSettings = Substitute.For<ITransportSettings>();
            var mqttTransportSettings = Substitute.For<ITransportSettings>();
            var innerHandler = Substitute.For<IDelegatingHandler>();
            innerHandler.CloseAsync().Returns(TaskConstants.Completed);
            int openCallCounter = 0;
            innerHandler.OpenAsync(Arg.Is(false)).Returns(async ci =>
            {
                openCallCounter++;
                await Task.Yield();
                if (openCallCounter == 1)
                {
                    throw exceptionFactory();
                }
            });
            var sut = new RoutingDelegatingHandler((cs, ts) => innerHandler, null, new[] { amqpTransportSettings, mqttTransportSettings });

            await sut.OpenAsync(Arg.Is(false));

            await innerHandler.Received(1).CloseAsync();

            Assert.AreEqual(2, openCallCounter);
        }