fixed SPRNET-1176
This commit is contained in:
@@ -236,7 +236,7 @@ namespace Spring.Aop.Framework
|
||||
/// <value>
|
||||
/// <c>true</c> if this instance can be serialized, <c>false</c> otherwise.
|
||||
/// </value>
|
||||
public bool IsSerializable
|
||||
public virtual bool IsSerializable
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
/// <param name="info">Serialization data.</param>
|
||||
/// <param name="context">Serialization context.</param>
|
||||
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
|
||||
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("advised", m_advised);
|
||||
info.AddValue("introductions", m_introductions);
|
||||
|
||||
@@ -62,6 +62,14 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
protected BaseCompositionAopProxy(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{}
|
||||
|
||||
///<summary>
|
||||
///Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with the data needed to serialize the target object.
|
||||
///</summary>
|
||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IAopProxy Members
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Spring.Proxy;
|
||||
using Spring.Aop.Target;
|
||||
using Spring.Aop.Target;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -53,6 +54,13 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Serializable]
|
||||
public class DefaultAopProxyFactory : IAopProxyFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Force transient assemblies to be resolvable by <see cref="Assembly.Load(string)"/>.
|
||||
/// </summary>
|
||||
static DefaultAopProxyFactory()
|
||||
{
|
||||
SystemUtils.RegisterLoadedAssemblyResolver();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Spring.Aop.Framework.IAopProxy"/> for the
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Threading;
|
||||
using System.Reflection;
|
||||
using System.Collections;
|
||||
@@ -67,7 +71,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[TestFixtureSetUp]
|
||||
public void FixtureSetUp()
|
||||
{
|
||||
SystemUtils.RegisterLoadedAssemblyResolver();
|
||||
// SystemUtils.RegisterLoadedAssemblyResolver();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -95,6 +99,134 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
return (IAopProxy)proxyCtorInfo.Invoke(new object[] { advisedSupport });
|
||||
}
|
||||
|
||||
#region Serialization Tests
|
||||
|
||||
private object SerializeAndDeserialize(object s)
|
||||
{
|
||||
// Serialize the session
|
||||
using (Stream stream = new MemoryStream())
|
||||
{
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
formatter.AssemblyFormat = FormatterAssemblyStyle.Full;
|
||||
formatter.TypeFormat = FormatterTypeStyle.TypesAlways;
|
||||
formatter.Serialize(stream, s);
|
||||
|
||||
// Deserialize the session
|
||||
stream.Position = 0;
|
||||
object res = formatter.Deserialize(stream);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISerializableTestObject
|
||||
{
|
||||
string TestData { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableTestObject : ISerializableTestObject, IDeserializationCallback
|
||||
{
|
||||
public static int InstanceCount;
|
||||
|
||||
public SerializableTestObject()
|
||||
{
|
||||
InstanceCount++;
|
||||
}
|
||||
|
||||
public string TestData { get { return testData; } set { testData = value; } }
|
||||
|
||||
private string testData;
|
||||
|
||||
public void OnDeserialization(object sender)
|
||||
{
|
||||
// only count non-proxy type deserializations
|
||||
if (!AopUtils.IsAopProxy(this))
|
||||
{
|
||||
InstanceCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class CustomSerializableTestObject : ISerializableTestObject, ISerializable, IDeserializationCallback
|
||||
{
|
||||
public static int InstanceCount;
|
||||
|
||||
public CustomSerializableTestObject()
|
||||
{
|
||||
InstanceCount++;
|
||||
}
|
||||
|
||||
protected CustomSerializableTestObject(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
TestData = info.GetString("testData");
|
||||
}
|
||||
|
||||
public void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("testData", TestData);
|
||||
}
|
||||
|
||||
public string TestData { get { return testData; } set { testData = value; } }
|
||||
|
||||
public void OnDeserialization(object sender)
|
||||
{
|
||||
if (!AopUtils.IsAopProxy(this))
|
||||
{
|
||||
InstanceCount++;
|
||||
}
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
private string testData;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSerializeDeserializeSerializable()
|
||||
{
|
||||
int instanceCount;
|
||||
ISerializableTestObject target = new SerializableTestObject();
|
||||
target.TestData = "testData";
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = target;
|
||||
advised.Interfaces = new Type[] { typeof(ISerializableTestObject) };
|
||||
// advised.AddAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
|
||||
|
||||
ISerializableTestObject to = (ISerializableTestObject)CreateAopProxy(advised);
|
||||
|
||||
instanceCount = SerializableTestObject.InstanceCount;
|
||||
to = (ISerializableTestObject)SerializeAndDeserialize(to);
|
||||
|
||||
// new instance was created
|
||||
Assert.AreEqual(instanceCount + 1, SerializableTestObject.InstanceCount);
|
||||
// values were (de-)serialized
|
||||
Assert.AreEqual(target.TestData, to.TestData);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanSerializeDeserializeISerializable()
|
||||
{
|
||||
int instanceCount;
|
||||
ISerializableTestObject target = new CustomSerializableTestObject();
|
||||
target.TestData = "testData";
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = target;
|
||||
advised.Interfaces = new Type[] { typeof(ISerializableTestObject) };
|
||||
// advised.AddAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
|
||||
|
||||
ISerializableTestObject to = (ISerializableTestObject)CreateAopProxy(advised);
|
||||
|
||||
instanceCount = CustomSerializableTestObject.InstanceCount;
|
||||
to = (ISerializableTestObject)SerializeAndDeserialize(to);
|
||||
|
||||
// new instance was created
|
||||
Assert.AreEqual(instanceCount + 1, CustomSerializableTestObject.InstanceCount);
|
||||
// values were (de-)serialized
|
||||
Assert.AreEqual(target.TestData, to.TestData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test(Description = "Simple test that if we set values we can get them out again.")]
|
||||
public void ValuesStick()
|
||||
{
|
||||
|
||||
@@ -21,7 +21,15 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using NUnit.Framework;
|
||||
using Spring.Aop.Interceptor;
|
||||
using Spring.Aop.Support;
|
||||
using Spring.Objects;
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user