-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add test for empty post request on httpClientWrapper * convert test method to not have async in signature * add post method to http wrapper mock call * add valid url to httpClientWrapperTest * use AreEquals instead of Equals * introduce httpClientWrapper fix
- Loading branch information
1 parent
ff88ecb
commit f98bfe8
Showing
3 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Adyen.HttpClient; | ||
using Adyen.Model.Management; | ||
using Adyen.Model.TerminalApi; | ||
using Adyen.Service.Management; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using NSubstitute; | ||
|
||
namespace Adyen.Test | ||
{ | ||
[TestClass] | ||
public class HttpClientWrapperTest : BaseTest | ||
{ | ||
[TestMethod] | ||
public void EmptyRequestBodyPostTest() | ||
{ | ||
var mockHttpMessageHandler = new MockHttpMessageHandler("{}", System.Net.HttpStatusCode.OK); | ||
var httpClient = new System.Net.Http.HttpClient(mockHttpMessageHandler); | ||
var httpClientWrapper = new HttpClientWrapper(MockPaymentData.CreateConfigApiKeyBasedMock(), httpClient); | ||
var _ = httpClientWrapper.Request("https://test.com/testpath", null, null, HttpMethod.Post); | ||
Assert.AreEqual("{}", mockHttpMessageHandler.Input); | ||
} | ||
|
||
} | ||
} |
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,34 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public class MockHttpMessageHandler : HttpMessageHandler | ||
{ | ||
private readonly string _response; | ||
private readonly HttpStatusCode _statusCode; | ||
|
||
public string Input { get; private set; } | ||
public int NumberOfCalls { get; private set; } | ||
|
||
public MockHttpMessageHandler(string response, HttpStatusCode statusCode) | ||
{ | ||
_response = response; | ||
_statusCode = statusCode; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, | ||
CancellationToken cancellationToken) | ||
{ | ||
NumberOfCalls++; | ||
if (request.Content != null) // Could be a GET-request without a body | ||
{ | ||
Input = await request.Content.ReadAsStringAsync(); | ||
} | ||
return new HttpResponseMessage | ||
{ | ||
StatusCode = _statusCode, | ||
Content = new StringContent(_response) | ||
}; | ||
} | ||
} |
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