This commit is contained in:
James Newton-King
2017-08-13 10:44:07 +12:00
parent 946b43fab8
commit 81b0e443ff
65 changed files with 2571 additions and 866 deletions
File diff suppressed because it is too large Load Diff
@@ -62,6 +62,66 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class TypeNameHandlingTests : TestFixtureBase
{
[Test]
public void DeserializeByteArrayWithTypeName()
{
string json = @"{
""$type"": ""Newtonsoft.Json.Tests.TestObjects.HasByteArray, Newtonsoft.Json.Tests"",
""EncryptedPassword"": {
""$type"": ""System.Byte[], mscorlib"",
""$value"": ""cGFzc3dvcmQ=""
}
}";
HasByteArray value = JsonConvert.DeserializeObject<HasByteArray>(json, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects
});
CollectionAssert.AreEquivalent(Convert.FromBase64String("cGFzc3dvcmQ="), value.EncryptedPassword);
}
[Test]
public void DeserializeByteArrayWithTypeName_BadAdditionalContent()
{
string json = @"{
""$type"": ""Newtonsoft.Json.Tests.TestObjects.HasByteArray, Newtonsoft.Json.Tests"",
""EncryptedPassword"": {
""$type"": ""System.Byte[], mscorlib"",
""$value"": ""cGFzc3dvcmQ="",
""$value"": ""cGFzc3dvcmQ=""
}
}";
ExceptionAssert.Throws<JsonReaderException>(() =>
{
JsonConvert.DeserializeObject<HasByteArray>(json, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects
});
}, "Error reading bytes. Unexpected token: PropertyName. Path 'EncryptedPassword.$value', line 6, position 13.");
}
[Test]
public void DeserializeByteArrayWithTypeName_ExtraProperty()
{
string json = @"{
""$type"": ""Newtonsoft.Json.Tests.TestObjects.HasByteArray, Newtonsoft.Json.Tests"",
""EncryptedPassword"": {
""$type"": ""System.Byte[], mscorlib"",
""$value"": ""cGFzc3dvcmQ=""
},
""Pie"": null
}";
HasByteArray value = JsonConvert.DeserializeObject<HasByteArray>(json, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects
});
Assert.IsNotNull(value.EncryptedPassword);
CollectionAssert.AreEquivalent(Convert.FromBase64String("cGFzc3dvcmQ="), value.EncryptedPassword);
}
#if !(NET20 || NET35)
[Test]
public void SerializeValueTupleWithTypeName()