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 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); }
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); }
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()); }
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 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()); }
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 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()); }