Пример #1
0
        public static NegotiationResponse FromJson(JSONNode json)
        {
            if (json == null)
            {
                return(null);
            }

            var Result = new NegotiationResponse();

            Result.ConnectionId            = json["ConnectionId"].AsString;
            Result.ConnectionToken         = json["ConnectionToken"].AsString;
            Result.Url                     = json["Url"].AsString;
            Result.ProtocolVersion         = json["ProtocolVersion"].AsString;
            Result.DisconnectTimeout       = json["DisconnectTimeout"].AsDouble.GetValueOrDefault();
            Result.TryWebSockets           = json["TryWebSockets"].AsBool.GetValueOrDefault();
            Result.KeepAliveTimeout        = json["KeepAliveTimeout"].AsDouble;
            Result.TransportConnectTimeout = json["TransportConnectTimeout"].AsDouble.GetValueOrDefault();

            return(Result);
        }
Пример #2
0
        public void WebSocketRemovedFromTransportList()
        {
            var tcs = new TaskCompletionSource<NegotiationResponse>();
            var mre = new ManualResetEventSlim();

            var transports = new List<IClientTransport>();

            var webSocketTransport = new Mock<WebSocketTransport>();
            webSocketTransport.Setup(w => w.Start(It.IsAny<IConnection>(), It.IsAny<string>(), CancellationToken.None))
                .Callback(mre.Set);
            
            transports.Add(webSocketTransport.Object);
            transports.Add(new ServerSentEventsTransport());
            transports.Add(new LongPollingTransport());

            var negotiationResponse = new NegotiationResponse();
            negotiationResponse.TryWebSockets = false;

            tcs.SetResult(negotiationResponse);

            var autoTransport = new Mock<AutoTransport>(It.IsAny<IHttpClient>(), transports);
            autoTransport.Setup(c => c.GetNegotiateResponse(It.IsAny<Connection>(), It.IsAny<string>())).Returns(tcs.Task);
            autoTransport.Object.Negotiate(new Connection("http://foo", string.Empty), string.Empty).Wait();

            Assert.False(mre.IsSet);
        }