Example #1
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());
        }
 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);
 }
Example #3
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);
        }
Example #4
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());
        }
Example #5
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;
        }
Example #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());
        }
 public WebSocketTransportLayer(IHttpClient httpClient)
 {
     this.httpClient = httpClient;
     _abortHandler   = new TransportAbortHandler(httpClient, Name);
     ReconnectDelay  = TimeSpan.FromSeconds(5);
 }
 protected HttpBasedTransport(IHttpClient httpClient, string transport)
 {
     _httpClient   = httpClient;
     _transport    = transport;
     _abortHandler = new TransportAbortHandler(httpClient, transport);
 }