public void SetHttpMessageContentTransferEncodingFromRequestInsteadOfPayloadHandler() { // the TestPayloadHandler has a ContentType of "foo" var testPayloadHandler = new TestPayloadHandler(); // register the payload handler so that it is found when the ContentType of the request is set PayloadHandler.TryRegister(testPayloadHandler); // set the ContentType of the request to match the ContentType of the TestPayloadHandler so that the request uses the TestPayloadHandler var testHttpRequest = new HttpRequest { ContentType = "foo", ContentTransferEncoding = "testContentTransferEncoding-fromRequest", }; var testContentTransferEncoding = "testContentTransferEncoding-fromPayloadHandler"; testPayloadHandler.SetContentTransferEncoding(testContentTransferEncoding); var httpRequestMessage = new HttpRequestMessage(); testPayloadHandler.SetHttpRequestMessageContent(testHttpRequest, httpRequestMessage); httpRequestMessage.Headers.Contains("Content-Transfer-Encoding").Should().BeTrue(); // the content transfer encoding set on the request should win over the content transfer encoding set on the payload handler httpRequestMessage.Headers.ToString().Should().BeOneOf( "Content-Transfer-Encoding: testContentTransferEncoding-fromRequest\n", "Content-Transfer-Encoding: testContentTransferEncoding-fromRequest\r\n"); httpRequestMessage.Content.Should().NotBeNull(); httpRequestMessage.Content.GetType().Should().Be(typeof(StringContent)); }
public void SetHttpMessageContentTransferEncodingHeader() { // the TestPayloadHandler has a ContentType of "foo" var testPayloadHandler = new TestPayloadHandler(); // register the payload handler so that it is found when the ContentType of the request is set. The OktaClient will register payload handlers as appropriate. PayloadHandler.TryRegister(testPayloadHandler); // set the ContentType of the request to match the ContentType of the TestPayloadHandler so that the request uses the TestPayloadHandler var testHttpRequest = new HttpRequest { ContentType = "foo" }; var testContentTransferEncoding = "testContentTransferEncoding-fromPayloadHandler"; testPayloadHandler.SetContentTransferEncoding(testContentTransferEncoding); var httpRequestMessage = new HttpRequestMessage(); testPayloadHandler.SetHttpRequestMessageContent(testHttpRequest, httpRequestMessage); httpRequestMessage.Headers.Contains("Content-Transfer-Encoding").Should().BeTrue(); // if there is no content transfer encoding on the request then the value from the PayloadHandler is used httpRequestMessage.Headers.ToString().Should().BeOneOf( "Content-Transfer-Encoding: testContentTransferEncoding-fromPayloadHandler\n", "Content-Transfer-Encoding: testContentTransferEncoding-fromPayloadHandler\r\n"); httpRequestMessage.Content.Should().NotBeNull(); httpRequestMessage.Content.GetType().Should().Be(typeof(StringContent)); }
public async Task SetPayloadHandlerContentTypeOnPostAsync() { var mockRequestExecutor = Substitute.For <IRequestExecutor>(); mockRequestExecutor .PostAsync(Arg.Any <HttpRequest>(), Arg.Any <CancellationToken>()) .Returns(new HttpResponse <string>() { StatusCode = 200 }); var testPayloadHandler = new TestPayloadHandler(); PayloadHandler.TryRegister(testPayloadHandler); var request = new TestHttpRequest(); request.ContentType.Should().Be("application/json"); request.GetPayloadHandler().ContentType.Should().Be("application/json"); var dataStore = new DefaultDataStore(mockRequestExecutor, new DefaultSerializer(), new ResourceFactory(null, null), NullLogger.Instance); await dataStore.PostAsync <TestResource>(request, new RequestContext { ContentType = "foo" }, CancellationToken.None); request.ContentType.Should().Be("foo"); request.GetPayloadHandler().ContentType.Should().Be("foo"); }
public void SetHttpMessageContent() { // the TestPayloadHandler has a ContentType of "foo" var testPayloadHandler = new TestPayloadHandler(); // register the payload handler so that it is found when the ContentType of the request is set. The OktaClient will register payload handlers as appropriate. PayloadHandler.TryRegister(testPayloadHandler); // set the ContentType of the request to match the ContentType of the TestPayloadHandler so that the request uses the TestPayloadHandler var testHttpRequest = new HttpRequest { ContentType = "foo" }; var httpRequestMessage = new HttpRequestMessage(); httpRequestMessage.Content.Should().BeNull(); testPayloadHandler.SetHttpRequestMessageContent(testHttpRequest, httpRequestMessage); httpRequestMessage.Content.Should().NotBeNull(); httpRequestMessage.Content.GetType().Should().Be(typeof(StringContent)); }