-Added AutoCompleteOnClose to JsonWriter to control whether JSON is auto-completed on JsonWriter.Close
This commit is contained in:
@@ -882,6 +882,63 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
Assert.IsNull(reader.ReadAsBytes());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteEndOnProperty()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BsonWriter writer = new BsonWriter(ms);
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
writer.WriteEnd();
|
||||
|
||||
Assert.AreEqual("0B-00-00-00-0A-42-6C-61-68-00-00", (BitConverter.ToString(ms.ToArray())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteEndOnProperty_Close()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BsonWriter writer = new BsonWriter(ms);
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
writer.Close();
|
||||
|
||||
Assert.AreEqual("0B-00-00-00-0A-42-6C-61-68-00-00", (BitConverter.ToString(ms.ToArray())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteEndOnProperty_Dispose()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
using (BsonWriter writer = new BsonWriter(ms))
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
}
|
||||
|
||||
Assert.AreEqual("0B-00-00-00-0A-42-6C-61-68-00-00", (BitConverter.ToString(ms.ToArray())));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AutoCompleteOnClose_False()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
using (BsonWriter writer = new BsonWriter(ms))
|
||||
{
|
||||
writer.AutoCompleteOnClose = false;
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
// nothing is written because a BSON document needs to be completed before it can be written
|
||||
Assert.AreEqual(string.Empty, (BitConverter.ToString(ms.ToArray())));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1310,6 +1310,51 @@ _____'propertyName': NaN,
|
||||
Assert.AreEqual("{'Blah':null}", sw.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteEndOnProperty_Close()
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
JsonTextWriter writer = new JsonTextWriter(sw);
|
||||
writer.QuoteChar = '\'';
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
writer.Close();
|
||||
|
||||
Assert.AreEqual("{'Blah':null}", sw.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteEndOnProperty_Dispose()
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
using (JsonTextWriter writer = new JsonTextWriter(sw))
|
||||
{
|
||||
writer.QuoteChar = '\'';
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
}
|
||||
|
||||
Assert.AreEqual("{'Blah':null}", sw.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AutoCompleteOnClose_False()
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
using (JsonTextWriter writer = new JsonTextWriter(sw))
|
||||
{
|
||||
writer.AutoCompleteOnClose = false;
|
||||
writer.QuoteChar = '\'';
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("Blah");
|
||||
}
|
||||
|
||||
Assert.AreEqual("{'Blah':", sw.ToString());
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void QuoteChar()
|
||||
|
||||
Reference in New Issue
Block a user