public void Given_Validation_Error_With_CancellationToken_When_PutAsync_Invoked_Then_It_Should_Throw_Exception(HttpStatusCode statusCode) { var requestUri = "http://localhost"; var payload = "{ \"hello\": \"world\" }"; var exception = new SchemaValidationException(); var validator = new Mock <ISchemaValidator>(); validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ThrowsAsync(exception); var path = "default.json"; var func = default(Func <Task>); using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode, payload)) using (var httpClient = this._fixture.CreateHttpClient(handler)) using (var content = this._fixture.CreateHttpContent()) using (var source = this._fixture.CreateCancellationTokenSource()) { func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, content, validator.Object, path, source.Token).ConfigureAwait(false); func.Should().Throw <SchemaValidationException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, new Uri(requestUri), content, validator.Object, path, source.Token).ConfigureAwait(false); func.Should().Throw <SchemaValidationException>(); } }
public void Given_Null_Parameters_When_PutAsync_Invoked_Then_It_Should_Throw_Exception() { var requestUri = "http://localhost"; var validator = new Mock <ISchemaValidator>(); var func = default(Func <Task>); using (var httpClient = this._fixture.CreateHttpClient()) using (var content = this._fixture.CreateHttpContent()) { func = async() => await HttpClientExtensions.PutAsync(null, (string)null, null, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, (string)null, null, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, null, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, content, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, content, validator.Object, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(null, (Uri)null, null, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, (Uri)null, null, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, null, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, content, null, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, content, validator.Object, null).ConfigureAwait(false); func.Should().Throw <ArgumentNullException>(); } }
public void Given_Error_Response_When_PutAsync_Invoked_Then_It_Should_Throw_Exception(HttpStatusCode statusCode) { var requestUri = "http://localhost"; var validator = new Mock <ISchemaValidator>(); var path = "default.json"; var func = default(Func <Task>); using (var handler = this._fixture.CreateFakeHttpMessageHandler(statusCode)) using (var httpClient = this._fixture.CreateHttpClient(handler)) using (var content = this._fixture.CreateHttpContent()) { func = async() => await HttpClientExtensions.PutAsync(httpClient, requestUri, content, validator.Object, path).ConfigureAwait(false); func.Should().Throw <HttpRequestException>(); func = async() => await HttpClientExtensions.PutAsync(httpClient, new Uri(requestUri), content, validator.Object, path).ConfigureAwait(false); func.Should().Throw <HttpRequestException>(); } }
public async Task Given_Validation_Result_When_PutAsync_Invoked_Then_It_Should_Return_Result(HttpStatusCode statusCode) { var requestUri = "http://localhost"; var payload = "{ \"hello\": \"world\" }"; var validator = new Mock <ISchemaValidator>(); validator.Setup(p => p.ValidateAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); var path = "default.json"; using (var response = this._fixture.CreateHttpResponseMessage(statusCode, payload)) using (var handler = this._fixture.CreateFakeHttpMessageHandler(response)) using (var httpClient = this._fixture.CreateHttpClient(handler)) using (var content = this._fixture.CreateHttpContent()) using (var result1 = await HttpClientExtensions.PutAsync(httpClient, requestUri, content, validator.Object, path).ConfigureAwait(false)) using (var result2 = await HttpClientExtensions.PutAsync(httpClient, new Uri(requestUri), content, validator.Object, path).ConfigureAwait(false)) { result1.Should().Be(response); result2.Should().Be(response); } }
public Task <HttpResponseMessage> PutAsync <TRequest>(Uri requestUri, TRequest value, string mediaType = null) { return(HttpClientExtensions.PutAsync(this, requestUri, value, Formatter, mediaType)); }
public HttpResponseMessage Put <TRequest>(string requestUri, TRequest value, string mediaType = null) { return(HttpClientExtensions.PutAsync(this, requestUri, value, Formatter, mediaType).Result); }