Skip to content

Commit 13e8917

Browse files
committed
test: accept netfx throwing, even when allowing for "numbers-as-string"
1 parent 217830a commit 13e8917

1 file changed

Lines changed: 40 additions & 10 deletions

File tree

tests/serialization/json/JsonParseNodeTests.cs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,15 @@ public void GetIntValue_CanReadNumber(string input, int? expected)
559559

560560
[Theory]
561561
[InlineData("42", 42, "")]
562-
[InlineData("\"42\"", 42, "")]
563-
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Int32.")]
564562
[InlineData("null", null, "")]
563+
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Int32.")]
564+
#if NET5_0_OR_GREATER
565+
[InlineData("\"42\"", 42, "")]
566+
#else
567+
// below net5, JsonNumberHandling.AllowReadingFromString is not fully supported, so we are expecting an exception in this case
568+
// see https://github.com/microsoft/kiota-dotnet/pull/551#issuecomment-2981322976
569+
[InlineData("\"42\"", null, "The JSON value could not be converted to System.Int32.")]
570+
#endif
565571
public void GetIntValue_CanReadNumber_AsString(string input, int? expectedValue, string? expectexpectedExceptionMessage)
566572
{
567573
// Arrange
@@ -589,9 +595,15 @@ public void GetLongValue_CanReadNumber(string input, long? expected)
589595

590596
[Theory]
591597
[InlineData("42", 42L, null)]
592-
[InlineData("\"42\"", 42L, null)]
593-
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Int64.")]
594598
[InlineData("null", null, null)]
599+
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Int64.")]
600+
#if NET5_0_OR_GREATER
601+
[InlineData("\"42\"", 42L, null)]
602+
#else
603+
// below net5, JsonNumberHandling.AllowReadingFromString is not fully supported, so we are expecting an exception in this case
604+
// see https://github.com/microsoft/kiota-dotnet/pull/551#issuecomment-2981322976
605+
[InlineData("\"42\"", null, "The JSON value could not be converted to System.Int64.")]
606+
#endif
595607
public void GetLongValue_CanReadNumber_AsString(string input, long? expectedValue, string? expectedExceptionMessage)
596608
{
597609
// Arrange
@@ -619,9 +631,15 @@ public void GetFloatValue_CanReadNumber(string input, float? expected)
619631

620632
[Theory]
621633
[InlineData("13.37", 13.37F, "")]
622-
[InlineData("\"13.37\"", 13.37F, "")]
623-
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Single.")]
624634
[InlineData("null", null, "")]
635+
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Single.")]
636+
#if NET5_0_OR_GREATER
637+
[InlineData("\"13.37\"", 13.37F, "")]
638+
#else
639+
// below net5, JsonNumberHandling.AllowReadingFromString is not fully supported, so we are expecting an exception in this case
640+
// see https://github.com/microsoft/kiota-dotnet/pull/551#issuecomment-2981322976
641+
[InlineData("\"13.37\"", null, "The JSON value could not be converted to System.Single.")]
642+
#endif
625643
public void GetFloatValue_CanReadNumber_AsString(string input, float? expectedValue, string? expectedExceptionMessage)
626644
{
627645
// Arrange
@@ -649,9 +667,16 @@ public void GetDoubleValue_CanReadNumber(string input, double? expected)
649667

650668
[Theory]
651669
[InlineData("13.37", 13.37D)]
652-
[InlineData("\"13.37\"", 13.37D)]
653-
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Double.")]
654670
[InlineData("null", null)]
671+
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Double.")]
672+
[InlineData("\"13.37\"", 13.37D)]
673+
#if NET5_0_OR_GREATER
674+
[InlineData("\"13.37\"", 13.37D, "")]
675+
#else
676+
// below net5, JsonNumberHandling.AllowReadingFromString is not fully supported, so we are expecting an exception in this case
677+
// see https://github.com/microsoft/kiota-dotnet/pull/551#issuecomment-2981322976
678+
[InlineData("\"13.37\"", null, "The JSON value could not be converted to System.Double.")]
679+
#endif
655680
public void GetDoubleValue_CanReadNumber_AsString(string input, double? expectedValue, string? expectedExceptionMessage = null)
656681
{
657682
// Arrange
@@ -683,9 +708,14 @@ public void GetDecimalValue_CanReadNumber(string input, double? expectedDouble)
683708

684709
[Theory]
685710
[InlineData("13.37", 13.37)]
686-
[InlineData("\"13.37\"", 13.37)]
687-
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Decimal.")]
688711
[InlineData("null", null)]
712+
[InlineData("\"not-a-number\"", null, "The JSON value could not be converted to System.Decimal.")]
713+
[InlineData("\"13.37\"", 13.37)]
714+
#if NET5_0_OR_GREATER
715+
[InlineData("\"13.37\"", 13.37, "")]
716+
#else
717+
[InlineData("\"13.37\"", null, "The JSON value could not be converted to System.Decimal.")]
718+
#endif
689719
public void GetDecimalValue_CanReadNumber_AsString(string input, double? expectedDouble, string? expectedExceptionMessage = null)
690720
{
691721
// Arrange

0 commit comments

Comments
 (0)