-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1 | ADDED: Transmitter concept for hooking Sending Function.
- Loading branch information
Showing
5 changed files
with
93 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using FluentAssertions; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace TitanShark.Thresher.Core.Tests | ||
{ | ||
public class TransmitterTests | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public TransmitterTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public async Task Custom_SendFunction_In_Transmitter_Is_Possible() | ||
{ | ||
// prepares | ||
const string responseContentText = "Hello World!"; | ||
var transmitter = new Transmitter | ||
( | ||
(callId, request, cancellationToken) => | ||
{ | ||
_output.WriteLine($"Request to '{request.RequestUri}' was sent out."); | ||
|
||
return Task.FromResult(new HttpResponseMessage(System.Net.HttpStatusCode.Created) | ||
{ | ||
Content = new StringContent(responseContentText) | ||
}); | ||
} | ||
); | ||
var handler = new SerialInterceptionHttpClientHandler(transmitter: transmitter); | ||
var sut = new HttpClient(handler); | ||
|
||
// acts | ||
var response = await sut.GetAsync("https://testing.only").ConfigureAwait(false); | ||
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); | ||
|
||
// asserts | ||
response.StatusCode.Should().Be(System.Net.HttpStatusCode.Created); | ||
content.Should().Be(responseContentText); | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace TitanShark.Thresher.Core | ||
{ | ||
public class Transmitter | ||
{ | ||
public Func<CallId, HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> SendFunction { get; } | ||
|
||
public Transmitter(Func<CallId, HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> sendFunction) | ||
{ | ||
if (sendFunction == null) | ||
{ | ||
throw new ArgumentNullException(nameof(sendFunction)); | ||
} | ||
|
||
SendFunction = sendFunction; | ||
} | ||
} | ||
} |