Skip to content

Commit 96b222c

Browse files
committed
Added more coverage for the unit test on Read.
1 parent 82fde2e commit 96b222c

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

TensionDev.UUID.Serialization.SystemTextJson.Tests/TestUuidSystemTextJsonConverter.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,59 @@ public void TestWrite(bool useNullOptions)
4040
}
4141

4242
[Fact]
43-
public void TestRead()
43+
public void TestReadNotString()
44+
{
45+
// Arrange
46+
// Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers.
47+
const string input = "00000000-0000-0000-0000-000000000000";
48+
string jsonText = "0";
49+
byte[] json = Encoding.UTF8.GetBytes(jsonText);
50+
var reader = new Utf8JsonReader(json);
51+
reader.Read();
52+
53+
// Act
54+
JsonException ex = null;
55+
try
56+
{
57+
_converter.Read(ref reader, typeof(Uuid), new JsonSerializerOptions());
58+
}
59+
catch (JsonException caught)
60+
{
61+
ex = caught;
62+
}
63+
64+
// Assert
65+
Assert.NotNull(ex);
66+
}
67+
68+
[Fact]
69+
public void TestReadEmptyString()
70+
{
71+
// Arrange
72+
// Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers.
73+
const string input = "00000000-0000-0000-0000-000000000000";
74+
string jsonText = "\"\"";
75+
byte[] json = Encoding.UTF8.GetBytes(jsonText);
76+
var reader = new Utf8JsonReader(json);
77+
reader.Read();
78+
79+
// Act
80+
JsonException ex = null;
81+
try
82+
{
83+
_converter.Read(ref reader, typeof(Uuid), new JsonSerializerOptions());
84+
}
85+
catch (JsonException caught)
86+
{
87+
ex = caught;
88+
}
89+
90+
// Assert
91+
Assert.NotNull(ex);
92+
}
93+
94+
[Fact]
95+
public void TestReadString()
4496
{
4597
// Arrange
4698
// Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers.

0 commit comments

Comments
 (0)