starting fixing proxy equality issue (false == proxy.Equals(proxy))
This commit is contained in:
@@ -23,12 +23,14 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
|
||||
using AopAlliance.Aop;
|
||||
using AopAlliance.Intercept;
|
||||
using Spring.Aop.Target;
|
||||
using Spring.Util;
|
||||
|
||||
#endregion
|
||||
@@ -426,6 +428,62 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
get { return m_targetType; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Equal, HashCode and ToString overrides
|
||||
|
||||
/// <summary>
|
||||
/// Delegate to target object handling of equals method.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to compare with the current target object</param>
|
||||
/// <returns>true if the specified Object is equal to the current target object; otherwise, false</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(this, obj))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AdvisedProxy otherProxy = obj as AdvisedProxy;
|
||||
if (otherProxy != null)
|
||||
{
|
||||
using (m_targetSourceWrapper)
|
||||
using (otherProxy.m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().Equals(otherProxy.m_targetSourceWrapper.GetTarget());
|
||||
}
|
||||
}
|
||||
|
||||
using (m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().Equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delgate to the target object generation of the hash code.
|
||||
/// </summary>
|
||||
/// <returns>A hash code for the target object.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
using (m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a String the represents the target object.
|
||||
/// </summary>
|
||||
/// <returns>A String that represents the target object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
using (m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,46 +84,5 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Equal, HashCode and ToString overrides
|
||||
|
||||
/// <summary>
|
||||
/// Delegate to target object handling of equals method.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to compare with the current target object</param>
|
||||
/// <returns>true if the specified Object is equal to the current target object; otherwise, false</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
using (m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().Equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delgate to the target object generation of the hash code.
|
||||
/// </summary>
|
||||
/// <returns>A hash code for the target object.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
using (m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a String the represents the target object.
|
||||
/// </summary>
|
||||
/// <returns>A String that represents the target object</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
using (m_targetSourceWrapper)
|
||||
{
|
||||
return m_targetSourceWrapper.GetTarget().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -263,6 +263,24 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
string Company { get; set; }
|
||||
}
|
||||
|
||||
public class TestCustomer : ITestCustomer
|
||||
{
|
||||
public long Id
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public string Company
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test(Description = "http://jira.springframework.org/browse/SPRNET-1174")]
|
||||
@@ -290,6 +308,22 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Equality()
|
||||
{
|
||||
TestCustomer customer = new TestCustomer();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = customer;
|
||||
advised.Interfaces = new Type[] { typeof(ITestCustomer) };
|
||||
|
||||
ITestCustomer to = CreateProxy(advised) as ITestCustomer;
|
||||
Assert.IsNotNull(to);
|
||||
Assert.IsTrue( to.Equals(to), "identity must be equal" );
|
||||
Assert.AreEqual(to, to);
|
||||
Assert.AreEqual(to, ((IAdvised)to).TargetSource.GetTarget());
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(NotSupportedException)
|
||||
, ExpectedMessage = "Target 'target' is null.")]
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<WarningLevel>3</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<UseVSHostingProcess>true</UseVSHostingProcess>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>..\..\..\build\VS.Net.2008\Spring.Aop.Tests\Release\</OutputPath>
|
||||
|
||||
Reference in New Issue
Block a user