Skip to content

Commit ebcdac0

Browse files
committed
test: GetDecimalValue as string
1 parent af749be commit ebcdac0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/serialization/json/JsonParseNodeTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,5 +735,31 @@ public void GetDecimalValue_CanReadNumber(string input, double? expectedDouble)
735735
Assert.Equal(expected.Value, actual.Value);
736736
}
737737
}
738+
739+
[Theory]
740+
[InlineData("13.37", 13.37)]
741+
[InlineData("\"13.37\"", 13.37)]
742+
[InlineData("null", null)]
743+
public void GetDecimalValue_CanReadNumber_AsString(string input, double? expectedDouble)
744+
{
745+
// Arrange
746+
var expected = expectedDouble.HasValue
747+
? Convert.ToDecimal(expectedDouble)
748+
: default(decimal?)
749+
; //13.37M is not supported as a constant expression in attributes
750+
751+
using var jsonDocument = JsonDocument.Parse(input);
752+
var parseNode = new JsonParseNode(jsonDocument.RootElement, readNumbersAsStringsContext);
753+
754+
// Act
755+
var actual = parseNode.GetDecimalValue();
756+
757+
// Assert
758+
Assert.Equal(expected.HasValue, actual.HasValue);
759+
if(expected.HasValue && actual.HasValue)
760+
{
761+
Assert.Equal(expected.Value, actual.Value);
762+
}
763+
}
738764
}
739765
}

0 commit comments

Comments
 (0)