test(commons): NJ-1 review — backward-compat decode tests for old-form Float/DateTime + assert DateTime list is quoted-string array

This commit is contained in:
Joseph Doherty
2026-06-16 17:38:57 -04:00
parent abe8832e9e
commit bf80ca1388
@@ -93,10 +93,28 @@ public class AttributeValueCodecTests
{
var json = AttributeValueCodec.Encode(
new List<DateTime> { new(2026, 6, 16, 0, 0, 0, DateTimeKind.Utc) });
Assert.StartsWith("[\"", json); // DateTime list must be an array of quoted strings
Assert.Contains("2026-06-16T00:00:00", json);
Assert.DoesNotContain("06/16/2026", json);
}
[Fact]
public void Decode_OldStringFloatForm_BackwardCompatible()
{
var back = (IList<float>)AttributeValueCodec.Decode("[\"1.5\",\"2.25\"]", DataType.List, DataType.Float)!;
Assert.Equal(new[] { 1.5f, 2.25f }, back);
}
[Fact]
public void Decode_OldStringDateTimeForm_BackwardCompatible()
{
// The pre-native codec encoded DateTime via IFormattable.ToString(null, InvariantCulture):
// "06/16/2026 12:30:45" (US-invariant, no 'T'/'Z'). New Decode must still parse it.
var back = (IList<DateTime>)AttributeValueCodec.Decode(
"[\"06/16/2026 12:30:45\"]", DataType.List, DataType.DateTime)!;
Assert.Equal(new DateTime(2026, 6, 16, 12, 30, 45, DateTimeKind.Unspecified), back[0]);
}
[Fact]
public void Decode_NewNativeIntForm_Parses()
{