From 96b222c8972f9ef81c97d71f890c14dfba90c862 Mon Sep 17 00:00:00 2001 From: amsga <49681949+amsga@users.noreply.github.com> Date: Wed, 11 Feb 2026 16:46:59 +0800 Subject: [PATCH] Added more coverage for the unit test on Read. --- .../TestUuidSystemTextJsonConverter.cs | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/TensionDev.UUID.Serialization.SystemTextJson.Tests/TestUuidSystemTextJsonConverter.cs b/TensionDev.UUID.Serialization.SystemTextJson.Tests/TestUuidSystemTextJsonConverter.cs index a0534a2..f335e5c 100644 --- a/TensionDev.UUID.Serialization.SystemTextJson.Tests/TestUuidSystemTextJsonConverter.cs +++ b/TensionDev.UUID.Serialization.SystemTextJson.Tests/TestUuidSystemTextJsonConverter.cs @@ -40,7 +40,59 @@ public void TestWrite(bool useNullOptions) } [Fact] - public void TestRead() + public void TestReadNotString() + { + // Arrange + // Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers. + const string input = "00000000-0000-0000-0000-000000000000"; + string jsonText = "0"; + byte[] json = Encoding.UTF8.GetBytes(jsonText); + var reader = new Utf8JsonReader(json); + reader.Read(); + + // Act + JsonException ex = null; + try + { + _converter.Read(ref reader, typeof(Uuid), new JsonSerializerOptions()); + } + catch (JsonException caught) + { + ex = caught; + } + + // Assert + Assert.NotNull(ex); + } + + [Fact] + public void TestReadEmptyString() + { + // Arrange + // Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers. + const string input = "00000000-0000-0000-0000-000000000000"; + string jsonText = "\"\""; + byte[] json = Encoding.UTF8.GetBytes(jsonText); + var reader = new Utf8JsonReader(json); + reader.Read(); + + // Act + JsonException ex = null; + try + { + _converter.Read(ref reader, typeof(Uuid), new JsonSerializerOptions()); + } + catch (JsonException caught) + { + ex = caught; + } + + // Assert + Assert.NotNull(ex); + } + + [Fact] + public void TestReadString() { // Arrange // Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers.