public WebSocketTransport(IHttpClient client)
     : base(maxIncomingMessageSize: null) // Disable max incoming message size on the client
 {
     _client = client;
     _disconnectToken = CancellationToken.None;
     _abortHandler = new TransportAbortHandler(client, Name);
     ReconnectDelay = TimeSpan.FromSeconds(2);
 }
Exemplo n.º 2
0
        public void AbortValidatesArguments()
        {
            var httpClient = Mock.Of<IHttpClient>();
            var abortHandler = new TransportAbortHandler(httpClient, "fakeTransport");

            var transport =
                new Mock<ClientTransportBase>(httpClient, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            Assert.Equal("connection",
                Assert.Throws<ArgumentNullException>(() => transport.Abort(null, new TimeSpan(0, 0, 5), "connectionData")).ParamName);
        }
Exemplo n.º 3
0
        internal ClientTransportBase(IHttpClient httpClient, string transportName, TransportHelper transportHelper, TransportAbortHandler abortHandler)
        {
            if (httpClient == null)
            {
                throw new ArgumentNullException("httpClient");
            }

            if (string.IsNullOrWhiteSpace(transportName))
            {
                throw new ArgumentNullException("transportName");
            }

            Debug.Assert(transportHelper != null, "transportHelper is null");
            Debug.Assert(abortHandler != null, "abortHandler is null");

            _httpClient = httpClient;
            _transportName = transportName;
            _transportHelper = transportHelper;
            _abortHandler = abortHandler;
        }
Exemplo n.º 4
0
 protected HttpBasedTransport(IHttpClient httpClient, string transport)
 {
     _httpClient = httpClient;
     _transport = transport;
     _abortHandler = new TransportAbortHandler(httpClient, transport);
 }
Exemplo n.º 5
0
        public void AbortRequestNotSentIfConnectionTokenNull()
        {
            var mockClient = new Mock<IHttpClient>();
            var abortHandler = new TransportAbortHandler(mockClient.Object, "fakeTransport");
            var transport =
                new Mock<ClientTransportBase>(mockClient.Object, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            transport.Abort(Mock.Of<IConnection>(), new TimeSpan(0, 0, 5), "connectionData");

            mockClient.Verify(
                m => m.Post(It.IsAny<string>(), It.IsAny<Action<IRequest>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<bool>()),
                Times.Never());
        }
Exemplo n.º 6
0
        public void FailuresWhileSendingAbortRequestsAreLoggedAndSwallowed()
        {
            const string exceptionMessage = "Abort request failed";

            var tcs = new TaskCompletionSource<IResponse>();
            tcs.SetException(new InvalidOperationException(exceptionMessage));

            var traceStringBuilder = new StringBuilder();
            var connection = new Connection("http://fake.url/")
            {
                ConnectionToken = "connectionToken",
                TraceWriter = new StringWriter(traceStringBuilder)
            };

            var mockClient = new Mock<IHttpClient>();
            mockClient
                .Setup(m => m.Post(It.IsAny<string>(), It.IsAny<Action<IRequest>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<bool>()))
                .Returns(tcs.Task);

            var abortHandler = new TransportAbortHandler(mockClient.Object, "fakeTransport");

            var transport =
                new Mock<ClientTransportBase>(mockClient.Object, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            transport.Abort(connection, new TimeSpan(0, 0, 5), "connectionData");

            mockClient.Verify(
                m => m.Post(It.Is<string>(url => url.StartsWith("http://fake.url/abort?")), It.IsAny<Action<IRequest>>(),
                        It.IsAny<IDictionary<string, string>>(), false),
                Times.Once());

            Assert.Contains(exceptionMessage, traceStringBuilder.ToString());
        }
Exemplo n.º 7
0
        public void AbortSendsAbortRequestOnlyOnce()
        {
            var connection = new Connection("http://fake.url/") { ConnectionToken = "connectionToken" };

            var mockClient = new Mock<IHttpClient>();

            var abortHandler = new TransportAbortHandler(mockClient.Object, "fakeTransport");

            mockClient
                .Setup(m => m.Post(It.IsAny<string>(), It.IsAny<Action<IRequest>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<bool>()))
                .Returns(() =>
                {
                    abortHandler.CompleteAbort();
                    return Task.FromResult((IResponse)null);
                });

            var transport =
                new Mock<ClientTransportBase>(mockClient.Object, "fakeTransport", Mock.Of<TransportHelper>(), abortHandler)
                {
                    CallBase = true
                }.Object;

            transport.Abort(connection, new TimeSpan(0, 0, 5), "connectionData");

            transport.Abort(connection, new TimeSpan(0, 0, 5), "connectionData");

            mockClient.Verify(
                m => m.Post(It.Is<string>(url => url.StartsWith("http://fake.url/abort?")), It.IsAny<Action<IRequest>>(),
                        It.IsAny<IDictionary<string, string>>(), false),
                Times.Once());
        }