synced AdvisedSupport with Spring/J
This commit is contained in:
@@ -222,9 +222,9 @@ namespace Spring.Aop.Framework
|
||||
|
||||
private ITestObject CreateProxy(object target, IAdvice interceptor, bool exposeProxy)
|
||||
{
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
pf.ExposeProxy = exposeProxy;
|
||||
pf.Target = target;
|
||||
// pf.Target = target;
|
||||
pf.AddAdvice(interceptor);
|
||||
|
||||
return pf.GetProxy() as ITestObject;
|
||||
|
||||
@@ -96,14 +96,6 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
ProxyAssertions(testObject, 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecoratorProxyWithWildcardMatch()
|
||||
{
|
||||
ITestObject testObject = (ITestObject)ctx.GetObject("decoratorProxy");
|
||||
DecoratorProxyAssertions(testObject);
|
||||
Assert.AreEqual("decoratorProxy", testObject.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FrozenProxy()
|
||||
{
|
||||
@@ -141,6 +133,14 @@ namespace Spring.Aop.Framework.AutoProxy
|
||||
Assert.AreEqual(2*nopInterceptorCount, nop.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecoratorProxyWithWildcardMatch()
|
||||
{
|
||||
ITestObject testObject = (ITestObject)ctx.GetObject("decoratorProxy");
|
||||
DecoratorProxyAssertions(testObject);
|
||||
Assert.AreEqual("decoratorProxy", testObject.Name);
|
||||
}
|
||||
|
||||
private void DecoratorProxyAssertions(ITestObject testObject)
|
||||
{
|
||||
CountingBeforeAdvice cba = (CountingBeforeAdvice) ctx.GetObject("countingBeforeAdvice");
|
||||
|
||||
@@ -459,15 +459,13 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
ITestObject target = new TestObject();
|
||||
target.Age = 26;
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = target;
|
||||
AdvisedSupport advised = new AdvisedSupport(target);
|
||||
advised.AddAdvice(new NopInterceptor());
|
||||
IAopProxy aop = CreateAopProxy(advised);
|
||||
ITestObject proxy1 = (ITestObject)aop.GetProxy();
|
||||
Assert.AreEqual(target.Age, proxy1.Age, "Incorrect age");
|
||||
|
||||
advised = new AdvisedSupport();
|
||||
advised.Target = proxy1;
|
||||
advised = new AdvisedSupport(proxy1);
|
||||
advised.AddAdvice(new NopInterceptor());
|
||||
aop = CreateAopProxy(advised);
|
||||
ITestObject proxy2 = (ITestObject)aop.GetProxy();
|
||||
@@ -483,14 +481,12 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
TheCommand target = new TheCommand();
|
||||
|
||||
// proxy
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = target;
|
||||
AdvisedSupport advised = new AdvisedSupport(target);
|
||||
advised.AddAdvice(new NopInterceptor());
|
||||
object proxy = CreateProxy(advised);
|
||||
|
||||
// proxy again
|
||||
advised = new AdvisedSupport();
|
||||
advised.Target = proxy;
|
||||
advised = new AdvisedSupport(proxy);
|
||||
advised.AddAdvice(new NopInterceptor());
|
||||
proxy = CreateAopProxy(advised);
|
||||
|
||||
@@ -844,8 +840,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.TargetSource = mockTargetSource;
|
||||
AdvisedSupport advised = new AdvisedSupport(mockTargetSource);
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
AbstractProxyTypeBuilderTests.InterfaceWithGenericMethod proxy =
|
||||
@@ -884,8 +879,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.TargetSource = mockTargetSource;
|
||||
AdvisedSupport advised = new AdvisedSupport(mockTargetSource);
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
AbstractProxyTypeBuilderTests.GenericInterface<TestObject> proxy =
|
||||
@@ -927,8 +921,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
TestObject target = new TestObject();
|
||||
target.Age = 26;
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = target;
|
||||
AdvisedSupport advised = new AdvisedSupport(target);
|
||||
advised.AddAdvice(new NopInterceptor());
|
||||
|
||||
ITestObject proxy = CreateProxy(advised) as ITestObject;
|
||||
@@ -1716,8 +1709,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
public void CanCastProxyToIAdvised()
|
||||
{
|
||||
TestObject to = new TestObject();
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = to;
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport(to);
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
advisedSupport.AddAdvice(0, ni);
|
||||
|
||||
|
||||
@@ -39,8 +39,9 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[TestFixture]
|
||||
public sealed class CachedAopProxyFactoryTests : DefaultAopProxyFactoryTests
|
||||
{
|
||||
protected override IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
|
||||
protected override IAopProxy CreateAopProxy(ProxyFactory advisedSupport)
|
||||
{
|
||||
// return (IAopProxy) advisedSupport.GetProxy();
|
||||
IAopProxyFactory apf = new CachedAopProxyFactory();
|
||||
return apf.CreateAopProxy(advisedSupport);
|
||||
}
|
||||
@@ -48,24 +49,20 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
// Clear Aop proxy type cache
|
||||
Assert.IsNotNull(TypeCacheField);
|
||||
TypeCacheField.SetValue(null, new Hashtable());
|
||||
CachedAopProxyFactory.ClearCache();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DoesNotCacheWithDifferentBaseType()
|
||||
{
|
||||
// Decorated-based proxy (BaseType == TargetType)
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new TestObject());
|
||||
advisedSupport.ProxyTargetType = true;
|
||||
advisedSupport.Target = new TestObject();
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
// Composition-based proxy (BaseType = BaseCompositionAopProxy)
|
||||
advisedSupport = new AdvisedSupport();
|
||||
advisedSupport = new ProxyFactory(new TestObject());
|
||||
advisedSupport.ProxyTargetType = false;
|
||||
advisedSupport.Target = new TestObject();
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
AssertAopProxyTypeCacheCount(2);
|
||||
@@ -74,12 +71,10 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void DoesNotCacheWithDifferentTargetType()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new BadCommand();
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new BadCommand());
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new GoodCommand();
|
||||
advisedSupport = new ProxyFactory(new GoodCommand());
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
AssertAopProxyTypeCacheCount(2);
|
||||
@@ -88,20 +83,17 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void DoesNotCacheWithDifferentInterfaces()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new TestObject();
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new TestObject());
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new TestObject();
|
||||
advisedSupport = new ProxyFactory(new TestObject());
|
||||
advisedSupport.AddInterface(typeof(IPerson));
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
AssertAopProxyTypeCacheCount(2);
|
||||
|
||||
// Same with Introductions
|
||||
advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new TestObject();
|
||||
advisedSupport = new ProxyFactory(new TestObject());
|
||||
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
|
||||
ti.TimeStamp = new DateTime(666L);
|
||||
IIntroductionAdvisor introduction = new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped));
|
||||
@@ -114,14 +106,12 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void DoesCacheWithTwoDecoratorBasedProxy()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new TestObject());
|
||||
advisedSupport.ProxyTargetType = true;
|
||||
advisedSupport.Target = new TestObject();
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
advisedSupport = new AdvisedSupport();
|
||||
advisedSupport = new ProxyFactory(new TestObject());
|
||||
advisedSupport.ProxyTargetType = true;
|
||||
advisedSupport.Target = new TestObject();
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
AssertAopProxyTypeCacheCount(1);
|
||||
@@ -130,27 +120,18 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void DoesCacheWithTwoCompositionBasedProxy()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new TestObject();
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new TestObject());
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new TestObject();
|
||||
advisedSupport = new ProxyFactory(new TestObject());
|
||||
CreateAopProxy(advisedSupport);
|
||||
|
||||
AssertAopProxyTypeCacheCount(1);
|
||||
}
|
||||
|
||||
|
||||
private static readonly FieldInfo TypeCacheField =
|
||||
typeof(CachedAopProxyFactory).GetField("typeCache", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
|
||||
private void AssertAopProxyTypeCacheCount(int count)
|
||||
{
|
||||
Assert.IsNotNull(TypeCacheField);
|
||||
Hashtable cache = TypeCacheField.GetValue(null) as Hashtable;
|
||||
Assert.IsNotNull(cache);
|
||||
Assert.AreEqual(count, cache.Count);
|
||||
Assert.AreEqual(count, CachedAopProxyFactory.CountCachedTypes);
|
||||
}
|
||||
|
||||
#region Helper classes definitions
|
||||
|
||||
@@ -209,8 +209,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.TargetSource = mockTargetSource;
|
||||
AdvisedSupport advised = new AdvisedSupport(mockTargetSource);
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
// Cast to the interface that method belongs to
|
||||
|
||||
@@ -36,8 +36,9 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[TestFixture]
|
||||
public class DefaultAopProxyFactoryTests
|
||||
{
|
||||
protected virtual IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
|
||||
protected virtual IAopProxy CreateAopProxy(ProxyFactory advisedSupport)
|
||||
{
|
||||
// return (IAopProxy) advisedSupport.GetProxy();
|
||||
IAopProxyFactory apf = new DefaultAopProxyFactory();
|
||||
return apf.CreateAopProxy(advisedSupport);
|
||||
}
|
||||
@@ -46,21 +47,23 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[ExpectedException(typeof(AopConfigException), ExpectedMessage="Cannot create IAopProxy with null ProxyConfig")]
|
||||
public void NullConfig()
|
||||
{
|
||||
CreateAopProxy(null);
|
||||
IAopProxyFactory apf = new DefaultAopProxyFactory();
|
||||
apf.CreateAopProxy(null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(AopConfigException), ExpectedMessage="Cannot create IAopProxy with no advisors and no target source")]
|
||||
public void NoInterceptorsAndNoTarget()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport(new Type[] { typeof(ITestObject) });
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new Type[] { typeof(ITestObject) });
|
||||
CreateAopProxy(advisedSupport);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TargetDoesNotImplementAnyInterfaces()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
ProxyFactory advisedSupport = new ProxyFactory();
|
||||
advisedSupport.AopProxyFactory = new DefaultAopProxyFactory();
|
||||
advisedSupport.ProxyTargetType = false;
|
||||
advisedSupport.Target = new DoesNotImplementAnyInterfacesTestObject();
|
||||
|
||||
@@ -72,9 +75,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void TargetImplementsAnInterface()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
advisedSupport.Target = new TestObject();
|
||||
|
||||
ProxyFactory advisedSupport = new ProxyFactory(new TestObject());
|
||||
IAopProxy aopProxy = CreateAopProxy(advisedSupport);
|
||||
Assert.IsNotNull(aopProxy);
|
||||
|
||||
@@ -84,7 +85,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void TargetImplementsAnInterfaceWithProxyTargetTypeSetToTrue()
|
||||
{
|
||||
AdvisedSupport advisedSupport = new AdvisedSupport();
|
||||
ProxyFactory advisedSupport = new ProxyFactory();
|
||||
advisedSupport.ProxyTargetType = true;
|
||||
advisedSupport.Target = new TestObject();
|
||||
|
||||
|
||||
@@ -230,8 +230,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
{
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = new InheritanceTestObject();
|
||||
AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
object proxy = CreateProxy(advised);
|
||||
@@ -253,8 +252,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
{
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = new InheritanceTestObject();
|
||||
AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
object proxy = CreateProxy(advised);
|
||||
@@ -277,8 +275,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
{
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = new InheritanceTestObject();
|
||||
AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
object proxy = CreateProxy(advised);
|
||||
@@ -296,8 +293,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
{
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = new InheritanceTestObject();
|
||||
AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
object proxy = CreateProxy(advised);
|
||||
@@ -314,8 +310,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
{
|
||||
NopInterceptor ni = new NopInterceptor();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.Target = new InheritanceTestObject();
|
||||
AdvisedSupport advised = new AdvisedSupport(new InheritanceTestObject());
|
||||
advised.AddAdvice(ni);
|
||||
|
||||
object proxy = CreateProxy(advised);
|
||||
|
||||
@@ -32,9 +32,7 @@ using System.Web;
|
||||
using AopAlliance.Aop;
|
||||
using AopAlliance.Intercept;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Aop.Advice;
|
||||
using Spring.Aop.Framework.Adapter;
|
||||
using Spring.Aop.Interceptor;
|
||||
@@ -164,7 +162,7 @@ namespace Spring.Aop.Framework
|
||||
Assert.AreEqual(di.Count, 0);
|
||||
test1.Age = (5);
|
||||
Assert.AreEqual(test1_1.Age, test1.Age);
|
||||
Assert.AreEqual(di.Count, 3);
|
||||
Assert.AreEqual(3, di.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -180,7 +178,7 @@ namespace Spring.Aop.Framework
|
||||
public void PrototypeInstancesAreIndependent()
|
||||
{
|
||||
IObjectFactory objectFactory = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTests.xml", GetType()));
|
||||
// Initial count value set in object factory XML
|
||||
// Initial count value set in object factory XML
|
||||
int INITIAL_COUNT = 10;
|
||||
|
||||
|
||||
@@ -222,7 +220,7 @@ namespace Spring.Aop.Framework
|
||||
public void CanGetFactoryReferenceAndManipulate()
|
||||
{
|
||||
ITestObject to = (ITestObject)factory.GetObject("test1");
|
||||
// no exception
|
||||
// no exception
|
||||
string dummy = to.Name;
|
||||
|
||||
IAdvised config = (IAdvised)to;
|
||||
@@ -246,7 +244,7 @@ namespace Spring.Aop.Framework
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Must see effect immediately on behaviour.
|
||||
/// Must see effect immediately on behaviour.
|
||||
/// TODO (EE): Note that we can't add or remove interfaces without reconfiguring the singleton.
|
||||
/// </summary>
|
||||
[Test, Ignore("change according to ProxyFactoryBeanTests.canAddAndRemoveAdvicesOnSingleton")]
|
||||
@@ -376,7 +374,7 @@ namespace Spring.Aop.Framework
|
||||
|
||||
/// <summary>
|
||||
/// Note that we can't add or remove interfaces without reconfiguring the
|
||||
/// singleton.
|
||||
/// singleton.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void CanAddAndRemoveAspectInterfacesOnSingletonByCasting()
|
||||
@@ -463,6 +461,7 @@ namespace Spring.Aop.Framework
|
||||
Assert.IsTrue(agi.GlobalsAdded == -1);
|
||||
|
||||
ProxyFactoryObject pfb = (ProxyFactoryObject)factory.GetObject("&validGlobals");
|
||||
pfb.GetObject(); // for creation
|
||||
Assert.AreEqual(2, pfb.Advisors.Length, "Proxy should have 1 global and 1 explicit advisor");
|
||||
Assert.AreEqual(1, pfb.Introductions.Length, "Proxy should have 1 global introduction");
|
||||
|
||||
@@ -519,20 +518,34 @@ namespace Spring.Aop.Framework
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(AopConfigException))]
|
||||
public void AddAdvisorWhenConfigIsFrozen()
|
||||
private ProxyFactoryObject CreateFrozenProxyFactory()
|
||||
{
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.AddInterface(typeof(ITestObject));
|
||||
fac.IsFrozen = true;
|
||||
fac.AddAdvisor(new PointcutForVoid());
|
||||
fac.AddAdvisor(new PointcutForVoid()); // this is ok, no proxy created yet
|
||||
fac.GetObject();
|
||||
return fac;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddAdvisorWhenConfigIsFrozen()
|
||||
{
|
||||
ProxyFactoryObject fac = CreateFrozenProxyFactory();
|
||||
try
|
||||
{
|
||||
fac.AddAdvisor(new PointcutForVoid()); // not ok
|
||||
Assert.Fail("changing a frozen config must throw AopConfigException");
|
||||
}
|
||||
catch (AopConfigException)
|
||||
{}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(AopConfigException))]
|
||||
public void RemoveAdvisorWhenConfigIsFrozen()
|
||||
{
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
ProxyFactoryObject fac = CreateFrozenProxyFactory();
|
||||
fac.IsFrozen = true;
|
||||
fac.RemoveAdvisor(new PointcutForVoid());
|
||||
}
|
||||
@@ -541,7 +554,7 @@ namespace Spring.Aop.Framework
|
||||
[ExpectedException(typeof(AopConfigException))]
|
||||
public void ReplaceAdvisorWhenConfigIsFrozen()
|
||||
{
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
ProxyFactoryObject fac = CreateFrozenProxyFactory();
|
||||
fac.IsFrozen = true;
|
||||
fac.ReplaceAdvisor(new PointcutForVoid(), new PointcutForVoid());
|
||||
}
|
||||
@@ -581,22 +594,31 @@ namespace Spring.Aop.Framework
|
||||
GoodCommand target = new GoodCommand();
|
||||
NopInterceptor advice = new NopInterceptor();
|
||||
|
||||
IObjectFactory mock = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
|
||||
Expect.Call(mock.IsSingleton("advice")).Return(true); // advice is a singleton...
|
||||
Expect.Call(mock.GetObject("advice")).Return(advice);
|
||||
Expect.Call(mock.GetType("prototype")).Return(typeof(GoodCommand));
|
||||
|
||||
Expect.Call(mock.GetObject("advice")).Return(advice);
|
||||
Expect.Call(mock.GetObject("prototype")).Return(target);
|
||||
mocks.ReplayAll();
|
||||
MockRepository mocks = new MockRepository();
|
||||
IObjectFactory factory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
|
||||
fac.IsSingleton = false;
|
||||
fac.InterceptorNames = new string[] { "advice", "prototype" };
|
||||
fac.ObjectFactory = mock;
|
||||
fac.ObjectFactory = factory;
|
||||
|
||||
fac.GetObject();
|
||||
// using (mocks.Record())
|
||||
{
|
||||
using (mocks.Unordered())
|
||||
{
|
||||
Expect.Call(factory.IsSingleton("advice")).Return(true);
|
||||
Expect.Call(factory.GetObject("advice")).Return(advice);
|
||||
Expect.Call(factory.GetType("prototype")).Return(target.GetType());
|
||||
Expect.Call(factory.GetObject("prototype")).Return(target);
|
||||
}
|
||||
}
|
||||
mocks.ReplayAll();
|
||||
|
||||
// using(mocks.Playback())
|
||||
{
|
||||
fac.GetObject();
|
||||
}
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
@@ -633,7 +655,7 @@ namespace Spring.Aop.Framework
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SingletonProxyWithPrototypeTarget()
|
||||
public void SingletonProxyWithPrototypeTargetCreatesTargetOnlyOnce()
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -651,7 +673,7 @@ namespace Spring.Aop.Framework
|
||||
fac.InterceptorNames = new string[] { "advice", "prototype" };
|
||||
fac.ObjectFactory = ctx;
|
||||
|
||||
Assert.AreEqual(1, InstantiationCountingCommand.NumberOfInstantiations, "First Call");
|
||||
Assert.AreEqual(0, InstantiationCountingCommand.NumberOfInstantiations, "First Call");
|
||||
fac.GetObject();
|
||||
Assert.AreEqual(1, InstantiationCountingCommand.NumberOfInstantiations, "Second Call");
|
||||
fac.GetObject();
|
||||
@@ -685,8 +707,7 @@ namespace Spring.Aop.Framework
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(AopConfigException))]
|
||||
public void NullNameInInterceptorNamesArray()
|
||||
public void NullNameInInterceptorNamesArrayThrowAopConfigException()
|
||||
{
|
||||
IObjectFactory factory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));
|
||||
|
||||
@@ -695,6 +716,13 @@ namespace Spring.Aop.Framework
|
||||
fac.IsSingleton = false;
|
||||
fac.InterceptorNames = new string[] { null, null };
|
||||
fac.ObjectFactory = factory;
|
||||
try
|
||||
{
|
||||
fac.GetObject();
|
||||
Assert.Fail();
|
||||
}
|
||||
catch (AopConfigException)
|
||||
{}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -843,7 +871,7 @@ namespace Spring.Aop.Framework
|
||||
XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null);
|
||||
|
||||
HelperInterface2 hc = (HelperInterface2)objectFactory.GetObject("MyProxy");
|
||||
Console.WriteLine(hc.SecondDoSomething());
|
||||
Console.WriteLine(hc.SecondDoSomething());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -899,7 +927,7 @@ namespace Spring.Aop.Framework
|
||||
{
|
||||
ProxyFactoryObject factoryObject = (ProxyFactoryObject) this.factory.GetObject( "&concurrentPrototype" );
|
||||
Type testObjectType1 = factoryObject.GetObject().GetType();
|
||||
|
||||
|
||||
factoryObject.Interfaces = new Type[] {};
|
||||
Type testObjectType2 = factoryObject.GetObject().GetType();
|
||||
|
||||
@@ -1032,7 +1060,7 @@ namespace Spring.Aop.Framework
|
||||
int GlobalsAdded { get; set; }
|
||||
}
|
||||
|
||||
/// <summary> Use as a global interceptor. Checks that
|
||||
/// <summary> Use as a global interceptor. Checks that
|
||||
/// global interceptors can add aspect interfaces.
|
||||
/// NB: Add only via global interceptors in XML file.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,6 +26,7 @@ using AopAlliance.Aop;
|
||||
using AopAlliance.Intercept;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Aop.Interceptor;
|
||||
using Spring.Aop.Support;
|
||||
using Spring.Objects;
|
||||
|
||||
@@ -25,7 +25,6 @@ using AopAlliance.Intercept;
|
||||
using Spring.Aop.Framework.Adapter;
|
||||
#endregion
|
||||
|
||||
|
||||
namespace Spring.Aop
|
||||
{
|
||||
/// <summary>
|
||||
@@ -33,6 +32,7 @@ namespace Spring.Aop
|
||||
/// </summary>
|
||||
/// <author>Dmitriy Kopylenko</author>
|
||||
/// <author>Simon White (.NET)</author>
|
||||
[Serializable]
|
||||
public class SimpleBeforeAdviceAdapter : IAdvisorAdapter
|
||||
{
|
||||
#region IAdvisorAdapter Members
|
||||
|
||||
Reference in New Issue
Block a user