fix: add missing type property to image source model

This commit is contained in:
Stevan Freeborn
2024-07-18 23:46:55 -05:00
parent 999a255468
commit 0a692d1b9a
3 changed files with 66 additions and 0 deletions
@@ -20,6 +20,11 @@ public class ImageSource
/// </summary>
public string Data { get; init; } = string.Empty;
/// <summary>
/// Gets the type of encoding of the image data.
/// </summary>
public string Type { get; init; } = "base64";
[JsonConstructor]
internal ImageSource()
{
@@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);IDE0039</NoWarn>
</PropertyGroup>
<ItemGroup>
@@ -0,0 +1,60 @@
namespace AnthropicClient.Tests.Unit.Models;
public class ImageSourceTests
{
[Fact]
public void Constructor_WhenCalledWithValidArguments_ItShouldSetProperties()
{
var mediaType = "image/jpeg";
var data = "base64data";
var imageSource = new ImageSource(mediaType, data);
imageSource.MediaType.Should().Be(mediaType);
imageSource.Data.Should().Be(data);
}
[Fact]
public void Constructor_WhenCalledWithInvalidMediaType_ItShouldThrowArgumentException()
{
var mediaType = "invalid";
var data = "base64data";
var action = () => new ImageSource(mediaType, data);
action.Should().Throw<ArgumentException>();
}
[Fact]
public void Constructor_WhenCalledWithNullMediaType_ItShouldThrowArgumentNullException()
{
string? mediaType = null;
var data = "base64data";
var action = () => new ImageSource(mediaType!, data);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalledWithNullData_ItShouldThrowArgumentNullException()
{
var mediaType = "image/jpeg";
string? data = null;
var action = () => new ImageSource(mediaType, data!);
action.Should().Throw<ArgumentNullException>();
}
[Fact]
public void Constructor_WhenCalled_ItShouldHaveTypePropertySetToBase64()
{
var mediaType = "image/jpeg";
var data = "base64data";
var imageSource = new ImageSource(mediaType, data);
imageSource.Type.Should().Be("base64");
}
}