-Increment version to 8.0.2

-Tests
This commit is contained in:
James Newton-King
2016-01-08 21:31:18 +13:00
parent 9021858293
commit 2c5322c302
8 changed files with 140 additions and 66 deletions
@@ -406,7 +406,7 @@ third line", jsonTextReader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
ExceptionAssert.Throws<JsonReaderException>(() => { reader.Read(); }, "Unexpected content while parsing JSON. Path 'u', line 1, position 27.");
ExceptionAssert.Throws<JsonReaderException>(() => { reader.Read(); }, "Unexpected content while parsing JSON. Path 'u', line 1, position 29.");
}
[Test]
@@ -2418,7 +2418,7 @@ new Date()"));
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"nul"));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.Read(); }, "Error parsing null value. Path '', line 0, position 0.");
ExceptionAssert.Throws<JsonReaderException>(() => { reader.Read(); }, "Unexpected end when reading JSON. Path '', line 1, position 3.");
}
[Test]
@@ -2426,7 +2426,7 @@ new Date()"));
{
JsonTextReader reader = new JsonTextReader(new StringReader(@"nulz"));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.Read(); }, "Error parsing null value. Path '', line 0, position 0.");
ExceptionAssert.Throws<JsonReaderException>(() => { reader.Read(); }, "Error parsing null value. Path '', line 1, position 3.");
}
[Test]
@@ -3469,11 +3469,16 @@ null//comment
'TRUE',
'false',
'FALSE',
// comment!
/* comment! */
'',
null
]";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
#if DEBUG
reader.SetCharBuffer(new char[10]);
#endif
Assert.IsTrue(reader.Read());
Assert.AreEqual("", reader.Path);
@@ -3523,14 +3528,86 @@ null//comment
Assert.AreEqual(null, reader.ReadAsBoolean());
Assert.AreEqual("[14]", reader.Path);
Assert.IsTrue(reader.Read());
Assert.AreEqual(null, reader.ReadAsBoolean());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.AreEqual("", reader.Path);
Assert.IsFalse(reader.Read());
Assert.AreEqual(null, reader.ReadAsBoolean());
Assert.AreEqual(JsonToken.None, reader.TokenType);
Assert.AreEqual("", reader.Path);
}
#endif
[Test]
public void ReadAsString_Null_AdditionalBadData()
{
string json = @"nullllll";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsString(); }, "Error parsing null value. Path '', line 1, position 4.");
}
[Test]
public void ReadAsBoolean_AdditionalBadData()
{
string json = @"falseeeee";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBoolean(); }, "Unexpected character encountered while parsing value: e. Path '', line 1, position 5.");
}
[Test]
public void ReadAsString_AdditionalBadData()
{
string json = @"falseeeee";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsString(); }, "Unexpected character encountered while parsing value: e. Path '', line 1, position 5.");
}
[Test]
public void ReadAsBoolean_UnexpectedEnd()
{
string json = @"tru";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsBoolean(); }, "Unexpected end when reading JSON. Path '', line 1, position 3.");
}
[Test]
public void ReadAsDateTime_Boolean()
{
string json = @"true";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsDateTime(); }, "Unexpected character encountered while parsing value: t. Path '', line 1, position 1.");
}
[Test]
public void ReadAsString_UnexpectedEnd()
{
string json = @"tru";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsString(); }, "Unexpected end when reading JSON. Path '', line 1, position 3.");
}
[Test]
public void ReadAsString_Null_UnexpectedEnd()
{
string json = @"nul";
JsonTextReader reader = new JsonTextReader(new StringReader(json));
ExceptionAssert.Throws<JsonReaderException>(() => { reader.ReadAsString(); }, "Unexpected end when reading JSON. Path '', line 1, position 3.");
}
[Test]
public void ReadAsBytes()
{
@@ -530,39 +530,40 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual("AAECAwQFBgcICQ==", (string)o["$value"]);
}
public class ItemWithTypedPayload
public class ItemWithUntypedPayload
{
public float Payload { get; set; }
public object Payload { get; set; }
}
[Test]
public void PrimitiveType_MetadataPropertyIgnore_WithType()
public void PrimitiveType_MetadataPropertyIgnore_WithNoType()
{
ItemWithTypedPayload actual = JsonConvert.DeserializeObject<ItemWithTypedPayload>(@"{
ItemWithUntypedPayload actual = JsonConvert.DeserializeObject<ItemWithUntypedPayload>(@"{
""Payload"": {
""$type"": ""System.Single, mscorlib"",
""$value"": ""5""
}
}",
new JsonSerializerSettings());
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto
});
Assert.AreEqual(5f, actual.Payload);
ExceptionAssert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<ItemWithTypedPayload>(@"{
actual = JsonConvert.DeserializeObject<ItemWithUntypedPayload>(@"{
""Payload"": {
""$type"": ""System.Single, mscorlib"",
""$value"": ""5""
}
}",
new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore
});
}, @"Cannot deserialize the current JSON object (e.g. {""name"":""value""}) into type 'System.Single' because the type requires a JSON primitive value (e.g. string, number, boolean, null) to deserialize correctly.
To fix this error either change the JSON to a JSON primitive value (e.g. string, number, boolean, null) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'Payload.$type', line 3, position 12.");
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Auto,
MetadataPropertyHandling = MetadataPropertyHandling.Ignore
});
Assert.IsTrue(actual.Payload is JObject);
}
[Test]
@@ -186,7 +186,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public void NestedValueObjects()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++)
for (int i = 0; i < 3; i++)
{
sb.Append(@"{""$value"":");
}
@@ -196,7 +196,7 @@ namespace Newtonsoft.Json.Tests.Serialization
var reader = new JsonTextReader(new StringReader(sb.ToString()));
var ser = new JsonSerializer();
ser.MetadataPropertyHandling = MetadataPropertyHandling.Default;
ser.Deserialize<float>(reader);
ser.Deserialize<sbyte>(reader);
}, "Unexpected token when deserializing primitive value: StartObject. Path '$value', line 1, position 11.");
}