Fix exception tests where we are asserting against the literal message (dotnet/corefx...
authorLayomi Akinrinade <laakinri@microsoft.com>
Wed, 13 Nov 2019 05:25:46 +0000 (21:25 -0800)
committermsftbot[bot] <48340428+msftbot[bot]@users.noreply.github.com>
Wed, 13 Nov 2019 05:25:46 +0000 (05:25 +0000)
* Fix up exception tests where we are asserting against the literal message

* Remove null assignments

Commit migrated from https://github.com/dotnet/corefx/commit/dd1892dc53e28b481bfab364a08573214d3df462

src/libraries/System.Text.Json/tests/NewtonsoftTests/CustomObjectConverterTests.cs
src/libraries/System.Text.Json/tests/NewtonsoftTests/EnumConverterTests.cs
src/libraries/System.Text.Json/tests/NewtonsoftTests/ImmutableCollectionsTests.cs
src/libraries/System.Text.Json/tests/NewtonsoftTests/JsonSerializerTests.cs

index 2340b45..a34830f 100644 (file)
@@ -165,11 +165,8 @@ namespace System.Text.Json.Tests
                         ""Number"": 123
                     }
                 }]";
-            NotSupportedException nse = Assert.Throws<NotSupportedException>(() =>
-            {
-                JsonSerializer.Deserialize<List<MyClass>>(validJson);
-            });
-            Assert.Equal("Deserialization of interface types is not supported. Type 'System.Text.Json.Tests.IThing'", nse.Message);
+
+            Assert.Throws<NotSupportedException>(() => JsonSerializer.Deserialize<List<MyClass>>(validJson));
 
             const string invalidJson =
                 @"{
index 490de14..6594447 100644 (file)
@@ -186,17 +186,13 @@ namespace System.Text.Json.Tests
         [Fact]
         public static void DuplicateNameEnumTest()
         {
-            JsonException e = Assert.Throws<JsonException>(() =>
-                JsonSerializer.Deserialize<DuplicateNameEnum>("\"foo_bar\""));
+            Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<DuplicateNameEnum>("\"foo_bar\""));
         }
 
         [Fact]
         public static void InvalidValueStringNumber()
         {
-            JsonException ex = Assert.Throws<JsonException>(() =>
-            {
-                StoreColor s = JsonSerializer.Deserialize<StoreColor>("\"1\"");
-            });
+            Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<StoreColor>("\"1\""));
         }
 
         [Fact]
@@ -236,10 +232,7 @@ namespace System.Text.Json.Tests
         [Fact]
         public static void InvalidValueDash()
         {
-            JsonException ex = Assert.Throws<JsonException>(() =>
-            {
-                JsonSerializer.Deserialize<StoreColor>("\"-\"");
-            });
+            Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<StoreColor>("\"-\""));
         }
 
         [Fact]
index 10e588a..4b8829e 100644 (file)
@@ -128,9 +128,8 @@ namespace System.Text.Json.Tests
         [Fact]
         public void SerializeDefaultArray()
         {
-            InvalidOperationException e = Assert.Throws<InvalidOperationException>(
-                () => JsonSerializer.Serialize(default(ImmutableArray<int>), s_indentedOption));
-            Assert.Equal("This operation cannot be performed on a default instance of ImmutableArray<T>.  Consider initializing the array, or checking the ImmutableArray<T>.IsDefault property.", e.Message);
+            // The call to .GetEnumerator() throws this exception. Json.NET fails in the same way.
+            Assert.Throws<InvalidOperationException>(() => JsonSerializer.Serialize(default(ImmutableArray<int>), s_indentedOption));
         }
         #endregion
 
index 77d8a22..2826e8b 100644 (file)
@@ -69,22 +69,22 @@ namespace System.Text.Json.Tests
         public void IncompleteContainers()
         {
             JsonException e = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IList<object>>("[1,"));
-            Assert.Equal("Expected start of a property name or value, but instead reached end of data. Path: $[1] | LineNumber: 0 | BytePositionInLine: 2.", e.Message);
+            Assert.Contains("Path: $[1] | LineNumber: 0 | BytePositionInLine: 2.", e.Message);
 
             e = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IList<int>>("[1,"));
-            Assert.Equal("Expected start of a property name or value, but instead reached end of data. Path: $[1] | LineNumber: 0 | BytePositionInLine: 2.", e.Message);
+            Assert.Contains("Path: $[1] | LineNumber: 0 | BytePositionInLine: 2.", e.Message);
 
             e = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IList<int>>("[1"));
-            Assert.Equal("'1' is an invalid end of a number. Expected a delimiter. Path: $[0] | LineNumber: 0 | BytePositionInLine: 2.", e.Message);
+            Assert.Contains("Path: $[0] | LineNumber: 0 | BytePositionInLine: 2.", e.Message);
 
             e = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IDictionary<string, int>>("{\"key\":1,"));
-            Assert.Equal("Expected start of a property name or value, but instead reached end of data. Path: $.key | LineNumber: 0 | BytePositionInLine: 8.", e.Message);
+            Assert.Contains("Path: $.key | LineNumber: 0 | BytePositionInLine: 8.", e.Message);
 
             e = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IDictionary<string, int>>("{\"key\":1"));
-            Assert.Equal("'1' is an invalid end of a number. Expected a delimiter. Path: $.key | LineNumber: 0 | BytePositionInLine: 8.", e.Message);
+            Assert.Contains("Path: $.key | LineNumber: 0 | BytePositionInLine: 8.", e.Message);
 
             e = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IncompleteTestClass>("{\"key\":1,"));
-            Assert.Equal("Expected start of a property name or value, but instead reached end of data. Path: $ | LineNumber: 0 | BytePositionInLine: 8.", e.Message);
+            Assert.Contains("$ | LineNumber: 0 | BytePositionInLine: 8.", e.Message);
         }
 
         [Fact]