From 0c160e998a628af0f21883e592ddc8fb902f170f Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:17:29 -0500 Subject: [PATCH] tests: add tests for constructor using cache control --- .../Unit/Models/ToolResultContentTests.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/AnthropicClient.Tests/Unit/Models/ToolResultContentTests.cs b/tests/AnthropicClient.Tests/Unit/Models/ToolResultContentTests.cs index 0761f00..c15b209 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/ToolResultContentTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/ToolResultContentTests.cs @@ -35,6 +35,43 @@ public class ToolResultContentTests : SerializationTest action.Should().Throw(); } + [Fact] + public void Constructor_WhenCalledAndGivenCacheControl_ItShouldInitializeProperties() + { + var toolUseId = Guid.NewGuid().ToString(); + var content = "content"; + var cacheControl = new EphemeralCacheControl(); + + var actual = new ToolResultContent(toolUseId, content, cacheControl); + + actual.ToolUseId.Should().Be(toolUseId); + actual.Content.Should().Be(content); + actual.CacheControl.Should().BeSameAs(cacheControl); + actual.Type.Should().Be("tool_result"); + } + + [Fact] + public void Constructor_WhenCalledAndGivenCacheControlAndToolUseIdIsNull_ItShouldThrowArgumentNullException() + { + var content = "content"; + var cacheControl = new EphemeralCacheControl(); + + var action = () => new ToolResultContent(null!, content, cacheControl); + + action.Should().Throw(); + } + + [Fact] + public void Constructor_WhenCalledAndGivenCacheControlAndContentIsNull_ItShouldThrowArgumentNullException() + { + var toolUseId = Guid.NewGuid().ToString(); + var cacheControl = new EphemeralCacheControl(); + + var action = () => new ToolResultContent(toolUseId, null!, cacheControl); + + action.Should().Throw(); + } + [Fact] public void JsonSerialization_WhenSerialized_ItShouldReturnJsonString() { @@ -58,6 +95,34 @@ public class ToolResultContentTests : SerializationTest JsonAssert.Equal(expectedJson, actual); } + [Fact] + public void JsonSerialization_WhenSerializedWithCacheControl_ItShouldReturnJsonString() + { + var toolUseId = Guid.NewGuid().ToString(); + var content = "content"; + var cacheControl = new EphemeralCacheControl(); + + var expectedJson = @$"{{ + ""tool_use_id"": ""{toolUseId}"", + ""content"": ""{content}"", + ""type"": ""tool_result"", + ""cache_control"": {{ + ""type"": ""ephemeral"" + }} + }}"; + + var toolResultContent = new ToolResultContent + { + ToolUseId = toolUseId, + Content = content, + CacheControl = cacheControl + }; + + var actual = Serialize(toolResultContent); + + JsonAssert.Equal(expectedJson, actual); + } + [Fact] public void JsonDeserialization_WhenDeserialized_ItShouldReturnToolResultContent() {