tests: adding missing tests for newly introduced classes

This commit is contained in:
Stevan Freeborn
2025-06-15 11:49:48 -05:00
parent 98da1384c1
commit 0c62a7cfcc
12 changed files with 190 additions and 0 deletions
@@ -18,4 +18,12 @@ public class CharacterLocationCitation : Citation
/// </summary>
[JsonPropertyName("end_char_index")]
public int EndCharIndex { get; init; }
/// <summary>
/// Initializes a new instance of the <see cref="CharacterLocationCitation"/> class.
/// </summary>
/// <returns>A new instance of <see cref="CharacterLocationCitation"/>.</returns>
public CharacterLocationCitation() : base(CitationType.CharacterLocation)
{
}
}
+15
View File
@@ -29,4 +29,19 @@ public abstract class Citation
/// </summary>
[JsonPropertyName("document_title")]
public string DocumentTitle { get; init; } = string.Empty;
[JsonConstructor]
internal Citation()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Citation"/> class with a specified type.
/// </summary>
/// <param name="type">The type of the citation.</param>
/// <returns>A new instance of <see cref="Citation"/>.</returns>
protected Citation(string type)
{
Type = type;
}
}
@@ -22,6 +22,9 @@ public class CitationDelta : ContentDelta
/// <summary>
/// Initializes a new instance of the <see cref="CitationDelta"/> class.
/// </summary>
/// <param name="citation">The citation to associate with this delta.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="citation"/> is null.</exception>
/// <returns>A new instance of <see cref="CitationDelta"/>.</returns>
public CitationDelta(Citation citation) : base(ContentDeltaType.CitationDelta)
{
ArgumentValidator.ThrowIfNull(citation, nameof(citation));
@@ -18,4 +18,12 @@ public class ContentBlockLocationCitation : Citation
/// </summary>
[JsonPropertyName("end_block_index")]
public int EndBlockIndex { get; init; }
/// <summary>
/// Initializes a new instance of the <see cref="ContentBlockLocationCitation"/> class.
/// </summary>
/// <returns>A new instance of <see cref="ContentBlockLocationCitation"/>.</returns>
public ContentBlockLocationCitation() : base(CitationType.ContentBlockLocation)
{
}
}
@@ -18,4 +18,12 @@ public class PageLocationCitation : Citation
/// </summary>
[JsonPropertyName("end_page_number")]
public int EndPageNumber { get; init; }
/// <summary>
/// Initializes a new instance of the <see cref="PageLocationCitation"/> class.
/// </summary>
/// <returns>A new instance of <see cref="PageLocationCitation"/>.</returns>
public PageLocationCitation() : base(CitationType.PageLocation)
{
}
}
@@ -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<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithNullData_ItShouldThrowArgumentNullException()
{
var mediaType = "application/pdf";
string? data = null;
var action = () => new Base64Source(mediaType, data!);
action.Should().Throw<ArgumentNullException>();
}
}
@@ -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);
}
}
@@ -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<ArgumentNullException>();
}
}
@@ -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();
}
}
@@ -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");
}
}
@@ -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);
}
}
@@ -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);
}
}