feat: add serialization tests for CharacterLocationCitation, CitationDelta, ContentBlockLocationCitation, PageLocationCitation, and DocumentContent classes
This commit is contained in:
@@ -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<Citation>(json);
|
||||||
|
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
namespace AnthropicClient.Tests.Unit.Models;
|
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]
|
[Fact]
|
||||||
public void Constructor_WhenCalled_ItShouldSetProperties()
|
public void Constructor_WhenCalled_ItShouldSetProperties()
|
||||||
{
|
{
|
||||||
@@ -14,4 +23,36 @@ public class CharacterLocationCitationTests
|
|||||||
result.StartCharIndex.Should().Be(0);
|
result.StartCharIndex.Should().Be(0);
|
||||||
result.EndCharIndex.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>(citation);
|
||||||
|
|
||||||
|
JsonAssert.Equal(_testJson, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||||
|
{
|
||||||
|
var citation = Deserialize<Citation>(_testJson);
|
||||||
|
|
||||||
|
var characterLocationCitation = citation.As<CharacterLocationCitation>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,19 @@
|
|||||||
namespace AnthropicClient.Tests.Unit.Models;
|
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]
|
[Fact]
|
||||||
public void Constructor_WhenCalled_ItShouldSetProperties()
|
public void Constructor_WhenCalled_ItShouldSetProperties()
|
||||||
{
|
{
|
||||||
@@ -28,4 +40,39 @@ public class CitationDeltaTests
|
|||||||
|
|
||||||
act.Should().Throw<ArgumentNullException>();
|
act.Should().Throw<ArgumentNullException>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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<ContentDelta>(citationDelta);
|
||||||
|
|
||||||
|
JsonAssert.Equal(_testJson, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||||
|
{
|
||||||
|
var citation = Deserialize<ContentDelta>(_testJson);
|
||||||
|
|
||||||
|
var citationDelta = citation.As<CitationDelta>();
|
||||||
|
citationDelta!.Type.Should().Be("citations_delta");
|
||||||
|
|
||||||
|
var contentBlockLocationCitation = citationDelta.Citation.As<ContentBlockLocationCitation>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
namespace AnthropicClient.Tests.Unit.Models;
|
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]
|
[Fact]
|
||||||
public void Constructor_WhenCalled_ItShouldSetProperties()
|
public void Constructor_WhenCalled_ItShouldSetProperties()
|
||||||
{
|
{
|
||||||
@@ -14,4 +23,36 @@ public class ContentBlockLocationCitationTests
|
|||||||
result.StartBlockIndex.Should().Be(0);
|
result.StartBlockIndex.Should().Be(0);
|
||||||
result.EndBlockIndex.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>(citation);
|
||||||
|
|
||||||
|
JsonAssert.Equal(_testJson, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||||
|
{
|
||||||
|
var citation = Deserialize<Citation>(_testJson);
|
||||||
|
|
||||||
|
var contentBlockLocationCitation = citation.As<ContentBlockLocationCitation>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -87,6 +87,16 @@ public class DocumentContentTests : SerializationTest
|
|||||||
action.Should().Throw<ArgumentNullException>();
|
action.Should().Throw<ArgumentNullException>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Constructor_WhenCalledWithSource_ItShouldInitializeSource()
|
||||||
|
{
|
||||||
|
var source = new DocumentSource("application/pdf", "data");
|
||||||
|
|
||||||
|
var result = new DocumentContent(source);
|
||||||
|
|
||||||
|
result.Source.Should().BeSameAs(source);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Constructor_WhenCalledWithSourceAndCacheControl_ItShouldInitializeSourceAndCacheControl()
|
public void Constructor_WhenCalledWithSourceAndCacheControl_ItShouldInitializeSourceAndCacheControl()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
namespace AnthropicClient.Tests.Unit.Models;
|
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]
|
[Fact]
|
||||||
public void Constructor_WhenCalled_ItShouldSetProperties()
|
public void Constructor_WhenCalled_ItShouldSetProperties()
|
||||||
{
|
{
|
||||||
@@ -14,4 +23,36 @@ public class PageLocationCitationTests
|
|||||||
result.StartPageNumber.Should().Be(0);
|
result.StartPageNumber.Should().Be(0);
|
||||||
result.EndPageNumber.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>(citation);
|
||||||
|
|
||||||
|
JsonAssert.Equal(_testJson, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||||
|
{
|
||||||
|
var citation = Deserialize<Citation>(_testJson);
|
||||||
|
|
||||||
|
var pageLocationCitation = citation.As<PageLocationCitation>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user