From 0c62a7cfccbc7b0b894a6c1e8643ac52513f4c17 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 15 Jun 2025 11:49:48 -0500 Subject: [PATCH] tests: adding missing tests for newly introduced classes --- .../Models/CharacterLocationCitation.cs | 8 ++++ src/AnthropicClient/Models/Citation.cs | 15 +++++++ src/AnthropicClient/Models/CitationDelta.cs | 3 ++ .../Models/ContentBlockLocationCitation.cs | 8 ++++ .../Models/PageLocationCitation.cs | 8 ++++ .../Unit/Models/Base64SourceTests.cs | 39 +++++++++++++++++++ .../Models/CharacterLocationCitationTests.cs | 17 ++++++++ .../Unit/Models/CitationDeltaTests.cs | 31 +++++++++++++++ .../Unit/Models/CitationOptionTests.cs | 12 ++++++ .../Unit/Models/CitationTypeTests.cs | 22 +++++++++++ .../ContentBlockLocationCitationTests.cs | 17 ++++++++ .../Unit/Models/ContentDeltaTypeTests.cs | 10 +++++ 12 files changed, 190 insertions(+) create mode 100644 tests/AnthropicClient.Tests/Unit/Models/Base64SourceTests.cs create mode 100644 tests/AnthropicClient.Tests/Unit/Models/CharacterLocationCitationTests.cs create mode 100644 tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs create mode 100644 tests/AnthropicClient.Tests/Unit/Models/CitationOptionTests.cs create mode 100644 tests/AnthropicClient.Tests/Unit/Models/CitationTypeTests.cs create mode 100644 tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs diff --git a/src/AnthropicClient/Models/CharacterLocationCitation.cs b/src/AnthropicClient/Models/CharacterLocationCitation.cs index 0b461cb..678326e 100644 --- a/src/AnthropicClient/Models/CharacterLocationCitation.cs +++ b/src/AnthropicClient/Models/CharacterLocationCitation.cs @@ -18,4 +18,12 @@ public class CharacterLocationCitation : Citation /// [JsonPropertyName("end_char_index")] public int EndCharIndex { get; init; } + + /// + /// Initializes a new instance of the class. + /// + /// A new instance of . + public CharacterLocationCitation() : base(CitationType.CharacterLocation) + { + } } diff --git a/src/AnthropicClient/Models/Citation.cs b/src/AnthropicClient/Models/Citation.cs index ec7ae73..485f917 100644 --- a/src/AnthropicClient/Models/Citation.cs +++ b/src/AnthropicClient/Models/Citation.cs @@ -29,4 +29,19 @@ public abstract class Citation /// [JsonPropertyName("document_title")] public string DocumentTitle { get; init; } = string.Empty; + + [JsonConstructor] + internal Citation() + { + } + + /// + /// Initializes a new instance of the class with a specified type. + /// + /// The type of the citation. + /// A new instance of . + protected Citation(string type) + { + Type = type; + } } diff --git a/src/AnthropicClient/Models/CitationDelta.cs b/src/AnthropicClient/Models/CitationDelta.cs index 1d27bd0..e299d97 100644 --- a/src/AnthropicClient/Models/CitationDelta.cs +++ b/src/AnthropicClient/Models/CitationDelta.cs @@ -22,6 +22,9 @@ public class CitationDelta : ContentDelta /// /// Initializes a new instance of the class. /// + /// The citation to associate with this delta. + /// Thrown when is null. + /// A new instance of . public CitationDelta(Citation citation) : base(ContentDeltaType.CitationDelta) { ArgumentValidator.ThrowIfNull(citation, nameof(citation)); diff --git a/src/AnthropicClient/Models/ContentBlockLocationCitation.cs b/src/AnthropicClient/Models/ContentBlockLocationCitation.cs index 0cbb73a..f0383bb 100644 --- a/src/AnthropicClient/Models/ContentBlockLocationCitation.cs +++ b/src/AnthropicClient/Models/ContentBlockLocationCitation.cs @@ -18,4 +18,12 @@ public class ContentBlockLocationCitation : Citation /// [JsonPropertyName("end_block_index")] public int EndBlockIndex { get; init; } + + /// + /// Initializes a new instance of the class. + /// + /// A new instance of . + public ContentBlockLocationCitation() : base(CitationType.ContentBlockLocation) + { + } } \ No newline at end of file diff --git a/src/AnthropicClient/Models/PageLocationCitation.cs b/src/AnthropicClient/Models/PageLocationCitation.cs index 040c262..29a9ce1 100644 --- a/src/AnthropicClient/Models/PageLocationCitation.cs +++ b/src/AnthropicClient/Models/PageLocationCitation.cs @@ -18,4 +18,12 @@ public class PageLocationCitation : Citation /// [JsonPropertyName("end_page_number")] public int EndPageNumber { get; init; } + + /// + /// Initializes a new instance of the class. + /// + /// A new instance of . + public PageLocationCitation() : base(CitationType.PageLocation) + { + } } diff --git a/tests/AnthropicClient.Tests/Unit/Models/Base64SourceTests.cs b/tests/AnthropicClient.Tests/Unit/Models/Base64SourceTests.cs new file mode 100644 index 0000000..1a6972b --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/Base64SourceTests.cs @@ -0,0 +1,39 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class Base64SourceTests +{ + [Fact] + public void Constructor_WhenCalledWithValidArguments_ItShouldSetProperties() + { + var mediaType = "application/pdf"; + var data = "base64data"; + + var source = new Base64Source(mediaType, data); + + source.MediaType.Should().Be(mediaType); + source.Data.Should().Be(data); + source.Type.Should().Be("base64"); + } + + [Fact] + public void Constructor_WhenCalledWithNullMediaType_ItShouldThrowArgumentNullException() + { + string? mediaType = null; + var data = "base64data"; + + var action = () => new Base64Source(mediaType!, data); + + action.Should().Throw(); + } + + [Fact] + public void Constructor_WhenCalledWithNullData_ItShouldThrowArgumentNullException() + { + var mediaType = "application/pdf"; + string? data = null; + + var action = () => new Base64Source(mediaType, data!); + + 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 new file mode 100644 index 0000000..0043ea4 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/CharacterLocationCitationTests.cs @@ -0,0 +1,17 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class CharacterLocationCitationTests +{ + [Fact] + public void Constructor_WhenCalled_ItShouldSetProperties() + { + var result = new CharacterLocationCitation(); + + result.Type.Should().Be("char_location"); + result.CitedText.Should().BeEmpty(); + result.DocumentIndex.Should().Be(0); + result.DocumentTitle.Should().BeEmpty(); + result.StartCharIndex.Should().Be(0); + result.EndCharIndex.Should().Be(0); + } +} \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs b/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs new file mode 100644 index 0000000..8352ce8 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/CitationDeltaTests.cs @@ -0,0 +1,31 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class CitationDeltaTests +{ + [Fact] + public void Constructor_WhenCalled_ItShouldSetProperties() + { + var result = new CitationDelta(); + + result.Type.Should().Be("citations_delta"); + result.Citation.Should().BeEquivalentTo(new CharacterLocationCitation()); + } + + [Fact] + public void Constructor_WhenCalledWithCitation_ItShouldSetProperties() + { + var citation = new ContentBlockLocationCitation(); + var result = new CitationDelta(citation); + + result.Type.Should().Be("citations_delta"); + result.Citation.Should().BeSameAs(citation); + } + + [Fact] + public void Constructor_WhenCalledWithNullCitation_ItShouldThrowException() + { + var act = () => new CitationDelta(null!); + + act.Should().Throw(); + } +} \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/CitationOptionTests.cs b/tests/AnthropicClient.Tests/Unit/Models/CitationOptionTests.cs new file mode 100644 index 0000000..36ff5d8 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/CitationOptionTests.cs @@ -0,0 +1,12 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class CitationOptionTests +{ + [Fact] + public void Constructor_WhenCalled_ItShouldSetProperties() + { + var result = new CitationOption(); + + result.Enabled.Should().BeFalse(); + } +} \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/CitationTypeTests.cs b/tests/AnthropicClient.Tests/Unit/Models/CitationTypeTests.cs new file mode 100644 index 0000000..c0fb416 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/CitationTypeTests.cs @@ -0,0 +1,22 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class CitationTypeTests +{ + [Fact] + public void ContentBlockLocation_WhenCalled_ItShouldReturnCorrectValue() + { + CitationType.ContentBlockLocation.Should().Be("content_block_location"); + } + + [Fact] + public void CharacterLocation_WhenCalled_ItShouldReturnCorrectValue() + { + CitationType.CharacterLocation.Should().Be("char_location"); + } + + [Fact] + public void PageLocation_WhenCalled_ItShouldReturnCorrectValue() + { + CitationType.PageLocation.Should().Be("page_location"); + } +} \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs b/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs new file mode 100644 index 0000000..45fc169 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/ContentBlockLocationCitationTests.cs @@ -0,0 +1,17 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class ContentBlockLocationCitationTests +{ + [Fact] + public void Constructor_WhenCalled_ItShouldSetProperties() + { + var result = new ContentBlockLocationCitation(); + + result.Type.Should().Be("content_block_location"); + result.CitedText.Should().BeEmpty(); + result.DocumentIndex.Should().Be(0); + result.DocumentTitle.Should().BeEmpty(); + result.StartBlockIndex.Should().Be(0); + result.EndBlockIndex.Should().Be(0); + } +} \ No newline at end of file diff --git a/tests/AnthropicClient.Tests/Unit/Models/ContentDeltaTypeTests.cs b/tests/AnthropicClient.Tests/Unit/Models/ContentDeltaTypeTests.cs index 32a0023..bb46b42 100644 --- a/tests/AnthropicClient.Tests/Unit/Models/ContentDeltaTypeTests.cs +++ b/tests/AnthropicClient.Tests/Unit/Models/ContentDeltaTypeTests.cs @@ -21,4 +21,14 @@ public class ContentDeltaTypeTests actual.Should().Be(expected); } + + [Fact] + public void CitationDelta_WhenCalled_ItShouldReturnExpectedValue() + { + var expected = "citations_delta"; + + var actual = ContentDeltaType.CitationDelta; + + actual.Should().Be(expected); + } } \ No newline at end of file