-JsonReader ReadAsBytes refactor
This commit is contained in:
@@ -6692,20 +6692,20 @@ Path '', line 1, position 1.");
|
||||
serializer.TypeNameHandling = TypeNameHandling.All;
|
||||
|
||||
byte[] objectBytes;
|
||||
using (MemoryStream bsonStream = new MemoryStream())
|
||||
using (JsonWriter bsonWriter = new JsonTextWriter(new StreamWriter(bsonStream)))
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
using (JsonWriter jsonWriter = new JsonTextWriter(new StreamWriter(stream)))
|
||||
{
|
||||
serializer.Serialize(bsonWriter, test);
|
||||
bsonWriter.Flush();
|
||||
serializer.Serialize(jsonWriter, test);
|
||||
jsonWriter.Flush();
|
||||
|
||||
objectBytes = bsonStream.ToArray();
|
||||
objectBytes = stream.ToArray();
|
||||
}
|
||||
|
||||
using (MemoryStream bsonStream = new MemoryStream(objectBytes))
|
||||
using (JsonReader bsonReader = new JsonTextReader(new StreamReader(bsonStream)))
|
||||
using (MemoryStream stream = new MemoryStream(objectBytes))
|
||||
using (JsonReader jsonReader = new JsonTextReader(new StreamReader(stream)))
|
||||
{
|
||||
// Get exception here
|
||||
TestObject newObject = (TestObject)serializer.Deserialize(bsonReader);
|
||||
TestObject newObject = (TestObject)serializer.Deserialize(jsonReader);
|
||||
|
||||
Assert.AreEqual("Test", newObject.Name);
|
||||
CollectionAssert.AreEquivalent(new byte[] { 72, 63, 62, 71, 92, 55 }, newObject.Data);
|
||||
@@ -6964,7 +6964,7 @@ Path '', line 1, position 1.");
|
||||
}";
|
||||
|
||||
JsonConvert.DeserializeObject<TestObjects.MyClass>(json);
|
||||
}, "Unexpected character encountered while parsing value: t. Path 'PreProperty', line 2, position 17.");
|
||||
}, "Unexpected character encountered while parsing value: t. Path 'PreProperty', line 2, position 18.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -522,7 +522,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InfiniteLoopArrayHandling()
|
||||
public void ArrayHandling()
|
||||
{
|
||||
IList<string> errors = new List<string>();
|
||||
|
||||
@@ -538,16 +538,17 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
});
|
||||
|
||||
Assert.IsNull(o);
|
||||
Assert.IsNotNull(o);
|
||||
|
||||
Assert.AreEqual(3, errors.Count);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path '[0]', line 1, position 3.", errors[0]);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path '[0]', line 1, position 3.", errors[1]);
|
||||
Assert.AreEqual("Infinite loop detected from error handling. Path '[0]', line 1, position 3.", errors[2]);
|
||||
Assert.AreEqual(1, errors.Count);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path '[0]', line 1, position 4.", errors[0]);
|
||||
|
||||
Assert.AreEqual(1, ((int[])o).Length);
|
||||
Assert.AreEqual(0, ((int[])o)[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InfiniteLoopArrayHandlingInObject()
|
||||
public void ArrayHandlingInObject()
|
||||
{
|
||||
IList<string> errors = new List<string>();
|
||||
|
||||
@@ -563,13 +564,16 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
});
|
||||
|
||||
Assert.IsNull(o);
|
||||
Assert.IsNotNull(o);
|
||||
|
||||
Assert.AreEqual(4, errors.Count);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path 'badarray[0]', line 1, position 15.", errors[0]);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path 'badarray[0]', line 1, position 15.", errors[1]);
|
||||
Assert.AreEqual("Infinite loop detected from error handling. Path 'badarray[0]', line 1, position 15.", errors[2]);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path 'badarray[0]', line 1, position 15.", errors[3]);
|
||||
Assert.AreEqual(2, errors.Count);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: x. Path 'badarray[0]', line 1, position 16.", errors[0]);
|
||||
Assert.AreEqual("Unexpected character encountered while parsing value: ,. Path 'badarray[1]', line 1, position 17.", errors[1]);
|
||||
|
||||
Assert.AreEqual(2, o.Count);
|
||||
Assert.AreEqual(2, o["badarray"].Length);
|
||||
Assert.AreEqual(0, o["badarray"][0]);
|
||||
Assert.AreEqual(2, o["badarray"][1]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user