-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
tests/PinguApps.Appwrite.Client.Tests/Handlers/HeaderHandlerTests.cs
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,42 @@ | ||
using Moq; | ||
using Moq.Protected; | ||
using PinguApps.Appwrite.Client.Handlers; | ||
using PinguApps.Appwrite.Shared.Tests; | ||
|
||
namespace PinguApps.Appwrite.Client.Tests.Handlers; | ||
public class HeaderHandlerTests | ||
{ | ||
[Fact] | ||
public async Task SendAsync_AddsRequiredHeaders() | ||
{ | ||
// Arrange | ||
var mockInnerHandler = new Mock<HttpMessageHandler>(); | ||
mockInnerHandler.Protected() | ||
.Setup<Task<HttpResponseMessage>>( | ||
"SendAsync", | ||
ItExpr.IsAny<HttpRequestMessage>(), | ||
ItExpr.IsAny<CancellationToken>() | ||
) | ||
.ReturnsAsync(new HttpResponseMessage()) | ||
.Verifiable(); | ||
|
||
var headerHandler = new HeaderHandler(Constants.ProjectId) | ||
{ | ||
InnerHandler = mockInnerHandler.Object | ||
}; | ||
var httpClient = new HttpClient(headerHandler); | ||
|
||
// Act | ||
await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "http://test.com")); | ||
|
||
// Assert | ||
mockInnerHandler.Protected().Verify( | ||
"SendAsync", | ||
Times.Once(), | ||
ItExpr.Is<HttpRequestMessage>(req => | ||
req.Headers.Contains("x-appwrite-project") && | ||
req.Headers.GetValues("x-appwrite-project").Contains(Constants.ProjectId)), | ||
ItExpr.IsAny<CancellationToken>() | ||
); | ||
} | ||
} |