From c212ebffcdfb21fbe1578fa5a877069bc749f3a7 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sat, 12 Jul 2025 22:37:54 -0500 Subject: [PATCH] tests: add tests for anthropic file model --- src/AnthropicClient/Models/AnthropicFile.cs | 2 +- .../Unit/Models/AnthropicFileTests.cs | 95 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/AnthropicClient.Tests/Unit/Models/AnthropicFileTests.cs diff --git a/src/AnthropicClient/Models/AnthropicFile.cs b/src/AnthropicClient/Models/AnthropicFile.cs index a736a39..7a10a35 100644 --- a/src/AnthropicClient/Models/AnthropicFile.cs +++ b/src/AnthropicClient/Models/AnthropicFile.cs @@ -17,7 +17,7 @@ public class AnthropicFile /// Object type. /// [JsonPropertyName("type")] - public string Type { get; init; } = "file"; + public string Type { get; init; } = string.Empty; /// /// Original filename of the uploaded file. diff --git a/tests/AnthropicClient.Tests/Unit/Models/AnthropicFileTests.cs b/tests/AnthropicClient.Tests/Unit/Models/AnthropicFileTests.cs new file mode 100644 index 0000000..cd679c9 --- /dev/null +++ b/tests/AnthropicClient.Tests/Unit/Models/AnthropicFileTests.cs @@ -0,0 +1,95 @@ +namespace AnthropicClient.Tests.Unit.Models; + +public class AnthropicFileTests : SerializationTest +{ + private readonly string _testJson = @"{ + ""id"": ""file-123"", + ""type"": ""file"", + ""filename"": ""test.txt"", + ""created_at"": ""2023-10-01T00:00:00Z"", + ""size_bytes"": 1024, + ""mime_type"": ""text/plain"", + ""downloadable"": true + }"; + + [Fact] + public void Constructor_WhenCalled_ItShouldInitializeProperties() + { + var result = new AnthropicFile(); + + result.Id.Should().BeEmpty(); + result.Type.Should().BeEmpty("file"); + result.Name.Should().BeEmpty(); + result.CreatedAt.Should().Be(DateTimeOffset.MinValue); + result.Size.Should().Be(0); + result.MimeType.Should().BeEmpty(); + result.Downloadable.Should().BeFalse(); + } + + [Fact] + public void Constructor_WhenCalledWithValues_ItShouldInitializeProperties() + { + var file = new AnthropicFile + { + Id = "file-123", + Type = "file", + Name = "test.txt", + CreatedAt = new DateTimeOffset(2023, 10, 1, 0, 0, 0, TimeSpan.Zero), + Size = 1024, + MimeType = "text/plain", + Downloadable = true + }; + + file.Id.Should().Be("file-123"); + file.Type.Should().Be("file"); + file.Name.Should().Be("test.txt"); + file.CreatedAt.Should().Be(new DateTimeOffset(2023, 10, 1, 0, 0, 0, TimeSpan.Zero)); + file.Size.Should().Be(1024); + file.MimeType.Should().Be("text/plain"); + file.Downloadable.Should().BeTrue(); + } + + [Fact] + public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape() + { + var file = new AnthropicFile + { + Id = "file-123", + Type = "file", + Name = "test.txt", + CreatedAt = new DateTimeOffset(2023, 10, 1, 0, 0, 0, TimeSpan.Zero), + Size = 1024, + MimeType = "text/plain", + Downloadable = true + }; + + var json = Serialize(file); + + var expectedJson = @"{ + ""id"": ""file-123"", + ""type"": ""file"", + ""filename"": ""test.txt"", + ""created_at"": ""2023-10-01T00:00:00+00:00"", + ""size_bytes"": 1024, + ""mime_type"": ""text/plain"", + ""downloadable"": true + }"; + + JsonAssert.Equal(expectedJson, json, true); + } + + [Fact] + public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedValues() + { + var file = Deserialize(_testJson); + + file.Should().NotBeNull(); + file!.Id.Should().Be("file-123"); + file.Type.Should().Be("file"); + file.Name.Should().Be("test.txt"); + file.CreatedAt.Should().Be(new DateTimeOffset(2023, 10, 1, 0, 0, 0, TimeSpan.Zero)); + file.Size.Should().Be(1024); + file.MimeType.Should().Be("text/plain"); + file.Downloadable.Should().BeTrue(); + } +} \ No newline at end of file