You've already forked linux-packaging-mono
Imported Upstream version 3.12.0
Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
@ -1191,6 +1191,15 @@ namespace MonoTests.System.Runtime.Serialization.Json
|
||||
return ser.ReadObject (xr);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(string json)
|
||||
{
|
||||
var bytes = Encoding.Unicode.GetBytes (json);
|
||||
using (MemoryStream stream = new MemoryStream (bytes)) {
|
||||
var serializer = new DataContractJsonSerializer (typeof(T));
|
||||
return (T)serializer.ReadObject (stream);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsStartObject ()
|
||||
{
|
||||
@ -1819,6 +1828,50 @@ namespace MonoTests.System.Runtime.Serialization.Json
|
||||
serializer.WriteObject (stream, o);
|
||||
}
|
||||
|
||||
// properly deserialize object with a polymorphic property (known derived type)
|
||||
[Test]
|
||||
public void Bug23058()
|
||||
{
|
||||
string serializedObj = @"{""PolymorphicProperty"":{""__type"":""KnownDerivedType:#MonoTests.System.Runtime.Serialization.Json"",""BaseTypeProperty"":""Base"",""DerivedProperty"":""Derived 1""},""Name"":""Parent2""}";
|
||||
ParentType deserializedObj = Deserialize<ParentType> (serializedObj);
|
||||
|
||||
Assert.AreEqual (deserializedObj.PolymorphicProperty.GetType ().FullName, "MonoTests.System.Runtime.Serialization.Json.KnownDerivedType");
|
||||
Assert.AreEqual (deserializedObj.PolymorphicProperty.BaseTypeProperty, "Base");
|
||||
Assert.AreEqual ((deserializedObj.PolymorphicProperty as KnownDerivedType).DerivedProperty, "Derived 1");
|
||||
Assert.AreEqual (deserializedObj.Name, "Parent2");
|
||||
}
|
||||
|
||||
// properly deserialize object with a polymorphic property (base type with __type hint)
|
||||
[Test]
|
||||
public void DeserializeBaseTypePropHint()
|
||||
{
|
||||
string serializedObj = @"{""PolymorphicProperty"":{""__type"":""BaseType:#MonoTests.System.Runtime.Serialization.Json"",""BaseTypeProperty"":""Base""},""Name"":""Parent2""}";
|
||||
ParentType deserializedObj = Deserialize<ParentType> (serializedObj);
|
||||
|
||||
Assert.AreEqual (deserializedObj.PolymorphicProperty.GetType ().FullName, "MonoTests.System.Runtime.Serialization.Json.BaseType");
|
||||
Assert.AreEqual (deserializedObj.PolymorphicProperty.BaseTypeProperty, "Base");
|
||||
}
|
||||
|
||||
// properly deserialize object with a polymorphic property (base type with __type hint)
|
||||
[Test]
|
||||
public void DeserializeBaseTypePropNoHint()
|
||||
{
|
||||
string serializedObj = @"{""PolymorphicProperty"":{""BaseTypeProperty"":""Base""},""Name"":""Parent2""}";
|
||||
ParentType deserializedObj = Deserialize<ParentType> (serializedObj);
|
||||
|
||||
Assert.AreEqual (deserializedObj.PolymorphicProperty.GetType ().FullName, "MonoTests.System.Runtime.Serialization.Json.BaseType");
|
||||
Assert.AreEqual (deserializedObj.PolymorphicProperty.BaseTypeProperty, "Base");
|
||||
}
|
||||
|
||||
// properly fail deserializing object with a polymorphic property (unknown derived type)
|
||||
[ExpectedException (typeof (SerializationException))]
|
||||
[Test]
|
||||
public void FailDeserializingUnknownTypeProp()
|
||||
{
|
||||
string serializedObj = @"{""PolymorphicProperty"":{""__type"":""UnknownDerivedType:#MonoTests.System.Runtime.Serialization.Json"",""BaseTypeProperty"":""Base"",""DerivedProperty"":""Derived 1""},""Name"":""Parent2""}";
|
||||
ParentType deserializedObj = Deserialize<ParentType> (serializedObj);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -2037,6 +2090,42 @@ namespace MonoTests.System.Runtime.Serialization.Json
|
||||
public long CodedServerTimeUTC { get; set; }
|
||||
public DateTime ServerTimeUTC { get; set; }
|
||||
}
|
||||
|
||||
#region polymorphism test helper classes
|
||||
|
||||
[DataContract]
|
||||
[KnownType (typeof (KnownDerivedType))]
|
||||
public class ParentType
|
||||
{
|
||||
[DataMember]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public BaseType PolymorphicProperty { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class BaseType
|
||||
{
|
||||
[DataMember]
|
||||
public string BaseTypeProperty { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class KnownDerivedType : BaseType
|
||||
{
|
||||
[DataMemberAttribute]
|
||||
public string DerivedProperty { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class UnknownDerivedType : BaseType
|
||||
{
|
||||
[DataMember]
|
||||
public string DerivedProperty { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
|
@ -855,5 +855,16 @@ namespace MonoTests.System.Runtime.Serialization.Json
|
||||
r.ReadStartElement ();
|
||||
r.Read ();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadNumberAsObject ()
|
||||
{
|
||||
const double testValue = 42.42D;
|
||||
var serializer = new DataContractJsonSerializer (typeof (object));
|
||||
var serializedStream = GetInput (testValue.ToString (CultureInfo.InvariantCulture));
|
||||
var deserializedValue = serializer.ReadObject (serializedStream);
|
||||
Assert.AreEqual (typeof (decimal), deserializedValue.GetType ());
|
||||
Assert.AreEqual (testValue, (decimal) deserializedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,6 +351,24 @@ namespace MonoTests.System.ServiceModel.Syndication
|
||||
{
|
||||
Assert.IsNull (((IXmlSerializable) new Rss20ItemFormatter ()).GetSchema ());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadFromGuidPermaLink ()
|
||||
{
|
||||
const string xml1 = "<item><guid isPermaLink=\"false\">urn:myid</guid><description /></item>";
|
||||
using (XmlReader r = CreateReader (xml1)) {
|
||||
var rss = new Rss20ItemFormatter ();
|
||||
rss.ReadFrom (r);
|
||||
Assert.AreEqual ("urn:myid", rss.Item.Id);
|
||||
}
|
||||
|
||||
const string xml2 = "<item><guid isPermaLink=\"true\">urn:myid</guid><description /></item>";
|
||||
using (XmlReader r = CreateReader (xml2)) {
|
||||
var rss = new Rss20ItemFormatter ();
|
||||
rss.ReadFrom (r);
|
||||
Assert.AreEqual ("urn:myid", rss.Item.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user