diff --git a/tests/AnthropicClient.Tests/Unit/Json/CitationConverterTests.cs b/tests/AnthropicClient.Tests/Unit/Json/CitationConverterTests.cs new file mode 100644 index 0000000..2f7fb5f --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Json/CitationConverterTests.cs @@ -0,0 +1,14 @@ +namespace AnthropicClient.Tests.Unit.Json; + +public class CitationConverterTests : SerializationTest +{ + [Fact] + public void JsonDeserialization_WhenTypeIsUnknown_ItThrowException() + { + var json = @"{ ""type"": ""unknown"" }"; + + var action = () => Deserialize(json); + + action.Should().Throw(); + } +} \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/CharacterLocationCitationTests.cs b/tests/AnthropicClient.Tests/Unit/Models/CharacterLocationCitationTests.cs index 0043ea4..397c572 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/CharacterLocationCitationTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/CharacterLocationCitationTests.cs @@ -1,7 +1,16 @@ namespace AnthropicClient.Tests.Unit.Models; -public class CharacterLocationCitationTests +public class CharacterLocationCitationTests : SerializationTest { + private readonly string _testJson = @"{ + ""type"": ""char_location"", + ""cited_text"": ""cited text"", + ""document_index"": 1, + ""document_title"": ""document title"", + ""start_char_index"": 2, + ""end_char_index"": 3 + }"; + [Fact] public void Constructor_WhenCalled_ItShouldSetProperties() { @@ -14,4 +23,36 @@ public class CharacterLocationCitationTests result.StartCharIndex.Should().Be(0); result.EndCharIndex.Should().Be(0); } + + [Fact] + public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape() + { + var citation = new CharacterLocationCitation + { + Type = "char_location", + CitedText = "cited text", + DocumentIndex = 1, + DocumentTitle = "document title", + StartCharIndex = 2, + EndCharIndex = 3 + }; + + var result = Serialize(citation); + + JsonAssert.Equal(_testJson, result); + } + + [Fact] + public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape() + { + var citation = Deserialize(_testJson); + + var characterLocationCitation = citation.As(); + characterLocationCitation!.Type.Should().Be("char_location"); + characterLocationCitation.CitedText.Should().Be("cited text"); + characterLocationCitation.DocumentIndex.Should().Be(1); + characterLocationCitation.DocumentTitle.Should().Be("document title"); + characterLocationCitation.StartCharIndex.Should().Be(2); + characterLocationCitation.EndCharIndex.Should().Be(3); + } } \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs b/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs index 8352ce8..2f6d691 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs @@ -1,7 +1,19 @@ namespace AnthropicClient.Tests.Unit.Models; -public class CitationDeltaTests +public class CitationDeltaTests : SerializationTest { + private readonly string _testJson = @"{ + ""type"": ""citations_delta"", + ""citation"": { + ""type"": ""content_block_location"", + ""cited_text"": ""cited text"", + ""document_index"": 1, + ""document_title"": ""document title"", + ""start_block_index"": 2, + ""end_block_index"": 3 + } + }"; + [Fact] public void Constructor_WhenCalled_ItShouldSetProperties() { @@ -28,4 +40,39 @@ public class CitationDeltaTests act.Should().Throw(); } + + [Fact] + public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape() + { + var citation = new ContentBlockLocationCitation + { + Type = "content_block_location", + CitedText = "cited text", + DocumentIndex = 1, + DocumentTitle = "document title", + StartBlockIndex = 2, + EndBlockIndex = 3 + }; + + var citationDelta = new CitationDelta(citation); + var result = Serialize(citationDelta); + + JsonAssert.Equal(_testJson, result); + } + + [Fact] + public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape() + { + var citation = Deserialize(_testJson); + + var citationDelta = citation.As(); + citationDelta!.Type.Should().Be("citations_delta"); + + var contentBlockLocationCitation = citationDelta.Citation.As(); + contentBlockLocationCitation!.CitedText.Should().Be("cited text"); + contentBlockLocationCitation.DocumentIndex.Should().Be(1); + contentBlockLocationCitation.DocumentTitle.Should().Be("document title"); + contentBlockLocationCitation.StartBlockIndex.Should().Be(2); + contentBlockLocationCitation.EndBlockIndex.Should().Be(3); + } } \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs b/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs index 45fc169..8188f0c 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs @@ -1,7 +1,16 @@ namespace AnthropicClient.Tests.Unit.Models; -public class ContentBlockLocationCitationTests +public class ContentBlockLocationCitationTests : SerializationTest { + private readonly string _testJson = @"{ + ""type"": ""content_block_location"", + ""cited_text"": ""cited text"", + ""document_index"": 1, + ""document_title"": ""document title"", + ""start_block_index"": 2, + ""end_block_index"": 3 + }"; + [Fact] public void Constructor_WhenCalled_ItShouldSetProperties() { @@ -14,4 +23,36 @@ public class ContentBlockLocationCitationTests result.StartBlockIndex.Should().Be(0); result.EndBlockIndex.Should().Be(0); } + + [Fact] + public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape() + { + var citation = new ContentBlockLocationCitation + { + Type = "content_block_location", + CitedText = "cited text", + DocumentIndex = 1, + DocumentTitle = "document title", + StartBlockIndex = 2, + EndBlockIndex = 3 + }; + + var result = Serialize(citation); + + JsonAssert.Equal(_testJson, result); + } + + [Fact] + public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape() + { + var citation = Deserialize(_testJson); + + var contentBlockLocationCitation = citation.As(); + contentBlockLocationCitation!.Type.Should().Be("content_block_location"); + contentBlockLocationCitation.CitedText.Should().Be("cited text"); + contentBlockLocationCitation.DocumentIndex.Should().Be(1); + contentBlockLocationCitation.DocumentTitle.Should().Be("document title"); + contentBlockLocationCitation.StartBlockIndex.Should().Be(2); + contentBlockLocationCitation.EndBlockIndex.Should().Be(3); + } } \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/DocumentContentTests.cs b/tests/AnthropicClient.Tests/Unit/Models/DocumentContentTests.cs index 1687bdb..c5c4971 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/DocumentContentTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/DocumentContentTests.cs @@ -87,6 +87,16 @@ public class DocumentContentTests : SerializationTest action.Should().Throw(); } + [Fact] + public void Constructor_WhenCalledWithSource_ItShouldInitializeSource() + { + var source = new DocumentSource("application/pdf", "data"); + + var result = new DocumentContent(source); + + result.Source.Should().BeSameAs(source); + } + [Fact] public void Constructor_WhenCalledWithSourceAndCacheControl_ItShouldInitializeSourceAndCacheControl() { diff --git a/tests/AnthropicClient.Tests/Unit/Models/PageLocationCitationTests.cs b/tests/AnthropicClient.Tests/Unit/Models/PageLocationCitationTests.cs index 37cc3a4..b97b629 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/PageLocationCitationTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/PageLocationCitationTests.cs @@ -1,7 +1,16 @@ namespace AnthropicClient.Tests.Unit.Models; -public class PageLocationCitationTests +public class PageLocationCitationTests : SerializationTest { + private readonly string _testJson = @"{ + ""type"": ""page_location"", + ""cited_text"": ""cited text"", + ""document_index"": 1, + ""document_title"": ""document title"", + ""start_page_number"": 2, + ""end_page_number"": 3 + }"; + [Fact] public void Constructor_WhenCalled_ItShouldSetProperties() { @@ -14,4 +23,36 @@ public class PageLocationCitationTests result.StartPageNumber.Should().Be(0); result.EndPageNumber.Should().Be(0); } + + [Fact] + public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape() + { + var citation = new PageLocationCitation + { + Type = "page_location", + CitedText = "cited text", + DocumentIndex = 1, + DocumentTitle = "document title", + StartPageNumber = 2, + EndPageNumber = 3 + }; + + var result = Serialize(citation); + + JsonAssert.Equal(_testJson, result); + } + + [Fact] + public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape() + { + var citation = Deserialize(_testJson); + + var pageLocationCitation = citation.As(); + pageLocationCitation!.Type.Should().Be("page_location"); + pageLocationCitation.CitedText.Should().Be("cited text"); + pageLocationCitation.DocumentIndex.Should().Be(1); + pageLocationCitation.DocumentTitle.Should().Be("document title"); + pageLocationCitation.StartPageNumber.Should().Be(2); + pageLocationCitation.EndPageNumber.Should().Be(3); + } } \ No newline at end of file