From ebae27077ebaf4b1bd867560b589d62fe0119449 Mon Sep 17 00:00:00 2001
From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com>
Date: Mon, 1 Jul 2024 23:59:24 -0500
Subject: [PATCH] tests: work on adding integration tests
---
.../AnthropicClient.Tests.csproj | 1 +
.../Integration/AnthropicApiClientTests.cs | 34 ++++++
.../Integration/ErrorTestData.cs | 100 ++++++++++++++++++
.../Integration/IntegrationTest.cs | 40 +++++++
.../Unit/Utils/JsonSchemaGeneratorTestData.cs | 1 -
tests/AnthropicClient.Tests/Usings.cs | 6 +-
6 files changed, 180 insertions(+), 2 deletions(-)
create mode 100644 tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs
create mode 100644 tests/AnthropicClient.Tests/Integration/ErrorTestData.cs
create mode 100644 tests/AnthropicClient.Tests/Integration/IntegrationTest.cs
diff --git a/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj b/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj
index 491e4db..f21321f 100644
--- a/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj
+++ b/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj
@@ -14,6 +14,7 @@
+
diff --git a/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs b/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs
new file mode 100644
index 0000000..d073564
--- /dev/null
+++ b/tests/AnthropicClient.Tests/Integration/AnthropicApiClientTests.cs
@@ -0,0 +1,34 @@
+namespace AnthropicClient.Tests.Integration;
+
+public class AnthropicApiClientTests : IntegrationTest
+{
+ [Theory]
+ [ClassData(typeof(ErrorTestData))]
+ public async Task CreateChatMessageAsync_WhenCalledAndErrorReturned_ItShouldHandleError(
+ HttpStatusCode statusCode,
+ string content,
+ Type errorType
+ )
+ {
+ _mockHttpMessageHandler
+ .WhenCreateMessageRequest()
+ .Respond(
+ statusCode,
+ "application/json",
+ content
+ );
+
+ var request = new ChatMessageRequest(
+ model: AnthropicModels.Claude3Haiku,
+ messages: [new(MessageRole.User, [new TextContent("Hello!")])]
+ );
+
+ var result = await Client.CreateChatMessageAsync(request);
+
+ result.IsSuccess.Should().BeFalse();
+ result.Error.Should().BeOfType();
+
+ var actualErrorType = result.Error.Error!.GetType();
+ actualErrorType.Should().Be(errorType);
+ }
+}
\ No newline at end of file
diff --git a/tests/AnthropicClient.Tests/Integration/ErrorTestData.cs b/tests/AnthropicClient.Tests/Integration/ErrorTestData.cs
new file mode 100644
index 0000000..ed20c58
--- /dev/null
+++ b/tests/AnthropicClient.Tests/Integration/ErrorTestData.cs
@@ -0,0 +1,100 @@
+namespace AnthropicClient.Tests.Integration;
+
+public class ErrorTestData : IEnumerable