tests: work on adding integration tests

This commit is contained in:
Stevan Freeborn
2024-07-01 23:59:24 -05:00
parent c2788c3893
commit ebae27077e
6 changed files with 180 additions and 2 deletions
@@ -0,0 +1,40 @@
namespace AnthropicClient.Tests.Integration;
public class IntegrationTest
{
protected readonly MockHttpMessageHandler _mockHttpMessageHandler = new();
protected AnthropicApiClient Client => CreateClient();
private AnthropicApiClient CreateClient()
{
return new AnthropicApiClient("test-key", _mockHttpMessageHandler.ToHttpClient());
}
}
public static class MockHttpMessageHandlerExtensions
{
private static MockedRequest SetupBaseRequest(this MockHttpMessageHandler mockHttpMessageHandler)
{
return mockHttpMessageHandler
.When(HttpMethod.Post, "https://api.anthropic.com/v1/messages")
.WithHeaders(new Dictionary<string, string>
{
{ "anthropic-version", "2023-06-01" },
{ "x-api-key", "test-key" }
});
}
public static MockedRequest WhenCreateMessageRequest(this MockHttpMessageHandler mockHttpMessageHandler)
{
return mockHttpMessageHandler
.SetupBaseRequest()
.WithJsonContent<ChatMessageRequest>(r => r.Stream == false);
}
public static MockedRequest WhenCreateStreamMessageRequest(this MockHttpMessageHandler mockHttpMessageHandler)
{
return mockHttpMessageHandler
.SetupBaseRequest()
.WithJsonContent<ChatMessageRequest>(r => r.Stream == true);
}
}