-Fixed unhelpful error when failing conversion in JsonReader.ReadAsInt32

This commit is contained in:
James Newton-King
2018-02-17 18:04:00 +13:00
parent ce7f283b94
commit 73203653ba
4 changed files with 93 additions and 42 deletions
@@ -56,6 +56,16 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests
#endif
public class ReadAsyncTests : TestFixtureBase
{
[Test]
public async Task ReadAsInt32Async_IntegerTooLarge_ThrowsJsonReaderException()
{
JValue token = new JValue(long.MaxValue);
await ExceptionAssert.ThrowsAsync<JsonReaderException>(
() => token.CreateReader().ReadAsInt32Async()
);
}
[Test]
public async Task ReadMissingInt64()
{
@@ -61,6 +61,16 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests
#endif
public class ReadTests : TestFixtureBase
{
[Test]
public void ReadAsInt32_IntegerTooLarge_ThrowsJsonReaderException()
{
JValue token = new JValue(long.MaxValue);
ExceptionAssert.Throws<JsonReaderException>(
() => token.CreateReader().ReadAsInt32()
);
}
[Test]
public void ReadMissingInt64()
{
@@ -971,6 +971,11 @@ namespace Newtonsoft.Json.Tests.Serialization
{
JsonSerializer serializer = new JsonSerializer();
#pragma warning disable CS0618 // Type or member is obsolete
Assert.IsNotNull(serializer.Binder);
#pragma warning restore CS0618 // Type or member is obsolete
Assert.IsNotNull(serializer.SerializationBinder);
DefaultSerializationBinder customBinder = new DefaultSerializationBinder();
#pragma warning disable CS0618 // Type or member is obsolete
serializer.Binder = customBinder;
@@ -1090,6 +1095,11 @@ namespace Newtonsoft.Json.Tests.Serialization
{
JsonSerializerSettings settings = new JsonSerializerSettings();
#pragma warning disable CS0618 // Type or member is obsolete
Assert.IsNull(settings.Binder);
#pragma warning restore CS0618 // Type or member is obsolete
Assert.IsNull(settings.SerializationBinder);
DefaultSerializationBinder customBinder = new DefaultSerializationBinder();
#pragma warning disable CS0618 // Type or member is obsolete
settings.Binder = customBinder;
@@ -1205,6 +1215,11 @@ namespace Newtonsoft.Json.Tests.Serialization
{
JsonSerializerProxy serializerProxy = new JsonSerializerProxy(new JsonSerializerInternalReader(new JsonSerializer()));
#pragma warning disable CS0618 // Type or member is obsolete
Assert.IsNotNull(serializerProxy.Binder);
#pragma warning restore CS0618 // Type or member is obsolete
Assert.IsNotNull(serializerProxy.SerializationBinder);
DefaultSerializationBinder customBinder = new DefaultSerializationBinder();
#pragma warning disable CS0618 // Type or member is obsolete
serializerProxy.Binder = customBinder;