feat: add support for file source and url source

This commit is contained in:
Stevan Freeborn
2025-07-14 23:30:02 -05:00
parent 267972ca94
commit 1f83899eb8
10 changed files with 469 additions and 27 deletions
@@ -0,0 +1,52 @@
namespace AnthropicClient.Tests.Unit.Models;
public class FileSourceTests : SerializationTest
{
private readonly string _testJson = @"{
""file_id"": ""id"",
""type"": ""file""
}";
[Fact]
public void Constructor_WhenCalled_ItShouldInitializeProperties()
{
var result = new FileSource();
result.Type.Should().Be("file");
result.Id.Should().BeEmpty();
}
[Fact]
public void Constructor_WhenCalledWithValues_ItShouldInitializeProperties()
{
var id = "id";
var type = "type";
var result = new FileSource()
{
Id = id,
Type = type,
};
result.Id.Should().Be(id);
result.Type.Should().Be(type);
}
[Fact]
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
{
var source = new FileSource() { Id = "id" };
var result = Serialize<Source>(source);
JsonAssert.Equal(_testJson, result);
}
[Fact]
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedValues()
{
var result = Deserialize<Source>(_testJson);
result.Should().BeEquivalentTo(new FileSource() { Id = "id" });
}
}
@@ -77,7 +77,7 @@ public class ImageContentTests : SerializationTest
}
[Fact]
public void Constructor_WhenCalledWithCacheControlAndMediatTypeIsNull_ItShouldThrowArgumentNullException()
public void Constructor_WhenCalledWithCacheControlAndMediaTypeIsNull_ItShouldThrowArgumentNullException()
{
var expectedData = "data";
var cacheControl = new EphemeralCacheControl();
@@ -98,6 +98,49 @@ public class ImageContentTests : SerializationTest
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithSource_ItShouldInitializeSource()
{
var source = new ImageSource("image/png", "data");
var result = new ImageContent(source);
result.Source.Should().BeSameAs(source);
}
[Fact]
public void Constructor_WhenCalledWithSourceAndCacheControl_ItShouldInitializeSourceAndCacheControl()
{
var source = new ImageSource("image/png", "data");
var cacheControl = new EphemeralCacheControl();
var result = new ImageContent(source, cacheControl);
result.Source.Should().BeSameAs(source);
result.CacheControl.Should().BeSameAs(cacheControl);
}
[Fact]
public void Constructor_WhenSourceIsNull_ItShouldThrowArgumentNullException()
{
Source? source = null;
var action = () => new ImageContent(source!);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCacheControlIsNull_ItShouldThrowNullException()
{
var source = new ImageSource("image/png", "data");
CacheControl? cacheControl = null;
var action = () => new ImageContent(source, cacheControl!);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
{
@@ -19,4 +19,10 @@ public class SourceTypeTests
{
SourceType.Text.Should().Be("text");
}
[Fact]
public void File_WhenCalled_ItShouldReturnCorrectValue()
{
SourceType.File.Should().Be("file");
}
}
@@ -0,0 +1,64 @@
namespace AnthropicClient.Tests.Unit.Models;
public class UrlSourceTests : SerializationTest
{
private readonly string _testJson = @"{
""type"": ""url"",
""url"": ""https://example.com/document.pdf""
}";
[Fact]
public void Constructor_WhenCalled_ItShouldInitializeProperties()
{
var result = new UrlSource();
result.Url.Should().BeEmpty();
result.Type.Should().Be("url");
}
[Fact]
public void Constructor_WhenCalledWithValues_ItShouldInitializeProperties()
{
var url = "https://example.com/document.pdf";
var type = "type";
var result = new UrlSource()
{
Url = url,
Type = type,
};
result.Url.Should().Be(url);
result.Type.Should().Be(type);
}
[Fact]
public void Constructor_WhenCalledWithUrl_ItShouldInitializeProperties()
{
var url = "https://example.com/document.pdf";
var result = new UrlSource(url);
result.Url.Should().Be(url);
result.Type.Should().Be("url");
}
[Fact]
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
{
var url = "https://example.com/document.pdf";
var source = new UrlSource(url);
var result = Serialize<Source>(source);
JsonAssert.Equal(_testJson, result);
}
[Fact]
public void JsonDeserialization_WhenDeserialized_ItShouldMatchExpectedObject()
{
var result = Deserialize<Source>(_testJson);
result.Should().BeEquivalentTo(new UrlSource("https://example.com/document.pdf"));
}
}