-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for PATCH in HttpConnection.ConvertHttpMethod
Signed-off-by: Assaf Tirangel <atirangel@corp.tenablesecurity.com>
- Loading branch information
Assaf Tirangel
authored and
atirangel
committed
Jan 9, 2024
1 parent
a9f9eb4
commit 1650a04
Showing
3 changed files
with
68 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
using System; | ||
using System.Net.Http; | ||
using FluentAssertions; | ||
using OpenSearch.Net; | ||
using OpenSearch.OpenSearch.Xunit.XunitPlumbing; | ||
using Xunit; | ||
using HttpMethod = OpenSearch.Net.HttpMethod; | ||
|
||
namespace Tests.Connection.Http; | ||
|
||
public class HttpConnectionTests | ||
{ | ||
public static TheoryData<HttpMethod> HttpMethods() | ||
{ | ||
var data = new TheoryData<HttpMethod>(); | ||
foreach (var httpMethod in Enum.GetValues<HttpMethod>()) data.Add(httpMethod); | ||
return data; | ||
} | ||
|
||
[TU] | ||
[MemberData(nameof(HttpMethods))] | ||
public void UsesCorrectHttpMethod(HttpMethod method) | ||
{ | ||
var mockHttpConnection = new MockHttpConnection(); | ||
mockHttpConnection.Request<StringResponse>(new RequestData(method, "", null, null, null, null)); | ||
mockHttpConnection.LastRequest.Method.Should().Be(new System.Net.Http.HttpMethod(method.ToString())); | ||
} | ||
|
||
private class MockHttpConnection : HttpConnection | ||
{ | ||
public HttpRequestMessage LastRequest { get; private set; } | ||
|
||
protected override HttpRequestMessage CreateHttpRequestMessage(RequestData requestData) | ||
{ | ||
LastRequest = base.CreateHttpRequestMessage(requestData); | ||
return LastRequest; | ||
} | ||
|
||
public override TResponse Request<TResponse>(RequestData requestData) | ||
{ | ||
CreateHttpRequestMessage(requestData); | ||
return new TResponse(); | ||
} | ||
} | ||
} |