private HttpConnection CreateConnection(out Task closedTask, Func <Task> stopHandler = null)
            {
                var httpHandler      = new TestHttpMessageHandler();
                var transportFactory = new TestTransportFactory(new TestTransport(stopHandler));
                var connection       = new HttpConnection(
                    new Uri("http://fakeuri.org/"),
                    transportFactory,
                    NullLoggerFactory.Instance,
                    new HttpOptions()
                {
                    HttpMessageHandler = httpHandler,
                });

                var closedTcs = new TaskCompletionSource <object>();

                connection.Closed += ex =>
                {
                    if (ex != null)
                    {
                        closedTcs.SetException(ex);
                    }
                    else
                    {
                        closedTcs.SetResult(null);
                    }
                };
                closedTask = closedTcs.Task;

                return(connection);
            }
Beispiel #2
0
        private static HttpConnection CreateConnection(
            HttpConnectionOptions httpConnectionOptions,
            ILoggerFactory loggerFactory       = null,
            ITransport transport               = null,
            ITransportFactory transportFactory = null,
            TransferFormat transferFormat      = TransferFormat.Text)
        {
            loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
            httpConnectionOptions.Url ??= new Uri("http://fakeuri.org/");
            httpConnectionOptions.DefaultTransferFormat = transferFormat;

            if (transportFactory == null && transport != null)
            {
                transportFactory = new TestTransportFactory(transport);
            }

            if (transportFactory != null)
            {
                return(new HttpConnection(httpConnectionOptions, loggerFactory, transportFactory));
            }
            else
            {
                // Use the public constructor to get the default transport factory.
                return(new HttpConnection(httpConnectionOptions, loggerFactory));
            }
        }