Skip to content

Commit

Permalink
Added header handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Jul 7, 2024
1 parent 6ab332e commit 554ffd7
Showing 1 changed file with 42 additions and 0 deletions.
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>()
);
}
}

0 comments on commit 554ffd7

Please sign in to comment.