public async Task When_time_out_is_triggered_then_should_throw() { TimeSpan timeout = TimeSpan.FromMilliseconds(1000); Func <TimeSpan> getConnectionTimeout = () => timeout; HttpClient httpClient = CreateHttpClient(getConnectionTimeout); var stream = new DelayedReadStream(timeout.Add(TimeSpan.FromMilliseconds(500))); stream.Write(new byte[2048], 0, 2048); stream.Position = 0; await Assert.ThrowsAsync <ObjectDisposedException>(() => httpClient.PostAsync("http://example.com", new StreamContent(stream))); }
public async Task When_time_out_is_not_triggered_then_get_OK() { TimeSpan timeout = TimeSpan.FromMilliseconds(1000); Func <TimeSpan> getConnectionTimeout = () => timeout; HttpClient httpClient = CreateHttpClient(getConnectionTimeout); var stream = new DelayedReadStream(timeout.Add(TimeSpan.FromMilliseconds(-500))); stream.Write(new byte[2048], 0, 2048); stream.Position = 0; HttpResponseMessage response = await httpClient.PostAsync("http://example.com", new StreamContent(stream)); response.StatusCode.ShouldBe(HttpStatusCode.OK); }