From 0a692d1b9a5f39869aef05892f0801fefe31f50e Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Thu, 18 Jul 2024 23:46:55 -0500 Subject: [PATCH] fix: add missing type property to image source model --- src/AnthropicClient/Models/ImageSource.cs | 5 ++ .../AnthropicClient.Tests.csproj | 1 + .../Unit/Models/ImageSourceTests.cs | 60 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/AnthropicClient.Tests/Unit/Models/ImageSourceTests.cs diff --git a/src/AnthropicClient/Models/ImageSource.cs b/src/AnthropicClient/Models/ImageSource.cs index 4eca86d..cc68c74 100644 --- a/src/AnthropicClient/Models/ImageSource.cs +++ b/src/AnthropicClient/Models/ImageSource.cs @@ -20,6 +20,11 @@ public class ImageSource /// public string Data { get; init; } = string.Empty; + /// + /// Gets the type of encoding of the image data. + /// + public string Type { get; init; } = "base64"; + [JsonConstructor] internal ImageSource() { diff --git a/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj b/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj index 5dac8d0..0370ec0 100644 --- a/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj +++ b/tests/AnthropicClient.Tests/AnthropicClient.Tests.csproj @@ -6,6 +6,7 @@ enable false true + $(NoWarn);IDE0039 diff --git a/tests/AnthropicClient.Tests/Unit/Models/ImageSourceTests.cs b/tests/AnthropicClient.Tests/Unit/Models/ImageSourceTests.cs new file mode 100644 index 0000000..7fca4f9 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/ImageSourceTests.cs @@ -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(); + } + + [Fact] + public void Constructor_WhenCalledWithNullMediaType_ItShouldThrowArgumentNullException() + { + string? mediaType = null; + var data = "base64data"; + + var action = () => new ImageSource(mediaType!, data); + + action.Should().Throw(); + } + + [Fact] + public void Constructor_WhenCalledWithNullData_ItShouldThrowArgumentNullException() + { + var mediaType = "image/jpeg"; + string? data = null; + + var action = () => new ImageSource(mediaType, data!); + + action.Should().Throw(); + } + + [Fact] + public void Constructor_WhenCalled_ItShouldHaveTypePropertySetToBase64() + { + var mediaType = "image/jpeg"; + var data = "base64data"; + + var imageSource = new ImageSource(mediaType, data); + + imageSource.Type.Should().Be("base64"); + } +} \ No newline at end of file