User: fabian.schmied
Date: 2008/08/27 11:42 PM
Added:
/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/
DictionarySerializationTestCase.cs
/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/
ClassCallingVirtualMethodFromCtor.cs, ClassOverridingEqualsAndGetHashCode.cs
Modified:
/trunk/Tools/Castle.DynamicProxy2/
Changes.txt
/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/
BasicClassProxyTestCase.cs, Castle.DynamicProxy.Tests-vs2008.csproj
/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/
AbstractInvocation.cs
/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/Serialization/
ProxyObjectReference.cs
Log:
Added workarounds for dictionary deserialization scenarios (reported by
Gr‚gory C‚let), see DYNPROXY-ISSUE-76
Directory Changes:
Directory: /svn:mergeinfo/
==========================
+
---
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/DictionarySerializationTestCase.cs
(rev 0)
+++
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/DictionarySerializationTestCase.cs
2008-08-28 06:41:58 UTC (rev 5295)
@@ -0,0 +1,98 @@
+// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+using Castle.DynamicProxy.Tests.Classes;
+using NUnit.Framework;
+
+namespace Castle.DynamicProxy.Tests
+{
+ [TestFixture]
+ public class DictionarySerializationTestCase
+ {
+ [Test]
+ public void NullReferenceProxyDeserializationTest ()
+ {
+ ProxyGenerator generator = new ProxyGenerator ();
+ Dictionary<ClassOverridingEqualsAndGetHashCode, string>
theInstances = new Dictionary<ClassOverridingEqualsAndGetHashCode, string> ();
+ ClassOverridingEqualsAndGetHashCode c =
(ClassOverridingEqualsAndGetHashCode) generator.CreateClassProxy (typeof
(ClassOverridingEqualsAndGetHashCode));
+ c.Id = Guid.NewGuid ();
+ c.Name = DateTime.Now.ToString ("yyyyMMddHHmmss");
+ theInstances.Add (c, c.Name);
+ Dictionary<ClassOverridingEqualsAndGetHashCode, string>
theInstancesBis =
SerializeAndDeserialize<Dictionary<ClassOverridingEqualsAndGetHashCode,
string>> (theInstances);
+
+ Assert.IsNotNull (theInstancesBis);
+ Assert.AreEqual (theInstances.Count,
theInstancesBis.Count);
+ }
+
+ [Test]
+ public void DictionaryDeserializationWithoutProxyTest ()
+ {
+ Dictionary<ClassOverridingEqualsAndGetHashCode, string>
theInstances = new Dictionary<ClassOverridingEqualsAndGetHashCode, string> ();
+
+ for (int i = 0; i < 50; i++)
+ {
+ ClassOverridingEqualsAndGetHashCode c = new
ClassOverridingEqualsAndGetHashCode ();
+ c.Id = Guid.NewGuid ();
+ c.Name = DateTime.Now.ToString
("yyyyMMddHHmmss");
+ theInstances.Add (c, c.Name);
+ }
+
+ Dictionary<ClassOverridingEqualsAndGetHashCode, string>
theInstancesBis =
SerializeAndDeserialize<Dictionary<ClassOverridingEqualsAndGetHashCode,
string>> (theInstances);
+ }
+
+ [Test]
+ public void DictionaryDeserializationWithProxyTest ()
+ {
+ ProxyGenerator generator = new ProxyGenerator ();
+ Dictionary<ClassOverridingEqualsAndGetHashCode, string>
theInstances = new Dictionary<ClassOverridingEqualsAndGetHashCode, string> ();
+
+ for (int i = 0; i < 50; i++)
+ {
+ ClassOverridingEqualsAndGetHashCode c =
(ClassOverridingEqualsAndGetHashCode) generator.CreateClassProxy (typeof
(ClassOverridingEqualsAndGetHashCode));
+ c.Id = Guid.NewGuid ();
+ c.Name = DateTime.Now.ToString
("yyyyMMddHHmmss");
+ theInstances.Add (c, c.Name);
+ }
+
+ Dictionary<ClassOverridingEqualsAndGetHashCode, string>
theInstancesBis =
SerializeAndDeserialize<Dictionary<ClassOverridingEqualsAndGetHashCode,
string>> (theInstances);
+ }
+
+ [Test]
+ public void BasicSerializationProxyTest ()
+ {
+ ProxyGenerator generator = new ProxyGenerator ();
+ ClassOverridingEqualsAndGetHashCode c =
(ClassOverridingEqualsAndGetHashCode) generator.CreateClassProxy (typeof
(ClassOverridingEqualsAndGetHashCode));
+ c.Id = Guid.NewGuid ();
+ c.Name = DateTime.Now.ToString ("yyyyMMddHHmmss");
+
+ ClassOverridingEqualsAndGetHashCode c2 =
SerializeAndDeserialize<ClassOverridingEqualsAndGetHashCode> (c);
+ Assert.IsNotNull (c2);
+ Assert.AreEqual (c.Id, c2.Id);
+ Assert.AreEqual (c.Name, c2.Name);
+ }
+
+ public static T SerializeAndDeserialize<T> (T proxy)
+ {
+ MemoryStream stream = new MemoryStream ();
+ BinaryFormatter formatter = new BinaryFormatter ();
+ formatter.Serialize (stream, proxy);
+ stream.Position = 0;
+ return (T) formatter.Deserialize (stream);
+ }
+ }
+}
File Changes:
Directory: /trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/
=================================================================
File [modified]: AbstractInvocation.cs
Delta lines: +11 -2
===================================================================
---
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/Serialization/ProxyObjectReference.cs
2008-08-27 22:43:25 UTC (rev 5294)
+++
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/Serialization/ProxyObjectReference.cs
2008-08-28 06:41:58 UTC (rev 5295)
@@ -88,6 +88,10 @@
_proxyGenerationOptions = (ProxyGenerationOptions)
info.GetValue ("__proxyGenerationOptions", typeof (ProxyGenerationOptions));
_proxy = RecreateProxy ();
+
+ // We'll try to deserialize as much of the proxy state
as possible here. This is just best effort; due to deserialization dependency
reasons,
+ // we need to repeat this in OnDeserialization to
guarantee correct state deserialization.
+ DeserializeProxyState ();
}
private Type DeserializeTypeFromString (string key)
@@ -200,6 +204,13 @@
}
}
+ // Get the proxy state again, to get all those members
we couldn't get in the constructor due to deserialization ordering.
+ DeserializeProxyState();
+ InvokeCallback (_proxy);
+ }
+
+ private void DeserializeProxyState ()
+ {
if (_isInterfaceProxy)
{
object target = _info.GetValue ("__target",
typeof (object));
@@ -211,8 +222,6 @@
MemberInfo[] members =
FormatterServices.GetSerializableMembers (_baseType);
FormatterServices.PopulateObjectMembers
(_proxy, members, baseMemberData);
}
-
- InvokeCallback (_proxy);
}
Directory: /trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/
=======================================================================
File [modified]: BasicClassProxyTestCase.cs
Delta lines: +4 -1
===================================================================
---
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Castle.DynamicProxy.Tests-vs2008.csproj
2008-08-27 22:43:25 UTC (rev 5294)
+++
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Castle.DynamicProxy.Tests-vs2008.csproj
2008-08-28 06:41:58 UTC (rev 5295)
@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.21022</ProductVersion>
+ <ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{FE432670-73A1-499D-A353-28FC902A43C8}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -121,11 +121,14 @@
<Compile Include="BugsReported\DynProxy46.cs" />
<Compile Include="CacheKeyTestCase.cs" />
<Compile Include="ClassEmitterTestCase.cs" />
+ <Compile Include="Classes\ClassCallingVirtualMethodFromCtor.cs" />
<Compile Include="Classes\ClassWithCharRetType.cs" />
<Compile Include="Classes\ClassWithConstructors.cs" />
<Compile Include="Classes\MySerializableClass.cs" />
<Compile Include="Classes\ProtectedInternalConstructorClass.cs" />
<Compile Include="Classes\SimpleClass.cs" />
+ <Compile Include="Classes\ClassOverridingEqualsAndGetHashCode.cs" />
+ <Compile Include="DictionarySerializationTestCase.cs" />
<Compile Include="MixinDataTestCase.cs" />
<Compile Include="CrossAppDomainCaller.cs" />
File [modified]: Castle.DynamicProxy.Tests-vs2008.csproj
Delta lines: +30 -0
===================================================================
---
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/ClassCallingVirtualMethodFromCtor.cs
(rev 0)
+++
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/ClassCallingVirtualMethodFromCtor.cs
2008-08-28 06:41:58 UTC (rev 5295)
@@ -0,0 +1,30 @@
+// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+namespace Castle.DynamicProxy.Tests.Classes
+{
+ public class ClassCallingVirtualMethodFromCtor
+ {
+ public int Result;
+
+ public ClassCallingVirtualMethodFromCtor ()
+ {
+ Result = VirtualMethod();
+ }
+
+ public virtual int VirtualMethod ()
+ {
+ return 7;
+ }
+ }
+}
File [added]: DictionarySerializationTestCase.cs
Delta lines: +2 -0
===================================================================
--- trunk/Tools/Castle.DynamicProxy2/Changes.txt 2008-08-27 22:43:25 UTC
(rev 5294)
+++ trunk/Tools/Castle.DynamicProxy2/Changes.txt 2008-08-28 06:41:58 UTC
(rev 5295)
@@ -1,5 +1,7 @@
Beta 1 Version 1.0.0.0
======================
+- Added workarounds for dictionary deserialization scenarios (reported by
Grégory Célet)
+
- Fixed mixin-related bug with serialization (per Rogelio again)
- Made interface proxies without target and with target interface support
mixins
Directory: /trunk/Tools/Castle.DynamicProxy2/
=============================================
File [modified]: Changes.txt
Delta lines: +0 -0
===================================================================
Directory: /trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/
===============================================================================
File [added]: ClassCallingVirtualMethodFromCtor.cs
Delta lines: +72 -0
===================================================================
---
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs
(rev 0)
+++
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs
2008-08-28 06:41:58 UTC (rev 5295)
@@ -0,0 +1,72 @@
+// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.DynamicProxy.Tests.Classes
+{
+ using System;
+ [Serializable]
+ public class ClassOverridingEqualsAndGetHashCode
+ {
+ private Guid _id;
+ private string _name;
+
+ public virtual Guid Id
+ {
+ get { return _id; }
+ set { _id = value; }
+ }
+
+ public virtual string Name
+ {
+ get { return _name; }
+ set { _name = value; }
+ }
+
+ public virtual bool Equals (ClassOverridingEqualsAndGetHashCode
other)
+ {
+ if (other == null)
+ return false;
+
+ // use this pattern to compare value members
+ if (!Id.Equals (other.Id))
+ return false;
+
+ // use this pattern to compare reference members
+ // if (!Object.Equals(Id, other.Id)) return false;
+
+ return true;
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (obj == null)
+ return false;
+
+ if (!(obj is ClassOverridingEqualsAndGetHashCode))
+ return false;
+
+ // safe because of the GetType check
+ return Equals ((ClassOverridingEqualsAndGetHashCode)
obj);
+ }
+
+ public override int GetHashCode ()
+ {
+ int hash = 7;
+
+ hash = 31 * hash + Id.GetHashCode ();
+
+ return hash;
+ }
+ }
+}
File [added]: ClassOverridingEqualsAndGetHashCode.cs
Delta lines: +0 -0
===================================================================
Property changes on:
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/Classes/ClassOverridingEqualsAndGetHashCode.cs
___________________________________________________________________
Directory: /trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/Serialization/
===============================================================================
File [modified]: ProxyObjectReference.cs
Delta lines: +8 -0
===================================================================
---
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/BasicClassProxyTestCase.cs
2008-08-27 22:43:25 UTC (rev 5294)
+++
trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/BasicClassProxyTestCase.cs
2008-08-28 06:41:58 UTC (rev 5295)
@@ -356,5 +356,13 @@
object proxy = generator.CreateClassProxy (t1, new
Type[] { t2 }, new StandardInterceptor ());
Assert.IsFalse (StrongNameUtil.IsAssemblySigned
(proxy.GetType ().Assembly));
}
+
+ [Test]
+ public void VirtualCallFromCtor ()
+ {
+ StandardInterceptor interceptor = new
StandardInterceptor();
+ ClassCallingVirtualMethodFromCtor proxy =
generator.CreateClassProxy<ClassCallingVirtualMethodFromCtor> (interceptor);
+ Assert.AreEqual (7, proxy.Result);
+ }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=en
-~----------~----~----~----~------~----~------~--~---