This commit is contained in:
James Newton-King
2015-12-26 18:01:24 +13:00
parent 3773eb5be7
commit dc07e59b0b
2 changed files with 41 additions and 0 deletions
@@ -47,6 +47,7 @@ using Assert = Newtonsoft.Json.Tests.XUnitAssert;
using NUnit.Framework;
#endif
using System.IO;
using Newtonsoft.Json.Linq;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;
namespace Newtonsoft.Json.Tests.Serialization
@@ -547,6 +548,32 @@ namespace Newtonsoft.Json.Tests.Serialization
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]
public void ArrayHandlingInObject()
{