-Tests
This commit is contained in:
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()
|
||||
|
||||
Reference in New Issue
Block a user