Fix WriteLargeKeyOrValue System.Text.Json test (dotnet/corefx#39857)
authorStephen Toub <stoub@microsoft.com>
Mon, 29 Jul 2019 20:10:36 +0000 (16:10 -0400)
committerGitHub <noreply@github.com>
Mon, 29 Jul 2019 20:10:36 +0000 (16:10 -0400)
When the Utf8JsonWriter is disposed in the first part of the test, it flushes the WriteStartObject token to the ArrayBufferWriter, such that the output.WrittenCount is already 1 when the second part of the test starts, and then the Assert.Equal(0, output.WrittenCount) is doomed to fail.

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

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

index 17d0fd0..5574cbf 100644 (file)
@@ -4980,9 +4980,9 @@ namespace System.Text.Json.Tests
             value.AsSpan().Fill((byte)'b');
 
             var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
-            var output = new ArrayBufferWriter<byte>(1024);
 
             {
+                var output = new ArrayBufferWriter<byte>(1024);
                 using var jsonUtf8 = new Utf8JsonWriter(output, options);
                 jsonUtf8.WriteStartObject();
                 Assert.Throws<ArgumentException>(() => jsonUtf8.WriteString(key, DateTime.Now));
@@ -4990,6 +4990,7 @@ namespace System.Text.Json.Tests
             }
 
             {
+                var output = new ArrayBufferWriter<byte>(1024);
                 using var jsonUtf8 = new Utf8JsonWriter(output, options);
                 jsonUtf8.WriteStartArray();
                 Assert.Throws<ArgumentException>(() => jsonUtf8.WriteStringValue(value));