public async Task NegotiateReturnsAvailableTransports(TransportType transports)
        {
            var manager    = CreateConnectionManager();
            var dispatcher = new HttpConnectionDispatcher(manager, new LoggerFactory());
            var context    = new DefaultHttpContext();

            context.Features.Set <IHttpResponseFeature>(new ResponseFeature());
            var services = new ServiceCollection();

            services.AddEndPoint <TestEndPoint>();
            services.AddOptions();
            var ms = new MemoryStream();

            context.Request.Path   = "/foo";
            context.Request.Method = "POST";
            context.Response.Body  = ms;
            await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions { Transports = transports });

            var negotiateResponse   = JsonConvert.DeserializeObject <JObject>(Encoding.UTF8.GetString(ms.ToArray()));
            var availableTransports = (TransportType)0;

            foreach (var transport in negotiateResponse["availableTransports"])
            {
                availableTransports |= (TransportType)Enum.Parse(typeof(TransportType), transport.Value <string>());
            }

            Assert.Equal(transports, availableTransports);
        }
        public async Task NegotiateReservesConnectionIdAndReturnsIt()
        {
            var manager    = CreateConnectionManager();
            var dispatcher = new HttpConnectionDispatcher(manager, new LoggerFactory());
            var context    = new DefaultHttpContext();
            var services   = new ServiceCollection();

            services.AddEndPoint <TestEndPoint>();
            services.AddOptions();
            var ms = new MemoryStream();

            context.Request.Path   = "/foo";
            context.Request.Method = "POST";
            context.Response.Body  = ms;
            await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions());

            var negotiateResponse = JsonConvert.DeserializeObject <JObject>(Encoding.UTF8.GetString(ms.ToArray()));
            var connectionId      = negotiateResponse.Value <string>("connectionId");

            Assert.True(manager.TryGetConnection(connectionId, out var connectionContext));
            Assert.Equal(connectionId, connectionContext.ConnectionId);
        }