Add more Utf8JsonWriter.WritePropertyName test cases. (dotnet/corefx#38921)
authorAhson Khan <ahkha@microsoft.com>
Wed, 26 Jun 2019 13:57:12 +0000 (06:57 -0700)
committerGitHub <noreply@github.com>
Wed, 26 Jun 2019 13:57:12 +0000 (06:57 -0700)
* Revert "Fix build break for TestHelpers, move to common and rename to MemoryTestHelpers"

This reverts commit dotnet/corefx@61f9b4c44336a7e32f8679e0a186a9177d384c49.

* Add more Utf8JsonWriter.WritePropertyName test cases.

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

src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs

index 867061c..fd5581e 100644 (file)
@@ -1155,6 +1155,54 @@ namespace System.Text.Json.Tests
             {
                 Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
             }
+
+            jsonUtf8 = new Utf8JsonWriter(output, options);
+            jsonUtf8.WriteStartObject();
+            jsonUtf8.WritePropertyName("first name");
+            if (skipValidation)
+            {
+                jsonUtf8.WriteString("another property name", "some value");
+            }
+            else
+            {
+                Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString("another property name", "some value"));
+            }
+
+            jsonUtf8 = new Utf8JsonWriter(output, options);
+            jsonUtf8.WriteStartObject();
+            jsonUtf8.WritePropertyName("first name");
+            if (skipValidation)
+            {
+                jsonUtf8.WriteNumber("another property name", 12345);
+            }
+            else
+            {
+                Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumber("another property name", 12345));
+            }
+
+            jsonUtf8 = new Utf8JsonWriter(output, options);
+            jsonUtf8.WriteStartObject();
+            jsonUtf8.WritePropertyName("first name");
+            if (skipValidation)
+            {
+                jsonUtf8.WriteNull("another property name");
+            }
+            else
+            {
+                Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNull("another property name"));
+            }
+
+            jsonUtf8 = new Utf8JsonWriter(output, options);
+            jsonUtf8.WriteStartObject();
+            jsonUtf8.WritePropertyName("first name");
+            if (skipValidation)
+            {
+                jsonUtf8.WriteBoolean("another property name", true);
+            }
+            else
+            {
+                Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteBoolean("another property name", true));
+            }
         }
 
         [Theory]