-Tests
This commit is contained in:
@@ -3395,6 +3395,20 @@ null//comment
|
|||||||
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReadAsBytes()
|
||||||
|
{
|
||||||
|
byte[] data = Encoding.UTF8.GetBytes("Hello world");
|
||||||
|
|
||||||
|
string json = @"""" + Convert.ToBase64String(data) + @"""";
|
||||||
|
|
||||||
|
JsonTextReader reader = new JsonTextReader(new StringReader(json));
|
||||||
|
|
||||||
|
byte[] result = reader.ReadAsBytes();
|
||||||
|
|
||||||
|
CollectionAssert.AreEquivalent(data, result);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void UnexpectedEndTokenWhenParsingOddEndToken()
|
public void UnexpectedEndTokenWhenParsingOddEndToken()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ using Assert = Newtonsoft.Json.Tests.XUnitAssert;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
#endif
|
#endif
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
|
||||||
|
|
||||||
namespace Newtonsoft.Json.Tests.Serialization
|
namespace Newtonsoft.Json.Tests.Serialization
|
||||||
@@ -547,6 +548,32 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
Assert.AreEqual(0, ((int[])o)[0]);
|
Assert.AreEqual(0, ((int[])o)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ArrayHandling_JTokenReader()
|
||||||
|
{
|
||||||
|
IList<string> errors = new List<string>();
|
||||||
|
|
||||||
|
JTokenReader reader = new JTokenReader(new JArray(0, true));
|
||||||
|
|
||||||
|
JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Error = (sender, arg) =>
|
||||||
|
{
|
||||||
|
errors.Add(arg.ErrorContext.Error.Message);
|
||||||
|
arg.ErrorContext.Handled = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
object o = serializer.Deserialize(reader, typeof(int[]));
|
||||||
|
|
||||||
|
Assert.IsNotNull(o);
|
||||||
|
|
||||||
|
Assert.AreEqual(1, errors.Count);
|
||||||
|
Assert.AreEqual("Error reading integer. Unexpected token: Boolean. Path '[1]'.", errors[0]);
|
||||||
|
|
||||||
|
Assert.AreEqual(1, ((int[])o).Length);
|
||||||
|
Assert.AreEqual(0, ((int[])o)[0]);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ArrayHandlingInObject()
|
public void ArrayHandlingInObject()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user