var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var stream = new MemoryStream();
- var writer = new Utf8JsonWriter(stream, options);
- Assert.Equal(0, writer.BytesCommitted);
- Assert.Equal(0, writer.BytesPending);
- Assert.Equal(0, writer.CurrentDepth);
- Assert.Null(writer.Options.Encoder);
- Assert.Equal(formatted, writer.Options.Indented);
- Assert.Equal(skipValidation, writer.Options.SkipValidation);
- Assert.Equal(0, stream.Position);
+ using (var writer = new Utf8JsonWriter(stream, options))
+ {
+ Assert.Equal(0, writer.BytesCommitted);
+ Assert.Equal(0, writer.BytesPending);
+ Assert.Equal(0, writer.CurrentDepth);
+ Assert.Null(writer.Options.Encoder);
+ Assert.Equal(formatted, writer.Options.Indented);
+ Assert.Equal(skipValidation, writer.Options.SkipValidation);
+ Assert.Equal(0, stream.Position);
+ }
var output = new FixedSizedBufferWriter(0);
- writer = new Utf8JsonWriter(output, options);
- Assert.Equal(0, writer.BytesCommitted);
- Assert.Equal(0, writer.BytesPending);
- Assert.Equal(0, writer.CurrentDepth);
- Assert.Null(writer.Options.Encoder);
- Assert.Equal(formatted, writer.Options.Indented);
- Assert.Equal(skipValidation, writer.Options.SkipValidation);
- Assert.Equal(0, output.FormattedCount);
+ using (var writer = new Utf8JsonWriter(output, options))
+ {
+ Assert.Equal(0, writer.BytesCommitted);
+ Assert.Equal(0, writer.BytesPending);
+ Assert.Equal(0, writer.CurrentDepth);
+ Assert.Null(writer.Options.Encoder);
+ Assert.Equal(formatted, writer.Options.Indented);
+ Assert.Equal(skipValidation, writer.Options.SkipValidation);
+ Assert.Equal(0, output.FormattedCount);
+ }
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteNumberValue(1);
writeToStream.Flush();
Assert.Equal(previousWritten, stream.Position);
var output = new FixedSizedBufferWriter(256);
- var writeToIBW = new Utf8JsonWriter(output, options);
+ using var writeToIBW = new Utf8JsonWriter(output, options);
writeToIBW.WriteNumberValue(1);
writeToIBW.Flush();
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteNumberValue(1);
writeToStream.Flush();
Assert.Equal("11", Encoding.UTF8.GetString(stream.ToArray()));
var output = new FixedSizedBufferWriter(257);
- var writeToIBW = new Utf8JsonWriter(output, options);
+ using var writeToIBW = new Utf8JsonWriter(output, options);
writeToIBW.WriteNumberValue(1);
writeToIBW.Flush();
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteNumberValue(1);
writeToStream.Flush();
Assert.True(output.FormattedCount != 0);
output = new FixedSizedBufferWriter(256);
- var writeToIBW = new Utf8JsonWriter(output, options);
+ using var writeToIBW = new Utf8JsonWriter(output, options);
writeToIBW.WriteNumberValue(1);
writeToIBW.Flush();
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
Assert.Throws<ArgumentNullException>(() => writeToStream.Reset((Stream)null));
Assert.Throws<ArgumentNullException>(() => writeToStream.Reset((IBufferWriter<byte>)null));
Assert.Throws<ArgumentException>(() => writeToStream.Reset(stream));
var output = new FixedSizedBufferWriter(256);
- var writeToIBW = new Utf8JsonWriter(output, options);
+ using var writeToIBW = new Utf8JsonWriter(output, options);
Assert.Throws<ArgumentNullException>(() => writeToIBW.Reset((Stream)null));
Assert.Throws<ArgumentNullException>(() => writeToIBW.Reset((IBufferWriter<byte>)null));
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(0);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.Flush();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(0, output.FormattedCount);
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.Flush();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(0, stream.Position);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(0);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
await jsonUtf8.FlushAsync();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(0, output.FormattedCount);
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
await writeToStream.FlushAsync();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(0, stream.Position);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(256);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(2, output.FormattedCount);
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteStartObject();
writeToStream.WriteEndObject();
Assert.Equal(0, writeToStream.BytesCommitted);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(256);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(2, output.FormattedCount);
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteStartObject();
writeToStream.WriteEndObject();
Assert.Equal(0, writeToStream.BytesCommitted);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(256);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(2, output.FormattedCount);
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteStartObject();
writeToStream.WriteEndObject();
Assert.Equal(0, writeToStream.BytesCommitted);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(256);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(2, output.FormattedCount);
var stream = new MemoryStream();
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteStartObject();
writeToStream.WriteEndObject();
Assert.Equal(0, writeToStream.BytesCommitted);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(256);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(1, jsonUtf8.BytesPending);
var stream = new MemoryStream();
Assert.Throws<ObjectDisposedException>(() => jsonUtf8.Reset(stream));
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteStartObject();
Assert.Equal(0, writeToStream.BytesCommitted);
Assert.Equal(1, writeToStream.BytesPending);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new FixedSizedBufferWriter(256);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
Assert.Equal(0, jsonUtf8.BytesCommitted);
Assert.Equal(1, jsonUtf8.BytesPending);
var stream = new MemoryStream();
Assert.Throws<ObjectDisposedException>(() => jsonUtf8.Reset(stream));
- var writeToStream = new Utf8JsonWriter(stream, options);
+ using var writeToStream = new Utf8JsonWriter(stream, options);
writeToStream.WriteStartObject();
Assert.Equal(0, writeToStream.BytesCommitted);
Assert.Equal(1, writeToStream.BytesPending);
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new InvalidBufferWriter();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumberValue((ulong)12345678901));
}
byte[] utf8String = Encoding.UTF8.GetBytes(new string('a', 215));
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
Guid guid = Guid.NewGuid();
-
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue(guid));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.Flush();
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue(guid));
+ }
sizeTooSmall += formatted ? 9 : 1;
output = new FixedSizedBufferWriter(sizeTooSmall);
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
- jsonUtf8.WriteStringValue(guid);
- jsonUtf8.Flush();
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.WriteStringValue(guid);
+ jsonUtf8.Flush();
+ }
string actualStr = Encoding.UTF8.GetString(output.Formatted);
if (!formatted)
byte[] utf8String = Encoding.UTF8.GetBytes(new string('a', 232));
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
var date = new DateTime(2019, 1, 1);
-
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue(date));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.Flush();
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue(date));
+ }
sizeTooSmall += formatted ? 23 : 15;
output = new FixedSizedBufferWriter(sizeTooSmall);
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
- jsonUtf8.WriteStringValue(date);
- jsonUtf8.Flush();
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.WriteStringValue(date);
+ jsonUtf8.Flush();
+ }
string actualStr = Encoding.UTF8.GetString(output.Formatted);
if (!formatted)
byte[] utf8String = Encoding.UTF8.GetBytes(new string('a', 226));
- var jsonUtf8 = new Utf8JsonWriter(output, options);
DateTimeOffset date = new DateTime(2019, 1, 1);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
-
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue(date));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.Flush();
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue(date));
+ }
sizeTooSmall += formatted ? 23 : 15;
output = new FixedSizedBufferWriter(sizeTooSmall);
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
- jsonUtf8.WriteStringValue(date);
- jsonUtf8.Flush();
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.WriteStringValue(date);
+ jsonUtf8.Flush();
+ }
string actualStr = Encoding.UTF8.GetString(output.Formatted);
if (!formatted)
var output = new FixedSizedBufferWriter(256);
decimal value = JsonTestHelper.NextDecimal(random, 78E14, -78E14);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteNumberValue(value);
jsonUtf8.Flush();
{
var output = new FixedSizedBufferWriter(256);
decimal value = JsonTestHelper.NextDecimal(random, 1_000_000, -1_000_000);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteNumberValue(value);
jsonUtf8.Flush();
{
var output = new FixedSizedBufferWriter(256);
decimal value = 9999999999999999999999999999m;
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteNumberValue(value);
jsonUtf8.Flush();
{
var output = new FixedSizedBufferWriter(256);
decimal value = -9999999999999999999999999999m;
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteNumberValue(value);
jsonUtf8.Flush();
}
{
-
int sizeTooSmall = 256;
var output = new FixedSizedBufferWriter(sizeTooSmall);
byte[] utf8String = Encoding.UTF8.GetBytes(new string('a', 222));
decimal value = -0.9999999999999999999999999999m;
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumberValue(value));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.Flush();
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumberValue(value));
+ }
sizeTooSmall += formatted ? 9 : 1;
output = new FixedSizedBufferWriter(sizeTooSmall);
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStringValue(utf8String);
- jsonUtf8.WriteNumberValue(value);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStringValue(utf8String);
+ jsonUtf8.WriteNumberValue(value);
- jsonUtf8.Flush();
+ jsonUtf8.Flush();
+ }
string actualStr = Encoding.UTF8.GetString(output.Formatted);
if (!formatted)
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- if (skipValidation)
- {
- jsonUtf8.WriteEndArray();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- if (skipValidation)
- {
- jsonUtf8.WriteEndObject();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- if (skipValidation)
- {
- jsonUtf8.WriteStartArray("property at start");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("property at start"));
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartArray("property at start");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("property at start"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- if (skipValidation)
- {
- jsonUtf8.WriteStartObject("property at start");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("property at start"));
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartObject("property at start");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("property at start"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- if (skipValidation)
- {
- jsonUtf8.WriteStartArray("property inside array");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("property inside array"));
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartArray("property inside array");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("property inside array"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
jsonUtf8.WriteStartObject();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- if (skipValidation)
- {
- jsonUtf8.WriteEndObject();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- if (skipValidation)
- {
- jsonUtf8.WriteStringValue("key");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue("key"));
+ jsonUtf8.WriteStartObject();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStringValue("key");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStringValue("key"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- if (skipValidation)
- {
- jsonUtf8.WriteString("key", "value");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString("key", "value"));
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteString("key", "value");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString("key", "value"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- if (skipValidation)
- {
- jsonUtf8.WriteString(JsonEncodedText.Encode("key"), JsonEncodedText.Encode("value"));
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString(JsonEncodedText.Encode("key"), JsonEncodedText.Encode("value")));
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteString(JsonEncodedText.Encode("key"), JsonEncodedText.Encode("value"));
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString(JsonEncodedText.Encode("key"), JsonEncodedText.Encode("value")));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- jsonUtf8.WriteEndArray();
+ jsonUtf8.WriteStartObject();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- else
+
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ jsonUtf8.WriteStartObject();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
jsonUtf8.WriteStartArray();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray());
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteEndArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteEndArray();
- if (skipValidation)
- {
- jsonUtf8.WriteEndObject();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
- }
-
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteStartObject("some object");
- jsonUtf8.WriteEndObject();
- if (skipValidation)
- {
- jsonUtf8.WriteEndArray();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
- }
-
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
+ jsonUtf8.WriteStartObject();
jsonUtf8.WriteStartObject("some object");
jsonUtf8.WriteEndObject();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- else
+
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("some object"));
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartObject("some object");
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("some object"));
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteStartArray("test array");
- jsonUtf8.WriteEndArray();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WriteStartArray("test array");
jsonUtf8.WriteEndArray();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteEndArray();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
+ jsonUtf8.WriteStartArray();
jsonUtf8.WriteEndArray();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteEndObject();
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
+ jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStartArray();
- if (skipValidation)
- {
- jsonUtf8.WriteEndObject();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteStartObject("test object");
- if (skipValidation)
- {
- jsonUtf8.WriteEndArray();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WriteStartObject("test object");
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- if (skipValidation)
- {
- jsonUtf8.WritePropertyName("test name");
- jsonUtf8.WritePropertyName(JsonEncodedText.Encode("test name"));
- jsonUtf8.WritePropertyName("test name".AsSpan());
- jsonUtf8.WritePropertyName(Encoding.UTF8.GetBytes("test name"));
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName(JsonEncodedText.Encode("test name")));
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name".AsSpan()));
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName(Encoding.UTF8.GetBytes("test name")));
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ jsonUtf8.WritePropertyName(JsonEncodedText.Encode("test name"));
+ jsonUtf8.WritePropertyName("test name".AsSpan());
+ jsonUtf8.WritePropertyName(Encoding.UTF8.GetBytes("test name"));
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName(JsonEncodedText.Encode("test name")));
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name".AsSpan()));
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName(Encoding.UTF8.GetBytes("test name")));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- if (skipValidation)
- {
- jsonUtf8.WritePropertyName("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ jsonUtf8.WriteStartArray();
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WritePropertyName("first name");
- if (skipValidation)
- {
- jsonUtf8.WritePropertyName("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WritePropertyName("first name");
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WritePropertyName("first name");
- if (skipValidation)
- {
- jsonUtf8.WriteStartArray("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("test name"));
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WritePropertyName("first name");
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartArray("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("test name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WritePropertyName("first name");
- if (skipValidation)
- {
- jsonUtf8.WriteStartObject("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("test name"));
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WritePropertyName("first name");
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartObject("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("test name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WritePropertyName("first name");
- if (skipValidation)
- {
- jsonUtf8.WriteEndObject();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WritePropertyName("first name");
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ 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
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString("another property name", "some value"));
+ 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
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumber("another property name", 12345));
+ 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
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNull("another property name"));
+ 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
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteBoolean("another property name", true));
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WritePropertyName("first name");
+ if (skipValidation)
+ {
+ jsonUtf8.WriteBoolean("another property name", true);
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteBoolean("another property name", true));
+ }
}
}
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- Assert.True(jsonUtf8.CurrentDepth != 0);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ Assert.True(jsonUtf8.CurrentDepth != 0);
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.True(jsonUtf8.CurrentDepth != 0);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.True(jsonUtf8.CurrentDepth != 0);
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteEndArray();
- Assert.True(jsonUtf8.CurrentDepth != 0);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteEndArray();
+ Assert.True(jsonUtf8.CurrentDepth != 0);
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteStartObject("some object");
- Assert.True(jsonUtf8.CurrentDepth != 0);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WriteStartObject("some object");
+ Assert.True(jsonUtf8.CurrentDepth != 0);
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartArray();
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteEndObject();
- Assert.True(jsonUtf8.CurrentDepth != 0);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartArray();
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WriteEndObject();
+ Assert.True(jsonUtf8.CurrentDepth != 0);
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- jsonUtf8.WriteStartArray("test array");
- jsonUtf8.WriteEndArray();
- Assert.True(jsonUtf8.CurrentDepth != 0);
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ jsonUtf8.WriteStartArray("test array");
+ jsonUtf8.WriteEndArray();
+ Assert.True(jsonUtf8.CurrentDepth != 0);
+ }
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
jsonUtf8.WriteNumberValue(12345);
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumberValue(12345));
- }
-
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteStartArray();
- }
- else
- {
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray());
+ if (skipValidation)
+ {
+ jsonUtf8.WriteNumberValue(12345);
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteNumberValue(12345));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteStartObject();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject());
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteStartArray("property name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("property name"));
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteStartObject("property name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("property name"));
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartArray("property name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("property name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteString("property name", "value");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString("property name", "value"));
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteStartObject("property name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartObject("property name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteString(JsonEncodedText.Encode("property name"), JsonEncodedText.Encode("value"));
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString(JsonEncodedText.Encode("property name"), JsonEncodedText.Encode("value")));
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteString("property name", "value");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString("property name", "value"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteEndArray();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteString(JsonEncodedText.Encode("property name"), JsonEncodedText.Encode("value"));
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteString(JsonEncodedText.Encode("property name"), JsonEncodedText.Encode("value")));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WriteEndObject();
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndArray();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndArray());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNumberValue(12345);
- if (skipValidation)
- {
- jsonUtf8.WritePropertyName("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WriteEndObject();
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteEndObject());
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteBooleanValue(true);
- if (skipValidation)
- {
- jsonUtf8.WritePropertyName("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ jsonUtf8.WriteNumberValue(12345);
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteNullValue();
- if (skipValidation)
- {
- jsonUtf8.WritePropertyName("test name");
- }
- else
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ jsonUtf8.WriteBooleanValue(true);
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ }
}
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStringValue("some string");
- if (skipValidation)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- jsonUtf8.WritePropertyName("test name");
+ jsonUtf8.WriteNullValue();
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ }
}
- else
+
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ jsonUtf8.WriteStringValue("some string");
+ if (skipValidation)
+ {
+ jsonUtf8.WritePropertyName("test name");
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WritePropertyName("test name"));
+ }
}
}
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(double.NegativeInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(double.NegativeInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(double.PositiveInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(double.PositiveInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(double.NaN));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(double.NaN));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(float.PositiveInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(float.PositiveInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(float.NegativeInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(float.NegativeInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(float.NaN));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumberValue(float.NaN));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", double.NegativeInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", double.NegativeInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", double.PositiveInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", double.PositiveInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", double.NaN));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", double.NaN));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", float.PositiveInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", float.PositiveInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", float.NegativeInfinity));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", float.NegativeInfinity));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", float.NaN));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteNumber("name", float.NaN));
+ }
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = true };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
for (int i = 0; i < 100; i++)
{
sb.Append(Environment.NewLine);
sb.Append("[]");
- AssertContents(sb.ToString(), output);
+ JsonTestHelper.AssertContents(sb.ToString(), output);
}
[Theory]
string expectedStr = stringWriter.ToString();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WritePropertyName(Encoding.UTF8.GetBytes("foo1"));
jsonUtf8.WriteStringValue("bar1");
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
for (int i = 0; i < 1000; i++)
{
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- for (int i = 0; i < 999; i++)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- jsonUtf8.WriteStartObject("name");
+ jsonUtf8.WriteStartObject();
+ for (int i = 0; i < 999; i++)
+ {
+ jsonUtf8.WriteStartObject("name");
+ }
+ Assert.Equal(1000, jsonUtf8.CurrentDepth);
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("name"));
}
- Assert.Equal(1000, jsonUtf8.CurrentDepth);
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray("name"));
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- for (int i = 0; i < 999; i++)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- jsonUtf8.WriteStartObject(Encoding.UTF8.GetBytes("name"));
+ jsonUtf8.WriteStartObject();
+ for (int i = 0; i < 999; i++)
+ {
+ jsonUtf8.WriteStartObject(Encoding.UTF8.GetBytes("name"));
+ }
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray(Encoding.UTF8.GetBytes("name")));
}
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray(Encoding.UTF8.GetBytes("name")));
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- for (int i = 0; i < 999; i++)
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
{
- jsonUtf8.WriteStartObject(JsonEncodedText.Encode("name"));
+ jsonUtf8.WriteStartObject();
+ for (int i = 0; i < 999; i++)
+ {
+ jsonUtf8.WriteStartObject(JsonEncodedText.Encode("name"));
+ }
+ Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray(JsonEncodedText.Encode("name")));
}
- Assert.Throws<InvalidOperationException>(() => jsonUtf8.WriteStartArray(JsonEncodedText.Encode("name")));
}
// NOTE: WritingTooLargeProperty test is constrained to run on Windows and MacOSX because it causes
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteStartArray(keyChars));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteStartArray(keyChars));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteStartArray(key));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteStartArray(key));
+ }
}
// NOTE: WritingTooLargePropertyStandalone test is constrained to run on Windows and MacOSX because it causes
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WritePropertyName(keyChars));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WritePropertyName(keyChars));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WritePropertyName(key));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WritePropertyName(key));
+ }
}
[ConditionalTheory(nameof(IsX64))]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64StringValue(value));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64StringValue(value));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String("foo", value));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String("foo", value));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String(Encoding.UTF8.GetBytes("foo"), value));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String(Encoding.UTF8.GetBytes("foo"), value));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String("foo".AsSpan(), value));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String("foo".AsSpan(), value));
+ }
- jsonUtf8 = new Utf8JsonWriter(output, options);
- jsonUtf8.WriteStartObject();
- Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String(JsonEncodedText.Encode("foo"), value));
+ using (var jsonUtf8 = new Utf8JsonWriter(output, options))
+ {
+ jsonUtf8.WriteStartObject();
+ Assert.Throws<ArgumentException>(() => jsonUtf8.WriteBase64String(JsonEncodedText.Encode("foo"), value));
+ }
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteNumberValue(123456789012345);
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
for (int i = 0; i < 32; i++)
{
var output = new ArrayBufferWriter<byte>(32);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 32; i++)
{
var output = new ArrayBufferWriter<byte>(32);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
// Verify that escaping does not change the input strings/spans.
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(10);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
for (int i = 0; i < 4; i++)
{
var output = new ArrayBufferWriter<byte>(32);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
// Verify that escaping does not change the input strings/spans.
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(10);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
{
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(10);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.Flush();
- AssertContents("\"++++\"", output);
+ JsonTestHelper.AssertContents("\"++++\"", output);
}
[Fact]
builder.Append("ZGRk");
}
builder.Append("ZGQ=\"");
- AssertContents(builder.ToString(), output);
+ JsonTestHelper.AssertContents(builder.ToString(), output);
}
[Theory]
{
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(10);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
{
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(10);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(32);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartArray();
jsonUtf8.WriteEndArray();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(32);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
string comment = "comment is */ invalid";
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(32);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
string comment = "comment is * / valid";
jsonUtf8.WriteCommentValue(comment);
jsonUtf8.WriteCommentValue(invalidUtf8);
string expectedStr = GetCommentExpectedString(prettyPrint: formatted);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
private static string GetCommentExpectedString(bool prettyPrint)
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartArray();
jsonUtf8.WriteEndArray();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 32; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 6; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 6; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 6; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
string WriteProperty(byte[] propertyName, byte[] value)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteString(propertyName, value);
jsonUtf8.WriteEndObject();
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
var validUtf16 = new char[2] { (char)0xD801, (char)0xDC37 }; // 0x10437
var invalidUtf16 = new char[2] { (char)0xD801, 'a' };
for (int i = 0; i < 6; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
{
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(10);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(GetCustomExpectedString(formatted), output);
+ JsonTestHelper.AssertContents(GetCustomExpectedString(formatted), output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartArray();
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndArray();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = true };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartArray();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
{
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = true };
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndArray();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
switch (i)
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 4; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 4; i++)
{
var output = new ArrayBufferWriter<byte>(16);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 4; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int j = 0; j < 3; j++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
ReadOnlySpan<char> keyUtf16 = keyString.AsSpan();
ReadOnlySpan<byte> keyUtf8 = Encoding.UTF8.GetBytes(keyString);
jsonUtf8.Flush();
// TODO: The output doesn't match what JSON.NET does (different rounding/e-notation).
- // AssertContents(expectedStr, output);
+ // JsonTestHelper.AssertContents(expectedStr, output);
}
}
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
[Theory]
var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
var output = new ArrayBufferWriter<byte>();
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
int numberOfElements = 0;
jsonUtf8.WriteStartArray();
jsonUtf8.Flush();
string expectedStr = GetNumbersExpectedString(formatted, numberOfElements);
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
+ }
+
+ [Theory]
+ [InlineData(true, true, "message", true)]
+ [InlineData(true, false, "message", true)]
+ [InlineData(false, true, "message", true)]
+ [InlineData(false, false, "message", true)]
+ [InlineData(true, true, "mess><age", false)]
+ [InlineData(true, false, "mess><age", false)]
+ [InlineData(false, true, "mess><age", false)]
+ [InlineData(false, false, "mess><age", false)]
+ [InlineData(true, true, ">><++>>>\">>\\>>&>>>\u6f22\u5B57>>>", false)] // \u6f22 = 汉, \u5B57 = å—
+ [InlineData(true, false, ">><++>>>\">>\\>>&>>>\u6f22\u5B57>>>", false)]
+ [InlineData(false, true, ">><++>>>\">>\\>>&>>>\u6f22\u5B57>>>", false)]
+ [InlineData(false, false, ">><++>>>\">>\\>>&>>>\u6f22\u5B57>>>", false)]
+ [InlineData(true, true, "mess\r\nage\u0008\u0001!", true)]
+ [InlineData(true, false, "mess\r\nage\u0008\u0001!", true)]
+ [InlineData(false, true, "mess\r\nage\u0008\u0001!", true)]
+ [InlineData(false, false, "mess\r\nage\u0008\u0001!", true)]
+ public void WriteStringsWithRelaxedEscaping(bool formatted, bool skipValidation, string keyString, bool matchesRelaxedEscaping)
+ {
+ string expectedStr = GetExpectedString_RelaxedEscaping(prettyPrint: formatted, keyString);
+
+ var options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
+ WriteStringHelper(options, keyString, expectedStr, shouldMatch: true);
+
+ // Default encoder
+ options = new JsonWriterOptions { Indented = formatted, SkipValidation = skipValidation };
+ WriteStringHelper(options, keyString, expectedStr, matchesRelaxedEscaping);
+ }
+
+ private static void WriteStringHelper(JsonWriterOptions options, string keyString, string expectedStr, bool shouldMatch)
+ {
+ ReadOnlySpan<char> keyUtf16 = keyString.AsSpan();
+ ReadOnlySpan<byte> keyUtf8 = Encoding.UTF8.GetBytes(keyString);
+
+ for (int i = 0; i < 3; i++)
+ {
+ var output = new ArrayBufferWriter<byte>(1024);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
+
+ jsonUtf8.WriteStartObject();
+
+ switch (i)
+ {
+ case 0:
+ jsonUtf8.WriteString(keyString, keyString);
+ jsonUtf8.WriteStartArray(keyString);
+ break;
+ case 1:
+ jsonUtf8.WriteString(keyUtf16, keyString);
+ jsonUtf8.WriteStartArray(keyUtf16);
+ break;
+ case 2:
+ jsonUtf8.WriteString(keyUtf8, keyString);
+ jsonUtf8.WriteStartArray(keyUtf8);
+ break;
+ }
+
+ jsonUtf8.WriteStringValue(keyString);
+ jsonUtf8.WriteStringValue(keyString);
+ jsonUtf8.WriteEndArray();
+
+ jsonUtf8.WriteEndObject();
+ jsonUtf8.Flush();
+
+ if (shouldMatch)
+ {
+ JsonTestHelper.AssertContents(expectedStr, output);
+ }
+ else
+ {
+ JsonTestHelper.AssertContentsNotEqual(expectedStr, output);
+ }
+ }
}
[Theory]
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
for (int i = 0; i < 3; i++)
{
var output = new ArrayBufferWriter<byte>(1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteEndObject();
jsonUtf8.Flush();
- AssertContents(expectedStr, output);
+ JsonTestHelper.AssertContents(expectedStr, output);
}
}
var output = new ArrayBufferWriter<byte>(1024);
{
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
Assert.Throws<ArgumentException>(() => jsonUtf8.WriteString(key, DateTime.Now));
Assert.Equal(0, output.WrittenCount);
}
{
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartArray();
Assert.Throws<ArgumentException>(() => jsonUtf8.WriteStringValue(value));
Assert.Equal(0, output.WrittenCount);
jsonUtf8.WriteStringValue(DateTime.ParseExact(testStr, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind));
jsonUtf8.Flush();
- AssertContents($"\"{expectedStr}\"", output);
+ JsonTestHelper.AssertContents($"\"{expectedStr}\"", output);
}
[Theory]
jsonUtf8.WriteStringValue(DateTimeOffset.ParseExact(testStr, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind));
jsonUtf8.Flush();
- AssertContents($"\"{expectedStr}\"", output);
+ JsonTestHelper.AssertContents($"\"{expectedStr}\"", output);
}
[Fact]
{
// Resizing is too slow, even for outerloop tests, so initialize to a large output size up front.
var output = new ArrayBufferWriter<byte>(noThrow ? 40_000_000 : 1024);
- var jsonUtf8 = new Utf8JsonWriter(output, options);
+ using var jsonUtf8 = new Utf8JsonWriter(output, options);
jsonUtf8.WriteStartObject();
jsonUtf8.WriteStringValue(text);
jsonUtf8.Flush();
- AssertContents($"{expectedMessage}", output);
+ JsonTestHelper.AssertContents($"{expectedMessage}", output);
}
[Theory]
jsonUtf8.WriteStringValue(text);
jsonUtf8.Flush();
- AssertContents(expectedMessage, output);
+ JsonTestHelper.AssertContents(expectedMessage, output);
}
{
var message = new string('>', stringLength);
jsonUtf8.WriteStringValue(text);
jsonUtf8.Flush();
- AssertContents(expectedMessage, output);
+ JsonTestHelper.AssertContents(expectedMessage, output);
}
}
jsonUtf8.WriteStartObject(text);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:{{", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:{{", output);
}
{
jsonUtf8.WriteStartArray(text);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:[", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:[", output);
}
}
jsonUtf8.WriteBoolean(text, true);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:true", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:true", output);
}
{
jsonUtf8.WriteBoolean(text, false);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:false", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:false", output);
}
{
jsonUtf8.WriteNull(text);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:null", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:null", output);
}
}
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
{
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
{
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
{
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
{
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
{
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
{
jsonUtf8.WriteNumber(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:1", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:1", output);
}
}
jsonUtf8.WriteString(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:\"{value.ToString("yyyy-MM-ddTHH:mm:ss")}\"", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:\"{value.ToString("yyyy-MM-ddTHH:mm:ss")}\"", output);
}
{
jsonUtf8.WriteString(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:\"{value.ToString("yyyy-MM-ddTHH:mm:ssK")}\"", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:\"{value.ToString("yyyy-MM-ddTHH:mm:ssK")}\"", output);
}
{
jsonUtf8.WriteString(text, value);
jsonUtf8.Flush();
- AssertContents($"{{{expectedMessage}:\"{value.ToString()}\"", output);
+ JsonTestHelper.AssertContents($"{{{expectedMessage}:\"{value.ToString()}\"", output);
}
}
writer.Flush();
}
- AssertContents("[/**//**/]", output);
+ JsonTestHelper.AssertContents("[/**//**/]", output);
}
[Fact]
writer.Flush();
}
- AssertContents("{}", output);
+ JsonTestHelper.AssertContents("{}", output);
output.Clear();
using (var writer = new Utf8JsonWriter(output))
writer.Flush();
}
- AssertContents($"{{\"\":{wireValue},\"\":{wireValue}}}", output);
+ JsonTestHelper.AssertContents($"{{\"\":{wireValue},\"\":{wireValue}}}", output);
}
private static void WriteNullPropertyName_NoValue(
writer.Flush();
}
- AssertContents("{}", output);
+ JsonTestHelper.AssertContents("{}", output);
output.Clear();
using (var writer = new Utf8JsonWriter(output))
writer.Flush();
}
- AssertContents($"{{\"\":{wireValue},\"\":{wireValue}}}", output);
+ JsonTestHelper.AssertContents($"{{\"\":{wireValue},\"\":{wireValue}}}", output);
}
private static void WriteNullValue_InObject(
writer.Flush();
}
- AssertContents($"{{{nullValue},{wireValue},{wireValue}}}", output);
+ JsonTestHelper.AssertContents($"{{{nullValue},{wireValue},{wireValue}}}", output);
}
private static void WriteNullValue_InArray(
writer.Flush();
}
- AssertContents($"[{nullValue},{wireValue},{wireValue}]", output);
+ JsonTestHelper.AssertContents($"[{nullValue},{wireValue},{wireValue}]", output);
}
private static string GetHelloWorldExpectedString(bool prettyPrint, string propertyName, string value)
return Encoding.UTF8.GetString(ms.ToArray());
}
+ private static string GetExpectedString_RelaxedEscaping(bool prettyPrint, string keyString)
+ {
+ var ms = new MemoryStream();
+ TextWriter streamWriter = new StreamWriter(ms, new UTF8Encoding(false), 1024, true);
+
+ var json = new JsonTextWriter(streamWriter)
+ {
+ Formatting = prettyPrint ? Formatting.Indented : Formatting.None,
+ };
+
+ json.WriteStartObject();
+
+ json.WritePropertyName(keyString, escape: true);
+ json.WriteValue(keyString);
+
+ json.WritePropertyName(keyString, escape: true);
+ json.WriteStartArray();
+ json.WriteValue(keyString);
+ json.WriteValue(keyString);
+ json.WriteEnd();
+
+ json.WriteEnd();
+
+ json.Flush();
+
+ return Encoding.UTF8.GetString(ms.ToArray());
+ }
+
private static string GetGuidsExpectedString(bool prettyPrint, string keyString, Guid[] guids, bool escape = false)
{
var ms = new MemoryStream();
return Encoding.UTF8.GetString(ms.ToArray());
}
- private static void AssertContents(string expectedValue, ArrayBufferWriter<byte> buffer)
- {
- string value = Encoding.UTF8.GetString(
- buffer.WrittenSpan
-#if netfx
- .ToArray()
-#endif
- );
-
- // Temporary hack until we can use the same escape algorithm on both sides and make sure we want uppercase hex.
- Assert.Equal(expectedValue.NormalizeToJsonNetFormat(), value.NormalizeToJsonNetFormat());
- }
-
public static IEnumerable<object[]> JsonEncodedTextStrings
{
get