Initial import!

This commit is contained in:
markpollack
2008-05-30 22:55:02 +00:00
commit c478a783c0
2978 changed files with 510966 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Spring.Net Unit Tests")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.1.0")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
// *IMPORTANT*: for Mono compatibility one must not use these attributes if strong name is not used!
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
//[assembly: AssemblyKeyName("")]

View File

@@ -0,0 +1,92 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Advice
{
/// <summary>
/// Convenience <see cref="AopAlliance.Intercept.IMethodInterceptor"/>
/// implementation that displays verbose information about intercepted
/// invocations to the system console.
/// </summary>
/// <remarks>
/// <p>
/// Can be introduced into an interceptor chain to serve as a useful low
/// level debugging aid.
/// </p>
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
/// <author>Aleksandar Seovic (.NET)</author>
/// <version>$Id: DebugAdvice.cs,v 1.1 2007/08/08 07:45:36 markpollack Exp $</version>
/// <seealso cref="System.Console"/>
public sealed class DebugAdvice : IMethodInterceptor
{
private int _count;
/// <summary>
/// Gets the count of the number of times this interceptor has been
/// invoked.
/// </summary>
/// <returns>
/// The count of the number of times this interceptor has been invoked.
/// </returns>
public int Count
{
get { return _count; }
}
/// <summary>
/// Displays verbose information about intercepted invocations to the
/// system console.
/// </summary>
/// <param name="invocation">
/// The method invocation that is being intercepted.
/// </param>
/// <returns>
/// The result of the call to the
/// <see cref="AopAlliance.Intercept.IJoinpoint.Proceed"/> method of
/// the supplied <paramref name="invocation"/>; this return value may
/// well have been intercepted by the interceptor.
/// </returns>
/// <exception cref="System.Exception">
/// If any of the interceptors in the chain or the target object itself
/// throws an exception.
/// </exception>
/// <seealso cref="System.Console"/>
/// <seealso cref="AopAlliance.Intercept.IMethodInterceptor.Invoke(IMethodInvocation)"/>
public object Invoke(IMethodInvocation invocation)
{
++_count;
Console.Out.WriteLine("{0} [count={1}, invocation='{2}']",
typeof(DebugAdvice).Name, _count, invocation);
object returnValue = invocation.Proceed();
Console.Out.WriteLine("{0} ['{1}' invocation returned '{2}']",
typeof(DebugAdvice).Name, invocation.Method.Name, returnValue);
return returnValue;
}
}
}

View File

@@ -0,0 +1,102 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using NUnit.Framework;
using Spring.Aop.Framework;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects;
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.Aop.Config
{
/// <summary>
/// This class contains tests for the custom aop namespace.
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: AopNamespaceParserTests.cs,v 1.7 2007/08/09 03:06:37 markpollack Exp $</version>
[TestFixture]
public class AopNamespaceParserTests
{
private IApplicationContext ctx;
[SetUp]
public void Setup()
{
NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser));
//ctx = new XmlApplicationContext( "assembly://Spring.Aop.Tests/Spring.Aop.Config/AopNamespaceParserTests.xml");
ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("AopNamespaceParserTests.xml", this.GetType()));
}
[Test]
public void Registered()
{
Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/aop"));
IPointcut pointcut = ctx["getDescriptionCalls"] as IPointcut;
Assert.IsNotNull(pointcut);
Assert.IsFalse(AopUtils.IsAopProxy(pointcut));
ITestObject testObject = ctx["testObject"] as ITestObject;
Assert.IsNotNull(testObject);
Assert.IsTrue(AopUtils.IsAopProxy(testObject), "Object should be an AOP proxy");
IAdvised advised = testObject as IAdvised;
Assert.IsNotNull(advised);
IAdvisor[] advisors = advised.Advisors;
Assert.IsTrue(advisors.Length > 0, "Advisors should not be empty");
}
[Test]
public void AdviceInvokedCorrectly()
{
CountingBeforeAdvice getDescriptionCounter = ctx.GetObject("getDescriptionCounter") as CountingBeforeAdvice;
Assert.IsNotNull(getDescriptionCounter);
ITestObject testObject = GetTestObject();
Assert.AreEqual(0,getDescriptionCounter.GetCalls("GetDescription"),"Incorrect initial getDescription count");
testObject.GetDescription();
Assert.AreEqual(1, getDescriptionCounter.GetCalls("GetDescription"), "Incorrect getDescription count");
}
private ITestObject GetTestObject()
{
return ctx.GetObject("testObject", typeof (ITestObject)) as ITestObject;
}
}
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.net/aop">
<aop:config>
<aop:advisor id="getDescriptionAdvisor" pointcut-ref="getDescriptionCalls" advice-ref="getDescriptionCounter"/>
</aop:config>
<object id="getDescriptionCalls" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
<property name="patterns">
<list>
<value>.*GetDescription.*</value>
</list>
</property>
</object>
<object id="getDescriptionCounter" type="Spring.Aop.Framework.CountingBeforeAdvice, Spring.Aop.Tests"/>
<object name="testObject" type="Spring.Objects.TestObject, Spring.Core.Tests"/>
</objects>

View File

@@ -0,0 +1,248 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Globalization;
using System.Reflection;
using AopAlliance.Intercept;
using DotNetMock.Dynamic;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the AbstractMethodInvocation class.
/// </summary>
/// <author>Rick Evans</author>
/// <author>Bruno Baia</author>
/// <version>$Id: AbstractMethodInvocationTests.cs,v 1.2 2008/02/06 18:29:05 bbaia Exp $</version>
[TestFixture]
public abstract class AbstractMethodInvocationTests
{
protected abstract AbstractMethodInvocation CreateMethodInvocation(
object proxy, object target, MethodInfo method, MethodInfo onProxyMethod,
object[] arguments, Type targetType, IList interceptors);
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationWithNullMethod()
{
CreateMethodInvocation(null, this, null, null, null, GetType(), null);
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void InstantiationWithNullTarget()
{
CreateMethodInvocation(null, null, null, null, null, GetType(), null);
}
[Test]
public void ProceedWithNullInterceptorChain()
{
Target target = new Target();
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), null);
string score = (string) join.Proceed();
Assert.AreEqual(Target.DefaultScore + Target.Suffix, score);
}
[Test]
public void ProceedWithEmptyInterceptorChain()
{
Target target = new Target();
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList());
string score = (string) join.Proceed();
Assert.AreEqual(Target.DefaultScore + Target.Suffix, score);
}
[Test]
public void ToStringWithoutArguments()
{
Target target = new Target();
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList());
CheckToStringDoesntThrowAnException(join);
}
[Test]
public void ToStringWithArguments()
{
Target target = new Target();
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethod(), null, new string[] { "Five" }, target.GetType(), new ArrayList());
CheckToStringDoesntThrowAnException(join);
}
[Test]
public void ToStringMustNotInvokeToStringOnTarget()
{
Target target = new TargetWithBadToString();
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new ArrayList());
// if it hits the target the test will fail with NotSupportedException...
CheckToStringDoesntThrowAnException(join);
}
private static string CheckToStringDoesntThrowAnException(AbstractMethodInvocation join)
{
return join.ToString();
}
public class Target
{
public const string Suffix = "!!!";
public const string DefaultScore = "ONE HUNDRED AND EIGHTY";
public MethodInfo GetTargetMethodNoArgs()
{
return GetType().GetMethod("BullseyeMethod", Type.EmptyTypes);
}
public MethodInfo GetTargetMethod()
{
return GetType().GetMethod("BullseyeMethod", new Type[] {typeof (string)});
}
public string BullseyeMethod()
{
return BullseyeMethod(DefaultScore);
}
public string BullseyeMethod(string score)
{
return score + Suffix;
}
}
public interface ICommand
{
void Execute();
}
public sealed class BadCommand : ICommand
{
public void Execute()
{
throw new NotImplementedException();
}
public MethodInfo GetTargetMethod()
{
return GetType().GetMethod("Execute", Type.EmptyTypes);
}
}
private sealed class TargetWithBadToString : Target
{
public override string ToString()
{
throw new NotSupportedException("ToString");
}
}
[Test]
public void ValidInvocation()
{
Target target = new Target();
IDynamicMock mock = new DynamicMock(typeof (IMethodInterceptor));
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new object[] { mock.Object });
mock.ExpectAndReturn("Invoke", target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture));
string score = (string) join.Proceed();
Assert.AreEqual(Target.DefaultScore.ToLower(CultureInfo.InvariantCulture) + Target.Suffix, score);
mock.Verify();
}
[Test]
public void UnwrapsTargetInvocationException_NoInterceptors()
{
BadCommand target = new BadCommand();
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { });
try
{
join.Proceed();
}
catch (NotImplementedException)
{
// this is good, we want this exception to bubble up...
}
catch (TargetInvocationException)
{
Assert.Fail("Must have unwrapped this.");
}
}
[Test]
public void UnwrapsTargetInvocationException_WithInterceptor()
{
BadCommand target = new BadCommand();
IDynamicMock mock = new DynamicMock(typeof (IMethodInterceptor));
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock.Object });
mock.ExpectAndReturn("Invoke", null);
try
{
join.Proceed();
}
catch (NotImplementedException)
{
// this is good, we want this exception to bubble up...
}
catch (TargetInvocationException)
{
Assert.Fail("Must have unwrapped this.");
}
mock.Verify();
}
[Test]
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException()
{
BadCommand target = new BadCommand();
IDynamicMock mock = new DynamicMock(typeof (IMethodInterceptor));
AbstractMethodInvocation join = CreateMethodInvocation(
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock.Object });
mock.ExpectAndThrow("Invoke", new NotImplementedException());
try
{
join.Proceed();
}
catch (NotImplementedException)
{
// this is good, we want this exception to bubble up...
}
catch (TargetInvocationException)
{
Assert.Fail("Must have unwrapped this.");
}
mock.Verify();
}
}
}

View File

@@ -0,0 +1,86 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Text;
using NUnit.Framework;
using Spring.Aop;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects;
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// TestCase for AdvisorAdapterRegistrationManager mechanism.
/// </summary>
/// <author>Dmitriy Kopylenko</author>
/// <author>Simon White (.NET)</author>
[TestFixture]
public class AdvisorAdapterRegistrationTests
{
[Test]
public void AdvisorAdapterRegistrationManagerNotPresentInContext()
{
string configLocation = ReadOnlyXmlTestResource.GetFilePath("withoutBPPContext.xml", typeof(AdvisorAdapterRegistrationTests));
IApplicationContext ctx = new XmlApplicationContext(configLocation);
ITestObject to = (ITestObject) ctx.GetObject("testObject");
// just invoke any method to see if advice fired
try
{
to.ReturnsThis();
Assert.Fail("Should throw UnknownAdviceTypeException");
}
catch (UnknownAdviceTypeException)
{
// expected
Assert.AreEqual(0, GetAdviceImpl(to).InvocationCounter);
}
}
[Test]
public void AdvisorAdapterRegistrationManagerPresentInContext()
{
string configLocation = ReadOnlyXmlTestResource.GetFilePath("withBPPContext.xml", typeof(AdvisorAdapterRegistrationTests));
IApplicationContext ctx = new XmlApplicationContext(configLocation);
ITestObject to = (ITestObject) ctx.GetObject("testObject");
// just invoke any method to see if advice fired
try
{
to.ReturnsThis();
Assert.AreEqual(1, GetAdviceImpl(to).InvocationCounter);
}
catch (UnknownAdviceTypeException)
{
Assert.Fail("Should not throw UnknownAdviceTypeException");
}
}
private SimpleBeforeAdviceImpl GetAdviceImpl(ITestObject to)
{
IAdvised advised = (IAdvised) to;
IAdvisor advisor = advised.Advisors[0];
return (SimpleBeforeAdviceImpl) advisor.Advice;
}
}
}

View File

@@ -0,0 +1,96 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using DotNetMock.Dynamic;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Unit tests for the AfterReturningAdviceInterceptor class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[TestFixture]
public sealed class AfterReturningAdviceInterceptorTests
{
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void PassNullAdviceToCtor()
{
new AfterReturningAdviceInterceptor(null);
}
[Test]
public void IsNotInvokedIfServiceObjectThrowsException()
{
IDynamicMock mockAdvice = new DynamicMock(typeof (IAfterReturningAdvice));
IAfterReturningAdvice afterAdvice = (IAfterReturningAdvice) mockAdvice.Object;
IDynamicMock mockInvocation = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation invocation = (IMethodInvocation) mockInvocation.Object;
mockInvocation.ExpectAndThrow("Proceed", new FormatException(), null);
try
{
AfterReturningAdviceInterceptor interceptor = new AfterReturningAdviceInterceptor(afterAdvice);
interceptor.Invoke(invocation);
Assert.Fail("Must have thrown a FormatException by this point.");
}
catch (FormatException)
{
}
mockAdvice.Verify(); // must not have been called...
mockInvocation.Verify();
}
[Test]
public void JustPassesAfterReturningAdviceExceptionUpWithoutAnyWrapping()
{
IDynamicMock mockAdvice = new DynamicMock(typeof (IAfterReturningAdvice));
IAfterReturningAdvice afterAdvice = (IAfterReturningAdvice) mockAdvice.Object;
mockAdvice.ExpectAndThrow("AfterReturning", new FormatException(), new object[] { null, null, null, null});
IDynamicMock mockInvocation = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation invocation = (IMethodInvocation) mockInvocation.Object;
mockInvocation.ExpectAndReturn("Proceed", null);
try
{
AfterReturningAdviceInterceptor interceptor = new AfterReturningAdviceInterceptor(afterAdvice);
interceptor.Invoke(invocation);
Assert.Fail("Must have thrown a FormatException by this point.");
}
catch (FormatException)
{
}
mockAdvice.Verify();
mockInvocation.Verify();
}
}
}

View File

@@ -0,0 +1,288 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.Web;
using AopAlliance.Intercept;
using DotNetMock.Dynamic;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Unit tests for the ThrowsAdviceInterceptor class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[TestFixture]
public sealed class ThrowsAdviceInterceptorTests
{
[Test]
[ExpectedException(typeof (ArgumentException))]
public void NoHandlerMethods()
{
new ThrowsAdviceInterceptor(new object());
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void PassNullAdviceToCtor()
{
new ThrowsAdviceInterceptor(null);
}
[Test]
public void NotInvoked()
{
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
object ret = new object();
IDynamicMock mc = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation mi = (IMethodInvocation) mc.Object;
mi.Proceed();
mc.SetValue("Proceed", ret);
Assert.AreEqual(ret, ti.Invoke(mi));
Assert.AreEqual(0, th.GetCalls());
mc.Verify();
}
[Test]
public void NoHandlerMethodForThrowable()
{
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
Assert.AreEqual(2, ti.HandlerMethodCount);
Exception ex = new Exception();
IDynamicMock mc = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation mi = (IMethodInvocation) mc.Object;
mi.Proceed();
mc.ExpectAndThrow("Proceed", ex, null);
try
{
ti.Invoke(mi);
Assert.Fail();
}
catch (Exception caught)
{
Assert.AreEqual(ex, caught);
}
Assert.AreEqual(0, th.GetCalls());
mc.Verify();
}
[Test]
public void CorrectHandlerUsed()
{
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
HttpException ex = new HttpException();
IDynamicMock mc = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation mi = (IMethodInvocation) mc.Object;
mi.Proceed();
mc.ExpectAndThrow("Proceed", ex, null);
try
{
ti.Invoke(mi);
Assert.Fail();
}
catch (Exception caught)
{
Assert.AreEqual(ex, caught);
}
Assert.AreEqual(1, th.GetCalls());
Assert.AreEqual(1, th.GetCalls("HttpException"));
mc.Verify();
}
[Test]
public void NestedInnerExceptionsAreNotPickedUp()
{
MyThrowsHandler throwsHandler = new MyThrowsHandler();
ThrowsAdviceInterceptor throwsInterceptor = new ThrowsAdviceInterceptor(throwsHandler);
// nest the exceptions; make sure the advice gets applied because of the inner exception...
Exception exception = new FormatException("Parent", new HttpException("Inner"));
IDynamicMock mockInvocation = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation invocation = (IMethodInvocation) mockInvocation.Object;
invocation.Proceed();
mockInvocation.ExpectAndThrow("Proceed", exception, null);
try
{
throwsInterceptor.Invoke(invocation);
Assert.Fail("Must have failed (by throwing an exception by this point - check the mock).");
}
catch (Exception caught)
{
Assert.AreEqual(exception, caught);
}
Assert.AreEqual(0, throwsHandler.GetCalls(),
"Must NOT have been handled, 'cos the HttpException was wrapped by " +
"another Exception that did not have a handler.");
Assert.AreEqual(0, throwsHandler.GetCalls("HttpException"),
"Similarly, must NOT have been handled, 'cos the HttpException was wrapped by " +
"another Exception that did not have a handler.");
mockInvocation.Verify();
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void ChokesOnHandlerWhereMultipleMethodsAreApplicable()
{
object throwsHandler = new MultipleMethodsAreApplicableThrowsHandler();
new ThrowsAdviceInterceptor(throwsHandler);
}
[Test]
public void CorrectHandlerUsedForSubclass()
{
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
// Extends RemotingException
RemotingTimeoutException ex = new RemotingTimeoutException();
IDynamicMock mc = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation mi = (IMethodInvocation) mc.Object;
mi.Proceed();
mc.ExpectAndThrow("Proceed", ex, null);
try
{
ti.Invoke(mi);
Assert.Fail();
}
catch (Exception caught)
{
Assert.AreEqual(ex, caught);
}
Assert.AreEqual(1, th.GetCalls());
Assert.AreEqual(1, th.GetCalls("RemotingException"));
mc.Verify();
}
[Test]
public void HandlerMethodThrowsException()
{
Exception exception = new Exception();
MyThrowsHandler handler = new ThrowingMyHandler(exception);
ThrowsAdviceInterceptor interceptor = new ThrowsAdviceInterceptor(handler);
// extends RemotingException...
RemotingTimeoutException ex = new RemotingTimeoutException();
IDynamicMock mc = new DynamicMock(typeof (IMethodInvocation));
IMethodInvocation invocation = (IMethodInvocation) mc.Object;
invocation.Proceed();
mc.ExpectAndThrow("Proceed", ex, null);
try
{
interceptor.Invoke(invocation);
Assert.Fail("Should not have reached this point, should have thrown an exception.");
}
catch (Exception caught)
{
Assert.AreEqual(exception, caught);
}
Assert.AreEqual(1, handler.GetCalls());
Assert.AreEqual(1, handler.GetCalls("RemotingException"));
mc.Verify();
}
#region Helper Classes
private sealed class MultipleMethodsAreApplicableThrowsHandler
{
public void AfterThrowing(
MethodInfo method, object[] args, object target, RemotingException ex)
{
}
public void AfterThrowing(RemotingException ex)
{
}
}
private class ThrowingMyHandler : MyThrowsHandler
{
private Exception exception;
public ThrowingMyHandler(Exception ex)
{
this.exception = ex;
}
public override void AfterThrowing(RemotingException ex)
{
base.AfterThrowing(ex);
throw exception;
}
}
public class MyThrowsHandler : MethodCounter, IThrowsAdvice
{
public void AfterThrowing(
MethodInfo m, object[] args, object target, HttpException ex)
{
Count("HttpException");
}
public virtual void AfterThrowing(RemotingException ex)
{
Count("RemotingException");
}
// not valid, wrong number of arguments...
public void AfterThrowing(MethodInfo m, Exception ex)
{
throw new NotSupportedException("Shouldn't be called");
}
}
public interface IEcho
{
int A { get; set; }
int EchoException(int i, Exception t);
}
public class Echo : IEcho
{
private int a;
public int A
{
get { return a; }
set { a = value; }
}
public virtual int EchoException(int i, Exception ex)
{
if (ex != null)
{
throw ex;
}
return i;
}
}
#endregion
}
}

View File

@@ -0,0 +1,45 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework.Adapter
{
/// <summary>
/// Unit tests for the UnknownAdviceTypeException class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: UnknownAdviceTypeExceptionTests.cs,v 1.2 2006/04/09 07:19:05 markpollack Exp $</version>
[TestFixture]
public sealed class UnknownAdviceTypeExceptionTests
{
[Test]
public void InstantiationWithNullAdviceDoesNotThrowAnotherException()
{
new UnknownAdviceTypeException(null);
}
}
}

View File

@@ -0,0 +1,131 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Threading;
using NUnit.Framework;
using Spring.Objects;
using AopAlliance.Intercept;
using Spring.Threading;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the AopContext class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: AopContextTests.cs,v 1.6 2007/05/30 21:06:25 oakinger Exp $</version>
[TestFixture]
public sealed class AopContextTests
{
[SetUp]
public void SetUp()
{
// makes sure the context is always empty before any unit test...
try
{
do
{
AopContext.PopProxy();
} while (true);
}
catch (AopConfigException)
{
}
}
[Test]
[ExpectedException(typeof (AopConfigException))]
public void CurrentProxyChokesIfNoAopProxyIsOnTheStack()
{
AopContext.CurrentProxy.ToString();
}
[Test]
public void CurrentProxyStackJustPeeksItDoesntPop()
{
string foo = "Foo";
AopContext.PushProxy(foo);
object fooref = AopContext.CurrentProxy;
Assert.IsTrue(ReferenceEquals(foo, fooref),
"Not the exact same instance (must be).");
// must not have been popped off the stack by looking at it...
object foorefref = AopContext.CurrentProxy;
Assert.IsTrue(ReferenceEquals(fooref, foorefref),
"Not the exact same instance (must be).");
}
[Test]
[ExpectedException(typeof (AopConfigException))]
public void PopProxyWithNothingOnStack()
{
AopContext.PopProxy();
}
#region CurrentProxyIsThreadSafe
[Test(Description = "http://opensource.atlassian.com/projects/spring/browse/SPRNET-341")]
public void CurrentProxyIsThreadSafe()
{
AsyncTestMethod t1 = new AsyncTestMethod(100, new ThreadStart(ProxyTestObjectAndExposeProxy));
AsyncTestMethod t2 = new AsyncTestMethod(100, new ThreadStart(ProxyTestObjectAndExposeProxy));
t1.Start();
t2.Start();
t1.AssertNoException();
t2.AssertNoException();
}
private void ProxyTestObjectAndExposeProxy()
{
TestObject target = new TestObject();
target.Age = 26;
ProxyFactory pf = new ProxyFactory();
pf.ExposeProxy = true;
pf.Target = target;
pf.AddAdvice(new TestAopContextInterceptor());
ITestObject proxy = pf.GetProxy() as ITestObject;
Assert.IsNotNull(proxy);
Assert.AreEqual(target.Age, proxy.Age, "Incorrect age");
}
private class TestAopContextInterceptor : IMethodInterceptor
{
public object Invoke(IMethodInvocation invocation)
{
Assert.IsNotNull(AopContext.CurrentProxy);
Object ret = invocation.Proceed();
Assert.IsNotNull(AopContext.CurrentProxy);
return ret;
}
}
#endregion
}
}

View File

@@ -0,0 +1,146 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using NUnit.Framework;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Aop.Support;
using Spring.Context.Support;
using Spring.Objects;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Tests for auto proxy creation combined with factory object and circular references.
/// </summary>
/// <author>Erich Eichinger (.NET)</author>
/// <version>$Id: AdvisorAutoProxyCreatorCircularReferencesTests.cs,v 1.4 2007/09/07 01:53:01 markpollack Exp $</version>
[TestFixture]
public class AdvisorAutoProxyCreatorCircularReferencesTests
{
[Test]
public void TestAutoProxyCreation()
{
XmlApplicationContext context = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("advisorAutoProxyCreatorCircularReferencesTests.xml", typeof(AdvisorAutoProxyCreatorCircularReferencesTests)));
// direct deps of AutoProxyCreator are not eligable for proxying
Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("aapc")));
Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("testAdvisor")));
Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("&testObjectFactory")));
Assert.IsFalse(AopUtils.IsAopProxy(context.GetObject("someOtherObject")));
// this one is completely independent
Assert.IsTrue(AopUtils.IsAopProxy(context.GetObject("independentObject")));
// products of the factory created at runtime should be proxied
Assert.IsTrue(AopUtils.IsAopProxy(context.GetObject("testObjectFactory")));
}
}
#region Support Classes
public class TestAdvisor : StaticMethodMatcherPointcutAdvisor
{
private ITestObject testObject;
public ITestObject TestObject
{
get { return this.testObject; }
set { this.testObject = value; }
}
public override bool Matches(MethodInfo method, Type targetType)
{
return true;
}
}
public class SomeOtherObject
{}
public class IndependentObject
{ }
public class TestObjectFactoryObject : IFactoryObject, IInitializingObject
{
private bool initialized = false;
private ITestObject testObject;
private SomeOtherObject someOtherObject;
public TestObjectFactoryObject()
{
}
public SomeOtherObject SomeOtherObject
{
get { return this.someOtherObject; }
set { this.someOtherObject = value; }
}
public object GetObject()
{
// return product only, if factory has been fully initialized!
if (!initialized)
{
return null;
}
else
{
return testObject;
}
}
public Type ObjectType
{
get
{
// return type only if we are ready to deliver our product!
if (!initialized)
{
return null;
}
else
{
return typeof(ITestObject);
}
}
}
public bool IsSingleton
{
get { return true; }
}
public void AfterPropertiesSet()
{
Assert.IsNotNull(someOtherObject);
testObject = new TestObject();
initialized = true;
}
}
#endregion
}

View File

@@ -0,0 +1,121 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using NUnit.Framework;
using Spring.Aop.Framework.DynamicProxy;
using Spring.Context.Support;
using Spring.Objects;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
using Spring.Threading;
#endregion#region License
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Tests for auto proxy creation by advisor recognition.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: AdvisorAutoProxyCreatorTests.cs,v 1.4 2007/08/01 17:56:25 markpollack Exp $</version>
[TestFixture]
public class AdvisorAutoProxyCreatorTests
{
private static string ADVISOR_APC_OBJECT_NAME = "aapc";
protected virtual IObjectFactory ObjectFactory
{
get
{
string configLocation = ReadOnlyXmlTestResource.GetFilePath("advisorAutoProxyCreator.xml", typeof(AdvisorAutoProxyCreatorTests));
return new XmlApplicationContext(configLocation);
}
}
[Test]
public void DefaultExclusionPrefix()
{
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator)ObjectFactory.GetObject(ADVISOR_APC_OBJECT_NAME);
Assert.AreEqual(ADVISOR_APC_OBJECT_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR, aapc.AdvisorObjectNamePrefix);
Assert.IsFalse(aapc.UsePrefix);
}
/// <summary>
/// No pointcuts match the methods on NoSetterProperties therefore
/// there should be proxying.
/// </summary>
[Test]
public void NoProxy()
{
IObjectFactory of = ObjectFactory;
object o = of.GetObject("noSetterPropertiesObject");
Assert.IsFalse(AopUtils.IsAopProxy(o));
}
/// <summary>
/// A pointcut matches the property (i.e. method set_Age) on TestObject
/// therefore there should be proxying.
/// </summary>
[Test]
public void HasProxy()
{
IObjectFactory of = ObjectFactory;
object o = of.GetObject("testObject");
Assert.IsTrue(AopUtils.IsAopProxy(o), "Expected TestObject to be proxied");
}
[Test]
public void RegexpApplied()
{
IObjectFactory of = ObjectFactory;
ITestObject testObject = (ITestObject)of.GetObject("testObject");
MethodCounter counter = (MethodCounter)of.GetObject("CountingAdvice");
Assert.AreEqual(0,counter.GetCalls());
testObject.Spouse = new TestObject("Daniela", 23);
Assert.AreEqual(0, counter.GetCalls());
testObject.Name = "foo";
Assert.AreEqual(1, counter.GetCalls());
}
[Test]
public void SetLTCValue()
{
IObjectFactory of = ObjectFactory;
ITestObject testObject = (ITestObject)of.GetObject("testObject");
OrderedLogicalThreadContextCheckAdvisor orderedBeforeLTCSet =
(OrderedLogicalThreadContextCheckAdvisor)of.GetObject("orderedBeforeLTCSet");
Assert.AreEqual(0, orderedBeforeLTCSet.CountingBeforeAdvice.GetCalls());
Assert.IsNull(LogicalThreadContext.GetData(LogicalThreadContextAdvice.ORDERING_SLOT));
Assert.AreEqual(4, testObject.Age, "Initial value of age for test object is not correct.");
int newAge = 5;
testObject.Age = newAge;
Assert.AreEqual(1, orderedBeforeLTCSet.CountingBeforeAdvice.GetCalls());
Assert.AreEqual(newAge, testObject.Age, "Assigned value of age for test object is not correct.");
Assert.IsNotNull(LogicalThreadContext.GetData(LogicalThreadContextAdvice.ORDERING_SLOT));
}
}
}

View File

@@ -0,0 +1,82 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
using System;
using Spring.Objects;
using Spring.Objects.Factory;
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// This is simple implementation of IFactoryObject that creates a TestObject.
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: CreatesTestObject.cs,v 1.1 2007/09/07 01:53:02 markpollack Exp $</version>
public class CreatesTestObject : IFactoryObject, IInitializingObject
{
private bool initialized = false;
private ITestObject testObject;
public CreatesTestObject()
{
}
public object GetObject()
{
// return product only, if factory has been fully initialized!
if (!initialized)
{
return null;
}
else
{
return testObject;
}
}
public Type ObjectType
{
get
{
// return type only if we are ready to deliver our product!
if (!initialized)
{
return null;
}
else
{
return typeof(ITestObject);
}
}
}
public bool IsSingleton
{
get { return true; }
}
public void AfterPropertiesSet()
{
testObject = new TestObject();
initialized = true;
}
}
}

View File

@@ -0,0 +1,39 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System.Reflection;
using Spring.Threading;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
public class LogicalThreadContextAdvice : IMethodBeforeAdvice
{
public static string ORDERING_SLOT = "ordering_slot";
public void Before(MethodInfo method, object[] args, object target)
{
LogicalThreadContext.SetData(ORDERING_SLOT, new object());
}
}
}

View File

@@ -0,0 +1,44 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* 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.
*/
#endregion
using System.Text;
namespace Spring.Aop.Framework.AutoProxy
{
public class NoSetterProperties
{
public string FancyName
{
get
{
return "Joe Suave";
}
}
public void DoWork()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; i++)
{
sb.Append(i);
}
}
}
}

View File

@@ -0,0 +1,162 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using NUnit.Framework;
using Spring.Aop.Interceptor;
using Spring.Context;
using Spring.Context.Support;
using Spring.Objects;
using Spring.Objects.Factory.Xml;
#endregion#region License
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Tests for ObjectNameAutoProxyCreator functionality
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: ObjectNameAutoProxyCreatorTests.cs,v 1.6 2007/09/07 01:53:01 markpollack Exp $</version>
[TestFixture]
public class ObjectNameAutoProxyCreatorTests
{
private IApplicationContext ctx;
[SetUp]
public void SetUp()
{
string configLocation =
ReadOnlyXmlTestResource.GetFilePath("objectNameAutoProxyCreatorTests.xml",
typeof (ObjectNameAutoProxyCreatorTests));
ctx = new XmlApplicationContext(configLocation);
}
[Test]
public void NoProxy()
{
ITestObject testObject = (ITestObject) ctx.GetObject("noproxy");
Assert.IsFalse(AopUtils.IsAopProxy(testObject), testObject + " is not an AOP proxy");
Assert.AreEqual("noproxy", testObject.Name);
}
[Test]
public void ProxyWithExactNameMatch()
{
ITestObject testObject = (ITestObject) ctx.GetObject("testObject");
ProxyAssertions(testObject, 1);
Assert.AreEqual("SimpleTestObject", testObject.Name);
}
[Test]
public void ProxyWithDoubleProxying()
{
ITestObject testObject = (ITestObject)ctx.GetObject("doubleProxy");
ProxyAssertions(testObject, 2);
Assert.AreEqual("doubleProxy", testObject.Name);
}
[Test]
public void ProxyWithWildcardMatchSuffix()
{
ITestObject testObject = (ITestObject) ctx.GetObject("SmithFamilyMember");
ProxyAssertions(testObject, 1);
Assert.AreEqual("John Smith", testObject.Name);
}
[Test]
public void ProxyWithTwoWildcardsMatch()
{
ITestObject testObject = (ITestObject)ctx.GetObject("twoWildcardsTestObject");
ProxyAssertions(testObject, 1);
Assert.AreEqual("Damjan Tomic", testObject.Name);
}
[Test]
public void AppliesToCreatedObjectsNotFactoryObject()
{
ITestObject testObject = (ITestObject) ctx.GetObject("factoryObject");
ProxyAssertions(testObject, 1);
}
[Test]
public void DecoratorProxyWithWildcardMatch()
{
ITestObject testObject = (ITestObject)ctx.GetObject("decoratorProxy");
DecoratorProxyAssertions(testObject);
Assert.AreEqual("decoratorProxy", testObject.Name);
}
[Test]
public void FrozenProxy()
{
ITestObject testObject = (ITestObject)ctx.GetObject("frozen");
Assert.IsTrue( ((IAdvised)testObject).IsFrozen);
}
[Test]
public void Introduction()
{
object obj = ctx.GetObject("introductionUsingDecorator");
Assert.IsNotNull(obj as IIsModified);
ITestObject testObject = (ITestObject) obj;
NopInterceptor nop = (NopInterceptor)ctx.GetObject("introductionNopInterceptor");
Assert.AreEqual(0, nop.Count);
Assert.IsTrue(AopUtils.IsCompositionAopProxy(testObject), testObject + " is not an Composition AOP Proxy");
int age = 5;
testObject.Age = age;
Assert.AreEqual(age, testObject.Age);
Assert.IsNotNull(testObject as IIsModified);
Assert.IsTrue(((IIsModified)testObject).IsModified);
Assert.AreEqual(3, nop.Count);
Assert.AreEqual("introductionUsingDecorator", testObject.Name);
}
private void ProxyAssertions(ITestObject testObject, int nopInterceptorCount)
{
NopInterceptor nop = (NopInterceptor) ctx.GetObject("nopInterceptor");
Assert.AreEqual(0, nop.Count);
Assert.IsTrue(AopUtils.IsCompositionAopProxy(testObject), testObject + " is not an AOP Proxy");
int age = 5;
testObject.Age = age;
Assert.AreEqual(age, testObject.Age);
Assert.AreEqual(2 * nopInterceptorCount, nop.Count);
}
private void DecoratorProxyAssertions(ITestObject testObject)
{
CountingBeforeAdvice cba = (CountingBeforeAdvice) ctx.GetObject("countingBeforeAdvice");
NopInterceptor nop = (NopInterceptor)ctx.GetObject("nopInterceptor");
Assert.AreEqual(0, cba.GetCalls());
Assert.AreEqual(0, nop.Count);
Assert.IsTrue(AopUtils.IsDecoratorAopProxy(testObject), testObject + " is not an AOP Proxy");
//extra advice calls are due to test IsDecoratorAopProxy and call to .GetType in impl
Assert.AreEqual(1, nop.Count);
Assert.AreEqual(1, cba.GetCalls());
int age = 5;
testObject.Age = age;
Assert.AreEqual(age, testObject.Age);
Assert.AreEqual(3, nop.Count);
Assert.AreEqual(3, cba.GetCalls());
}
}
}

View File

@@ -0,0 +1,110 @@
#region License
/*
* Copyright <20> 2002-2006 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Aop.Support;
using Spring.Objects.Factory;
using Spring.Threading;
#endregion
namespace Spring.Aop.Framework.AutoProxy
{
/// <summary>
/// Before advisor that allow us to manipulate ordering to check
/// that superclass sorting works correctly.
/// </summary>
/// <remarks>
/// It doesn't actually do anything except count
/// method invocations and check for presence of a value in the
/// LogicalThreadContext.
/// </remarks>
/// <author>Mark Pollack (.NET)</author>
/// <version>$Id: OrderedLogicalThreadContextCheckAdvisor.cs,v 1.2 2006/09/15 21:25:17 markpollack Exp $</version>
public class OrderedLogicalThreadContextCheckAdvisor : StaticMethodMatcherPointcutAdvisor, IInitializingObject
{
public virtual bool RequireLTCHasValue
{
get { return requireLtcHasValue; }
set { requireLtcHasValue = value; }
}
public virtual CountingBeforeAdvice CountingBeforeAdvice
{
get { return (CountingBeforeAdvice) Advice; }
}
/// <summary> Should we insist on the presence of a transaction attribute or refuse to accept one?</summary>
private bool requireLtcHasValue = false;
public virtual void AfterPropertiesSet()
{
Advice = new LTCCountingBeforeAdvice(this);
}
public override bool Matches(MethodInfo method, Type targetClass)
{
return method.Name.StartsWith("set_Age");
}
private class LTCCountingBeforeAdvice : CountingBeforeAdvice
{
private OrderedLogicalThreadContextCheckAdvisor enclosingInstance;
public LTCCountingBeforeAdvice(OrderedLogicalThreadContextCheckAdvisor enclosingInstance)
{
this.enclosingInstance = enclosingInstance;
}
public OrderedLogicalThreadContextCheckAdvisor EnclosingInstance
{
get { return enclosingInstance; }
}
public override void Before(MethodInfo method, object[] args, object target)
{
// do check for presence of LTC value....
if (EnclosingInstance.requireLtcHasValue)
{
if (LogicalThreadContext.GetData(LogicalThreadContextAdvice.ORDERING_SLOT) == null)
{
throw new SystemException("Expected object in LTC ORDERING_SLOT");
}
}
else
{
if (LogicalThreadContext.GetData(LogicalThreadContextAdvice.ORDERING_SLOT) != null)
{
throw new SystemException("Expected no object in LTC ORDERING_SLOT");
}
}
base.Before(method, args, target);
}
}
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd"
default-autowire="byType"
>
<description>
Reproduces a problem with AutoProxyCreators, IFactoryObjects,
circular dependencies and a certain order of object definitions
</description>
<!-- start instantiating a factoryobject -->
<object id="testObjectFactory" type="Spring.Aop.Framework.AutoProxy.TestObjectFactoryObject, Spring.Aop.Tests">
<property name="SomeOtherObject" ref="someOtherObject" />
</object>
<!-- note that testAdvisor is defined *after* 'testObjectFactory'! -->
<object id="testAdvisor" type="Spring.Aop.Framework.AutoProxy.TestAdvisor, Spring.Aop.Tests">
<property name="testObject" ref="testObjectFactory" /> <!-- ref on testObjectFactory closes the dep circle -->
</object>
<!--
This object can be instantiated without any additional deps
- which causes the AutoProxyCreator to do its job
-->
<object id="someOtherObject" type="Spring.Aop.Framework.AutoProxy.SomeOtherObject, Spring.Aop.Tests" />
<!-- this object is not a direct or indirect dependency of aapc -->
<object id="independentObject" type="Spring.Aop.Framework.AutoProxy.IndependentObject, Spring.Aop.Tests" />
<!-- match everything -->
<object id="aapc" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop"/>
</objects>

View File

@@ -0,0 +1,43 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Aop.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Simple after returning advice example that we can use for counting checks.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: CountingAfterReturningAdvice.cs,v 1.2 2007/03/16 04:01:47 aseovic Exp $</version>
[Serializable]
public class CountingAfterReturningAdvice : MethodCounter, IAfterReturningAdvice
{
public void AfterReturning(object returnValue, MethodInfo method, object[] args, object target)
{
Count(method);
}
}
}

View File

@@ -0,0 +1,43 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Aop.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Simple before advice example that we can use for counting checks.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: CountingBeforeAdvice.cs,v 1.6 2007/03/16 04:01:47 aseovic Exp $</version>
[Serializable]
public class CountingBeforeAdvice : MethodCounter, IMethodBeforeAdvice
{
public virtual void Before(MethodInfo method, object[] args, object target)
{
Count(method);
}
}
}

View File

@@ -0,0 +1,55 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Aop.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Advice object that implements <i>multiple</i> Advice interfaces.
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: CountingMultiAdvice.cs,v 1.1 2006/08/10 18:45:57 bbaia Exp $</version>
public class CountingMultiAdvice : MethodCounter,
IMethodBeforeAdvice, IAfterReturningAdvice, IThrowsAdvice
{
public void Before(MethodInfo method, object[] args, object target)
{
Count(method);
}
public void AfterReturning(object returnValue, MethodInfo method, object[] args, object target)
{
Count(method);
}
public void AfterThrowing(ApplicationException aex)
{
Count(aex.GetType().Name);
}
}
}

View File

@@ -0,0 +1,50 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Aop.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Simple throw advice example that we can use for counting checks.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: CountingThrowsAdvice.cs,v 1.2 2007/03/16 04:01:47 aseovic Exp $</version>
[Serializable]
public class CountingThrowsAdvice : MethodCounter, IThrowsAdvice
{
public void AfterThrowing(Exception ex)
{
Count(ex.GetType().Name);
}
public void AfterThrowing(ApplicationException aex)
{
Count(aex.GetType().Name);
}
}
}

View File

@@ -0,0 +1,46 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Collections;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the DynamicMethodInvocation class.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: DynamicMethodInvocationTests.cs,v 1.2 2008/02/06 18:29:05 bbaia Exp $</version>
[TestFixture]
public class DynamicMethodInvocationTests : AbstractMethodInvocationTests
{
protected override AbstractMethodInvocation CreateMethodInvocation(object proxy, object target, MethodInfo method, MethodInfo onProxyMethod, object[] arguments, Type targetType, IList interceptors)
{
return new DynamicMethodInvocation(proxy, target, method, onProxyMethod, arguments, targetType, interceptors);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,223 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Aop.Framework;
using Spring.Aop.Interceptor;
using Spring.Aop.Support;
using Spring.Collections;
using Spring.Objects;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Unit tests for the AopUtils class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: AopUtilsTests.cs,v 1.2 2008/03/21 10:49:37 oakinger Exp $</version>
[TestFixture]
public sealed class AopUtilsTests
{
[Test]
public void GetAllInterfaces()
{
DerivedTestObject testObject = new DerivedTestObject();
IList interfaces = new ArrayList(testObject.GetType().GetInterfaces());
Assert.AreEqual(8, interfaces.Count, "Incorrect number of interfaces");
Assert.IsTrue(interfaces.Contains(typeof (ITestObject)), "Does not contain ITestObject");
Assert.IsTrue(interfaces.Contains(typeof (IOther)), "Does not contain IOther");
}
[Test]
public void PointcutCanNeverApply()
{
IPointcut pointcut = new NeverMatchesPointcut();
Assert.IsFalse(AopUtils.CanApply(pointcut, typeof (Object), null));
}
[Test]
public void PointcutAlwaysApplies()
{
Assert.IsTrue(AopUtils.CanApply(new DefaultPointcutAdvisor(new NopInterceptor()), typeof (Object), null));
Assert.IsTrue(AopUtils.CanApply(new DefaultPointcutAdvisor(new NopInterceptor()), typeof (TestObject), new Type[] {typeof (ITestObject)}));
}
[Test]
public void PointcutAppliesToOneMethodOnObject()
{
IPointcut pointcut = new OneMethodTestPointcut();
Assert.IsTrue(AopUtils.CanApply(pointcut, typeof (object), null),
"Must return true if we're not proxying interfaces.");
Assert.IsFalse(AopUtils.CanApply(pointcut, typeof (object),
new Type[] {typeof (ITestObject)}),
"Must return false if we're proxying interfaces.");
}
[Test]
public void PointcutAppliesToOneInterfaceOfSeveral()
{
IPointcut pointcut = new OneInterfaceTestPointcut();
// Will return true if we're proxying interfaces including ITestObject
Assert.IsTrue(AopUtils.CanApply(pointcut, typeof (TestObject), new Type[] {typeof (ITestObject), typeof (IComparable)}));
// Will return true if we're proxying interfaces including ITestObject
Assert.IsFalse(AopUtils.CanApply(pointcut, typeof (TestObject), new Type[] {typeof (IComparable)}));
}
[Test]
public void CanApplyWithAdvisorYieldsTrueIfAdvisorIsNotKnownAdvisorType()
{
IAdvisor advisor = (IAdvisor) new DynamicMock(typeof (IAdvisor)).Object;
Assert.IsTrue(AopUtils.CanApply(advisor, typeof (TestObject), null));
}
[Test]
public void CanApplyWithAdvisorYieldsTrueIfAdvisorIsNull()
{
Assert.IsTrue(AopUtils.CanApply((IAdvisor) null, typeof (TestObject), null));
}
[Test]
public void GetAllInterfacesWithNull()
{
Type[] interfaces = AopUtils.GetAllInterfaces(null);
Assert.IsNotNull(interfaces,
"Must never return null, even if the argument is null.");
Assert.AreEqual(0, interfaces.Length,
"Must return an empty array is the argument is null.");
}
[Test]
public void GetAllInterfacesWithObjectThatDoesntImpementAnything()
{
ImplementsNothing instance = new ImplementsNothing();
Type[] interfaces = AopUtils.GetAllInterfaces(instance);
Assert.IsNotNull(interfaces,
"Must never return null, even if the argument doesn't implement any interfaces.");
Assert.AreEqual(0, interfaces.Length,
"Must return an empty array is the argument doesn't implement any interfaces.");
}
[Test]
public void GetAllInterfacesSunnyDay()
{
ImplementsTwoInterfaces instance = new ImplementsTwoInterfaces();
Type[] interfaces = AopUtils.GetAllInterfaces(instance);
Assert.IsNotNull(interfaces, "Must never return null.");
Assert.AreEqual(2, interfaces.Length,
"Implements two interfaces.");
ISet ifaces = new ListSet(interfaces);
Assert.IsTrue(
ifaces.ContainsAll(
new Type [] {typeof(IDisposable), typeof(ICloneable)}),
"Did not find the correct interfaces.");
}
[Test]
public void GetAllInterfacesWithObjectThatInheritsInterfaces()
{
InheritsOneInterface instance = new InheritsOneInterface();
Type[] interfaces = AopUtils.GetAllInterfaces(instance);
Assert.IsNotNull(interfaces, "Must never return null.");
Assert.AreEqual(1, interfaces.Length,
"Inherited one interface from superclass.");
Type iface = interfaces[0];
Assert.IsNotNull(iface, "Returned interface cannot be null.");
Assert.AreEqual(typeof(IDisposable), iface, "Wrong interface returned.");
}
[Test]
public void CanApplyWithTrueIntroductionAdvisor()
{
DynamicMock mockIntroAdvisor = new DynamicMock(typeof (IIntroductionAdvisor));
mockIntroAdvisor.ExpectAndReturn("TypeFilter", TrueTypeFilter.True);
IAdvisor advisor = (IAdvisor) mockIntroAdvisor.Object;
Assert.IsTrue(AopUtils.CanApply(advisor, typeof (TestObject), null));
mockIntroAdvisor.Verify();
}
#region Helper Classes
private sealed class OneMethodTestPointcut : StaticMethodMatcherPointcut
{
public override bool Matches(MethodInfo m, Type targetClass)
{
return m.Name.Equals("GetHashCode");
}
}
private sealed class OneInterfaceTestPointcut : StaticMethodMatcherPointcut
{
public override bool Matches(MethodInfo m, Type targetClass)
{
return m.Name.Equals("ReturnsThis");
}
}
private sealed class NeverMatchesPointcut : StaticMethodMatcherPointcut
{
public override bool Matches(MethodInfo m, Type targetClass)
{
return false;
}
}
private sealed class ImplementsNothing
{
}
private abstract class ImplementsOneInterface : IDisposable
{
public void Dispose()
{
throw new NotImplementedException();
}
}
private sealed class InheritsOneInterface : ImplementsOneInterface
{
}
private sealed class ImplementsTwoInterfaces : IDisposable, ICloneable
{
public void Dispose()
{
throw new NotImplementedException();
}
public object Clone()
{
throw new NotImplementedException();
}
}
#endregion
}
}

View File

@@ -0,0 +1,181 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Collections;
using NUnit.Framework;
using Spring.Objects;
using Spring.Aop.Support;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Unit tests for the CachedAopProxyFactoryTests class.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: CachedAopProxyFactoryTests.cs,v 1.1 2007/08/04 01:20:11 bbaia Exp $</version>
[TestFixture]
public sealed class CachedAopProxyFactoryTests : DefaultAopProxyFactoryTests
{
protected override IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
{
IAopProxyFactory apf = new CachedAopProxyFactory();
return apf.CreateAopProxy(advisedSupport);
}
[SetUp]
public void SetUp()
{
// Clear Aop proxy type cache
Assert.IsNotNull(TypeCacheField);
TypeCacheField.SetValue(null, new Hashtable());
}
[Test]
public void DoesNotCacheWithDifferentBaseType()
{
// Decorated-based proxy (BaseType == TargetType)
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.ProxyTargetType = true;
advisedSupport.Target = new TestObject();
CreateAopProxy(advisedSupport);
// Composition-based proxy (BaseType = BaseCompositionAopProxy)
advisedSupport = new AdvisedSupport();
advisedSupport.ProxyTargetType = false;
advisedSupport.Target = new TestObject();
CreateAopProxy(advisedSupport);
AssertAopProxyTypeCacheCount(2);
}
[Test]
public void DoesNotCacheWithDifferentTargetType()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.Target = new BadCommand();
CreateAopProxy(advisedSupport);
advisedSupport = new AdvisedSupport();
advisedSupport.Target = new GoodCommand();
CreateAopProxy(advisedSupport);
AssertAopProxyTypeCacheCount(2);
}
[Test]
public void DoesNotCacheWithDifferentInterfaces()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.Target = new TestObject();
CreateAopProxy(advisedSupport);
advisedSupport = new AdvisedSupport();
advisedSupport.Target = new TestObject();
advisedSupport.AddInterface(typeof(IPerson));
CreateAopProxy(advisedSupport);
AssertAopProxyTypeCacheCount(2);
// Same with Introductions
advisedSupport = new AdvisedSupport();
advisedSupport.Target = new TestObject();
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
ti.TimeStamp = new DateTime(666L);
IIntroductionAdvisor introduction = new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped));
advisedSupport.AddIntroduction(introduction);
CreateAopProxy(advisedSupport);
AssertAopProxyTypeCacheCount(3);
}
[Test]
public void DoesCacheWithTwoDecoratorBasedProxy()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.ProxyTargetType = true;
advisedSupport.Target = new TestObject();
CreateAopProxy(advisedSupport);
advisedSupport = new AdvisedSupport();
advisedSupport.ProxyTargetType = true;
advisedSupport.Target = new TestObject();
CreateAopProxy(advisedSupport);
AssertAopProxyTypeCacheCount(1);
}
[Test]
public void DoesCacheWithTwoCompositionBasedProxy()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.Target = new TestObject();
CreateAopProxy(advisedSupport);
advisedSupport = new AdvisedSupport();
advisedSupport.Target = 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);
}
#region Helper classes definitions
public interface ICommand
{
void Execute();
}
public sealed class BadCommand : ICommand
{
public void Execute()
{
throw new NotImplementedException();
}
}
public sealed class GoodCommand : ICommand
{
public void Execute()
{
}
}
#endregion
}
}

View File

@@ -0,0 +1,114 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Objects;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Additional and overridden tests for the composition-based proxy.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: CompositionAopProxyTests.cs,v 1.4 2007/08/02 04:15:37 markpollack Exp $</version>
[TestFixture]
public class CompositionAopProxyTests : AbstractAopProxyTests
{
protected override object CreateProxy(AdvisedSupport advisedSupport)
{
Assert.IsFalse(advisedSupport.ProxyTargetType, "Not forcible decorator-based proxy");
object proxy = CreateAopProxy(advisedSupport).GetProxy();
Assert.IsTrue(AopUtils.IsCompositionAopProxy(proxy), "Should be a composition-based proxy: " + proxy.GetType());
return proxy;
}
protected override Type CreateAopProxyType(AdvisedSupport advisedSupport)
{
return new CompositionAopProxyTypeBuilder(advisedSupport).BuildProxyType();
}
[Test]
public void ProxyIsJustInterface()
{
TestObject target = new TestObject();
target.Age = 32;
AdvisedSupport advised = new AdvisedSupport();
advised.Target = target;
advised.Interfaces = new Type[] { typeof(ITestObject) };
object proxy = CreateProxy(advised);
Assert.IsTrue(proxy is ITestObject);
Assert.IsFalse(proxy is TestObject);
}
#region ReturnsThisWhenProxyIsIncompatible
[Test]
public void ReturnsThisWhenProxyIsIncompatible()
{
FooBar obj = new FooBar();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = obj;
advised.Interfaces = new Type[] { typeof(IFoo) };
IFoo proxy = (IFoo)CreateProxy(advised);
Assert.AreSame(obj, proxy.GetBarThis(),
"Target should be returned when return types are incompatible");
Assert.AreSame(proxy, proxy.GetFooThis(),
"Proxy should be returned when return types are compatible");
}
public interface IFoo
{
IBar GetBarThis();
IFoo GetFooThis();
}
public interface IBar
{
}
public class FooBar : IFoo, IBar
{
public IBar GetBarThis()
{
return this;
}
public IFoo GetFooThis()
{
return this;
}
}
#endregion
}
}

View File

@@ -0,0 +1,351 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using NUnit.Framework;
using Spring.Aop.Interceptor;
using Spring.Objects;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Additional and overridden tests for the decorator-based proxy.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Juergen Hoeller</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: DecoratorAopProxyTests.cs,v 1.6 2008/05/21 08:04:52 bbaia Exp $</version>
[TestFixture]
public class DecoratorAopProxyTests : AbstractAopProxyTests
{
protected override object CreateProxy(AdvisedSupport advisedSupport)
{
advisedSupport.ProxyTargetType = true;
object proxy = CreateAopProxy(advisedSupport).GetProxy();
Assert.IsTrue(AopUtils.IsDecoratorAopProxy(proxy));
return proxy;
}
protected override Type CreateAopProxyType(AdvisedSupport advisedSupport)
{
return new DecoratorAopProxyTypeBuilder(advisedSupport).BuildProxyType();
}
[Test]
[ExpectedException(typeof(AopConfigException))]
public void CannotProxySealedClass()
{
SealedTestObject target = new SealedTestObject();
mockTargetSource.SetTarget(target);
AdvisedSupport advised = new AdvisedSupport(new Type[] { });
advised.TargetSource = mockTargetSource;
IAopProxy aop = CreateAopProxy(advised);
}
[Test]
[ExpectedException(typeof(AopConfigException))]
public void CannotProxyNonPublicClass()
{
NonPublicTestObject target = new NonPublicTestObject();
mockTargetSource.SetTarget(target);
AdvisedSupport advised = new AdvisedSupport(new Type[] { });
advised.TargetSource = mockTargetSource;
IAopProxy aop = CreateAopProxy(advised);
}
[Test]
public void ProxyCanBeClassAndInterface()
{
TestObject target = new TestObject();
target.Age = 32;
mockTargetSource.SetTarget(target);
AdvisedSupport advised = new AdvisedSupport();
advised.TargetSource = mockTargetSource;
IAopProxy aop = CreateAopProxy(advised);
object proxy = aop.GetProxy();
Assert.IsTrue(AopUtils.IsDecoratorAopProxy(proxy), "Should be a decorator-based proxy");
Assert.IsTrue(proxy is ITestObject);
Assert.IsTrue(proxy is TestObject);
ITestObject itb = (ITestObject)proxy;
Assert.AreEqual(32, itb.Age, "Incorrect age");
TestObject tb = (TestObject)proxy;
Assert.AreEqual(32, tb.Age, "Incorrect age");
}
[Test]
public void InterceptVirtualMethod()
{
DoesNotImplementInterfaceTestObject target = new DoesNotImplementInterfaceTestObject();
target.Name = "Bruno";
mockTargetSource.SetTarget(target);
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.TargetSource = mockTargetSource;
advised.AddAdvice(ni);
DoesNotImplementInterfaceTestObject proxy = CreateProxy(advised) as DoesNotImplementInterfaceTestObject;
Assert.IsNotNull(proxy);
Assert.AreEqual(target.Name, proxy.Name, "Incorrect name");
proxy.Name = "Bruno Baia";
Assert.AreEqual("Bruno Baia", proxy.Name, "Incorrect name");
Assert.AreEqual(3, ni.Count);
}
[Test]
public void CannotInterceptFinalMethodThatDoesNotBelongToAnInterface()
{
DoesNotImplementInterfaceTestObject target = new DoesNotImplementInterfaceTestObject();
target.Location = "Paris";
mockTargetSource.SetTarget(target);
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.TargetSource = mockTargetSource;
advised.AddAdvice(ni);
DoesNotImplementInterfaceTestObject proxy = CreateProxy(advised) as DoesNotImplementInterfaceTestObject;
Assert.IsNotNull(proxy);
// Location is final and doesn't belong to an interface so can't proxy.
// method call goes directly to the proxy
// and will not have access to the valid _location field
Assert.IsNull(proxy.Location);
Assert.AreEqual(0, ni.Count);
}
[Test]
public void InterceptFinalMethodThatBelongsToAnInterface()
{
TestObject target = new TestObject();
target.Name = "Bruno";
mockTargetSource.SetTarget(target);
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.TargetSource = mockTargetSource;
advised.AddAdvice(ni);
// Cast to the interface that method belongs to
ITestObject proxy = CreateProxy(advised) as ITestObject;
Assert.IsNotNull(proxy);
Assert.AreEqual(target.Name, proxy.Name, "Incorrect name");
proxy.Name = "Bruno Baia";
Assert.AreEqual("Bruno Baia", proxy.Name, "Incorrect name");
Assert.AreEqual(3, ni.Count);
}
[Test]
[ExpectedException(typeof(AopConfigException), "Cannot create decorator-based IAopProxy for a non visible class [Spring.Aop.Framework.DynamicProxy.AbstractAopProxyTests+InternalRefOutTestObject]")]
public override void ProxyMethodWithRefOutParametersWithStandardReflection()
{
base.ProxyMethodWithRefOutParametersWithStandardReflection();
}
#if NET_2_0
[Test]
[ExpectedException(typeof(AopConfigException), "Cannot create decorator-based IAopProxy for a non visible class [Spring.Aop.Framework.DynamicProxy.AbstractAopProxyTests+InternalRefOutGenericTestObject]")]
public override void ProxyGenericMethodWithRefOutParametersWithStandardReflection()
{
base.ProxyGenericMethodWithRefOutParametersWithStandardReflection();
}
#endif
#region Attributes
[Test]
public void ProxyTargetVirtualMethodAttributes()
{
MarkerClass target = new MarkerClass();
AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IMarkerInterface) });
advised.Target = target;
IAopProxy aopProxy = CreateAopProxy(advised);
object proxy = aopProxy.GetProxy();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to GetProxy() was null.");
MethodInfo method = proxy.GetType().GetMethod("MarkerVirtualMethod");
Assert.IsNotNull(method);
object[] attrs = method.GetCustomAttributes(false);
Assert.IsNotNull(attrs, "Should have 1 attribute applied to the target method.");
Assert.AreEqual(1, attrs.Length, "Should have 1 attribute applied to the target method.");
Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the target method.");
}
[Test]
public void DoesNotProxyTargetVirtualMethodAttributesWithProxyTargetAttributesEqualsFalse()
{
MarkerClass target = new MarkerClass();
AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IMarkerInterface) });
advised.Target = target;
advised.ProxyTargetAttributes = false;
IAopProxy aopProxy = CreateAopProxy(advised);
object proxy = aopProxy.GetProxy();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to GetProxy() was null.");
MethodInfo method = proxy.GetType().GetMethod("MarkerVirtualMethod");
Assert.IsNotNull(method);
object[] attrs = method.GetCustomAttributes(false);
Assert.IsNotNull(attrs);
Assert.AreEqual(0, attrs.Length, "Should not have attribute applied to the target method.");
}
[Test]
public void ProxyTargetVirtualMethodParameterAttributes()
{
MarkerClass target = new MarkerClass();
AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IMarkerInterface) });
advised.Target = target;
IAopProxy aopProxy = CreateAopProxy(advised);
object proxy = aopProxy.GetProxy();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to GetProxy() was null.");
MethodInfo method = proxy.GetType().GetMethod("MarkerVirtualMethod");
Assert.IsNotNull(method);
object[] attrs = method.GetParameters()[1].GetCustomAttributes(false);
Assert.IsNotNull(attrs, "Should have had 1 attribute applied to the method's parameter.");
Assert.AreEqual(1, attrs.Length, "Should have had 1 attribute applied to the method's parameter.");
Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's parameter.");
}
[Test]
public void DoesNotProxyTargetVirtualMethodParameterAttributesWithProxyTargetAttributesEqualsFalse()
{
MarkerClass target = new MarkerClass();
AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IMarkerInterface) });
advised.Target = target;
advised.ProxyTargetAttributes = false;
IAopProxy aopProxy = CreateAopProxy(advised);
object proxy = aopProxy.GetProxy();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to GetProxy() was null.");
MethodInfo method = proxy.GetType().GetMethod("MarkerVirtualMethod");
Assert.IsNotNull(method);
object[] attrs = method.GetParameters()[1].GetCustomAttributes(false);
Assert.IsNotNull(attrs);
Assert.AreEqual(0, attrs.Length, "Should not have attribute applied to the method's parameter.");
}
#if NET_2_0
[Test]
public void ProxyTargetVirtualMethodReturnValueAttributes()
{
MarkerClass target = new MarkerClass();
AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IMarkerInterface) });
advised.Target = target;
IAopProxy aopProxy = CreateAopProxy(advised);
object proxy = aopProxy.GetProxy();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to GetProxy() was null.");
MethodInfo method = proxy.GetType().GetMethod("MarkerVirtualMethod");
Assert.IsNotNull(method);
object[] attrs = method.ReturnTypeCustomAttributes.GetCustomAttributes(false);
Assert.IsNotNull(attrs, "Should have had 1 attribute applied to the method's return value.");
Assert.AreEqual(1, attrs.Length, "Should have had 1 attribute applied to the method's return value.");
Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's return value.");
}
[Test]
public void DoesNotProxyTargetVirtualMethodReturnValueAttributesWithProxyTargetAttributesEqualsFalse()
{
MarkerClass target = new MarkerClass();
AdvisedSupport advised = new AdvisedSupport(new Type[] { typeof(IMarkerInterface) });
advised.Target = target;
advised.ProxyTargetAttributes = false;
IAopProxy aopProxy = CreateAopProxy(advised);
object proxy = aopProxy.GetProxy();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to GetProxy() was null.");
MethodInfo method = proxy.GetType().GetMethod("MarkerVirtualMethod");
Assert.IsNotNull(method);
object[] attrs = method.ReturnTypeCustomAttributes.GetCustomAttributes(false);
Assert.IsNotNull(attrs);
Assert.AreEqual(0, attrs.Length, "Should not have attribute applied to the method's return value.");
}
#endif
#endregion
#region Helper classes definitions
internal class NonPublicTestObject
{
}
public sealed class SealedTestObject
{
}
public class DoesNotImplementInterfaceTestObject
{
// virtual property
private string _name;
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
// final method
private string _location;
public string Location
{
get { return _location; }
set { _location = value; }
}
}
#endregion
}
}

View File

@@ -0,0 +1,108 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Objects;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Unit tests for the DefaultAopProxyFactory class.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: DefaultAopProxyFactoryTests.cs,v 1.1 2007/08/04 01:20:11 bbaia Exp $</version>
[TestFixture]
public class DefaultAopProxyFactoryTests
{
protected virtual IAopProxy CreateAopProxy(AdvisedSupport advisedSupport)
{
IAopProxyFactory apf = new DefaultAopProxyFactory();
return apf.CreateAopProxy(advisedSupport);
}
[Test]
[ExpectedException(typeof(AopConfigException), "Cannot create IAopProxy with null ProxyConfig")]
public void NullConfig()
{
CreateAopProxy(null);
}
[Test]
[ExpectedException(typeof(AopConfigException), "Cannot create IAopProxy with no advisors and no target source")]
public void NoInterceptorsAndNoTarget()
{
AdvisedSupport advisedSupport = new AdvisedSupport(new Type[] { typeof(ITestObject) });
CreateAopProxy(advisedSupport);
}
[Test]
public void TargetDoesNotImplementAnyInterfaces()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.ProxyTargetType = false;
advisedSupport.Target = new DoesNotImplementAnyInterfacesTestObject();
IAopProxy aopProxy = CreateAopProxy(advisedSupport);
Assert.IsNotNull(aopProxy);
Assert.IsTrue(AopUtils.IsDecoratorAopProxy(aopProxy));
}
[Test]
public void TargetImplementsAnInterface()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.Target = new TestObject();
IAopProxy aopProxy = CreateAopProxy(advisedSupport);
Assert.IsNotNull(aopProxy);
Assert.IsTrue(AopUtils.IsCompositionAopProxy(aopProxy));
}
[Test]
public void TargetImplementsAnInterfaceWithProxyTargetTypeSetToTrue()
{
AdvisedSupport advisedSupport = new AdvisedSupport();
advisedSupport.ProxyTargetType = true;
advisedSupport.Target = new TestObject();
IAopProxy aopProxy = CreateAopProxy(advisedSupport);
Assert.IsNotNull(aopProxy);
Assert.IsTrue(AopUtils.IsDecoratorAopProxy(aopProxy));
}
#region Helper classes definitions
public class DoesNotImplementAnyInterfacesTestObject
{
public virtual void SomeMethod()
{
}
}
#endregion
}
}

View File

@@ -0,0 +1,343 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Objects;
using Spring.Aop.Interceptor;
using Spring.Proxy;
using System.Reflection;
using Spring.Expressions;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Additional and overridden tests for the inheritance-based proxy.
/// </summary>
/// <author>Bruno Baia</author>
/// <version>$Id: InheritanceAopProxyTests.cs,v 1.2 2008/03/03 09:29:17 bbaia Exp $</version>
[TestFixture]
public class InheritanceAopProxyTests
{
protected object CreateProxy(AdvisedSupport advisedSupport)
{
Type proxyType = new InheritanceAopProxyTypeBuilder(advisedSupport).BuildProxyType();
ConstructorInfo proxyCtorInfo = proxyType.GetConstructor(new Type[] { typeof(IAdvised) });
ExpressionEvaluator.GetValue(advisedSupport, "Activate()");
return ((IAopProxy)proxyCtorInfo.Invoke(new object[] { advisedSupport })).GetProxy();
}
[Test]
public void DirectCall()
{
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
proxiedClass.Name = "DirectCall";
Assert.AreEqual("DirectCall", proxiedClass.Name);
Assert.IsTrue(proxy is IIncrementable);
IIncrementable proxiedIntf = proxy as IIncrementable;
proxiedIntf.Increment();
Assert.AreEqual(1, proxiedIntf.Value);
}
[Test]
public void ProxyTargetTypeOnly()
{
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject("ProxyTargetTypeOnly");
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
Assert.AreNotEqual("ProxyTargetTypeOnly", proxiedClass.Name);
}
[Test]
public void CallBaseConstructor()
{
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
Assert.AreEqual("InheritanceTestObject", proxiedClass.Name);
}
[Test]
public void InterceptVirtualMethod()
{
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
advised.AddAdvice(ni);
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
proxiedClass.Name = "InterceptVirtualMethod";
Assert.AreEqual("InterceptVirtualMethod", proxiedClass.Name);
Assert.AreEqual(2, ni.Count);
}
#if NET_2_0
[Test]
public void InterceptVirtualGenericMethod()
{
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new AnotherTestObject();
advised.AddAdvice(ni);
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is AnotherTestObject);
AnotherTestObject proxiedClass = proxy as AnotherTestObject;
Assert.AreEqual(typeof(int), proxiedClass.GenericMethod<int>());
Assert.AreEqual(1, ni.Count);
}
public class AnotherTestObject
{
public virtual Type GenericMethod<T>()
{
return typeof(T);
}
// Test ambiguous match
public virtual Type GenericMethod()
{
return typeof(string);
}
}
#endif
[Test]
public void DoesNotInterceptFinalMethod()
{
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
advised.AddAdvice(ni);
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
proxiedClass.Name = "DoesNotInterceptFinalMethod";
Assert.AreEqual("DoesNotInterceptFinalMethod", proxiedClass.Name);
Assert.AreEqual(2, ni.Count);
proxiedClass.Reset();
Assert.AreEqual(2, ni.Count);
Assert.AreEqual("InheritanceTestObject", proxiedClass.Name);
Assert.AreEqual(3, ni.Count);
}
[Test]
public void InterceptVirtualMethodThatBelongsToAnInterface()
{
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
advised.AddAdvice(ni);
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
proxiedClass.Increment();
Assert.AreEqual(1, ni.Count);
Assert.IsTrue(proxy is IIncrementable);
IIncrementable proxiedInterface = proxy as IIncrementable;
proxiedInterface.Increment();
Assert.AreEqual(2, ni.Count);
}
[Test]
public void InterceptNonVirtualMethodThatBelongsToAnInterface()
{
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
advised.AddAdvice(ni);
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
Assert.AreEqual(0, proxiedClass.Value);
Assert.AreEqual(0, ni.Count);
Assert.IsTrue(proxy is IIncrementable);
IIncrementable proxiedInterface = proxy as IIncrementable;
proxiedInterface.Increment();
Assert.AreEqual(1, proxiedInterface.Value);
Assert.AreEqual(2, ni.Count);
}
[Test]
public void InterceptThisCalls()
{
NopInterceptor ni = new NopInterceptor();
AdvisedSupport advised = new AdvisedSupport();
advised.Target = new InheritanceTestObject();
advised.AddAdvice(ni);
object proxy = CreateProxy(advised);
//DynamicProxyManager.SaveAssembly();
Assert.IsTrue(proxy is InheritanceTestObject);
InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
proxiedClass.IncrementTwice();
Assert.AreEqual(2, ni.Count);
Assert.AreEqual(2, proxiedClass.Value);
}
//[Test]
//public void InterceptProtectedMethod()
//{
// NopInterceptor ni = new NopInterceptor();
// AdvisedSupport advised = new AdvisedSupport();
// advised.Target = new InheritanceTestObject();
// advised.AddAdvice(ni);
// object proxy = CreateProxy(advised);
// //DynamicProxyManager.SaveAssembly();
// Assert.IsTrue(proxy is InheritanceTestObject);
// InheritanceTestObject proxiedClass = proxy as InheritanceTestObject;
// proxiedClass.Todo();
// Assert.AreEqual(1, ni.Count);
//}
}
#region Helper Classes
public interface IIncrementable
{
int Value {get; set;}
void Increment();
}
public class InheritanceTestObject : IIncrementable
{
// virtual method
private string _name;
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
// many constructors
public InheritanceTestObject() : this("InheritanceTestObject", 0)
{
}
public InheritanceTestObject(string name) : this(name, 0)
{
}
public InheritanceTestObject(string name, int value)
{
this._name = name;
this._value = value;
}
#region IIncrementable Members
// non virtual method that belongs to an interface
private int _value;
public int Value
{
get { return _value; }
set { _value = value; }
}
// virtual method that belongs to an interface too
public virtual void Increment()
{
// this call
this._value++;
}
#endregion
// final method
public void Reset()
{
this._name = "InheritanceTestObject";
this._value = 0;
}
// this call
public void IncrementTwice()
{
this.Increment();
this.Increment();
}
// protected method call
public void Todo()
{
ProtectedTodo();
}
protected virtual void ProtectedTodo()
{
}
}
#endregion
}

View File

@@ -0,0 +1,89 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using Spring.Aop.Target;
#endregion
namespace Spring.Aop.Framework.DynamicProxy
{
/// <summary>
/// Useful <see cref="Spring.Aop.ITargetSource"/> implementation
/// that checks calls to GetTarget and ReleaseTarget.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Bruno Baia (.NET)</author>
/// <version>$Id: MockTargetSource.cs,v 1.1 2006/08/10 18:45:58 bbaia Exp $</version>
public class MockTargetSource : ITargetSource
{
private object _target;
public int gets;
public int releases;
public void Reset()
{
this._target = null;
gets = releases = 0;
}
public void SetTarget(Object target)
{
this._target = target;
}
public void Verify()
{
if (gets != releases)
throw new Exception("Expectation failed: " + gets + " gets and " + releases + " releases");
}
#region ITargetSource Members
public Type TargetType
{
get { return _target.GetType(); }
}
public bool IsStatic
{
get { return false; }
}
public object GetTarget()
{
++gets;
return _target;
}
public void ReleaseTarget(object target)
{
if (target != this._target)
throw new Exception("Released wrong target");
++releases;
}
#endregion
}
}

View File

@@ -0,0 +1,84 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the HashtableCachingAdvisorChainFactory class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: HashtableCachingAdvisorChainFactoryTests.cs,v 1.2 2006/04/09 07:19:05 markpollack Exp $</version>
[TestFixture]
public sealed class HashtableCachingAdvisorChainFactoryTests
{
#region SetUp
/// <summary>
/// The setup logic executed before the execution of this test fixture.
/// </summary>
[TestFixtureSetUp]
public void FixtureSetUp()
{
}
/// <summary>
/// The setup logic executed before the execution of each individual test.
/// </summary>
[SetUp]
public void SetUp()
{
}
#endregion
#region TearDown
/// <summary>
/// The tear down logic executed after the execution of each individual test.
/// </summary>
[TearDown]
public void TearDown()
{
}
/// <summary>
/// The tear down logic executed after the entire test fixture has executed.
/// </summary>
[TestFixtureTearDown]
public void FixtureTearDown()
{
}
#endregion
[Test]
public void Instantiation() {
}
}
}

View File

@@ -0,0 +1,27 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
namespace Spring.Aop.Framework
{
public interface IIsModified
{
bool IsModified { get; set; }
}
}

View File

@@ -0,0 +1,39 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// This interface can be implemented by cacheable objects
/// or cache entries, to enable the freshness of objects
/// to be checked.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: ITimeStamped.cs,v 1.1 2004/08/01 10:20:20 choyrim Exp $</version>
public interface ITimeStamped
{
/// <summary>
/// Return the timestamp for this object.
/// </summary>
DateTime TimeStamp { get; }
}
}

View File

@@ -0,0 +1,43 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
using AopAlliance.Aop;
using Spring.Aop.Support;
namespace Spring.Aop.Framework
{
public class IsModifiedMixin : IIsModified, IAdvice
{
private bool isModified = true;
public virtual bool IsModified
{
get { return isModified; }
set { isModified = value; }
}
}
public class IsModifiedAdvisor : DefaultIntroductionAdvisor
{
public IsModifiedAdvisor()
: base(new IsModifiedMixin())
{}
}
}

View File

@@ -0,0 +1,67 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Reflection;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Useful base class for counting advices etc.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: MethodCounter.cs,v 1.2 2007/03/16 04:01:47 aseovic Exp $</version>
[Serializable]
public class MethodCounter
{
/// <summary>Method name --> count, does not understand overloading </summary>
private Hashtable map = new Hashtable();
private int allCount;
protected internal virtual void Count(MethodBase m)
{
Count(m.Name);
}
protected internal virtual void Count(string methodName)
{
int count = GetCalls(methodName);
++count;
map[methodName] = count;
++allCount;
}
public virtual int GetCalls(string methodName)
{
int count = 0;
if ( map.ContainsKey(methodName) )
{
count = (int) map[methodName];
}
return count;
}
public virtual int GetCalls()
{
return allCount;
}
}
}

View File

@@ -0,0 +1,101 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
using AopAlliance.Intercept;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
///
/// </summary>
/// <author>Juergen Hoeller</author>
/// <author>Simon White (.NET)</author>
[TestFixture]
public class PrototypeTargetTests
{
[Test]
public void PrototypeProxyWithPrototypeTarget()
{
TestObjectImpl.constructionCount = 0;
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTarget.xml", GetType()));
for (int i = 0 ; i < 10 ; i++)
{
int crap = TestObjectImpl.constructionCount;
TestObject to = (TestObject) iof.GetObject("testObjectPrototype");
crap = TestObjectImpl.constructionCount;
to.DoSomething();
}
TestInterceptor interceptor = (TestInterceptor) iof.GetObject("testInterceptor");
Assert.AreEqual(10, TestObjectImpl.constructionCount);
Assert.AreEqual(10, interceptor.invocationCount);
}
[Test]
public void SingletonProxyWithPrototypeTarget()
{
TestObjectImpl.constructionCount = 0;
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTarget.xml", GetType()));
for (int i = 0; i < 10; i++)
{
TestObject to = (TestObject) iof.GetObject("testObjectSingleton");
to.DoSomething();
}
TestInterceptor interceptor = (TestInterceptor) iof.GetObject("testInterceptor");
Assert.AreEqual(1, TestObjectImpl.constructionCount);
Assert.AreEqual(10, interceptor.invocationCount);
}
public interface TestObject
{
void DoSomething();
}
public class TestObjectImpl : TestObject
{
public static int constructionCount = 0;
public TestObjectImpl()
{
constructionCount++;
}
public void DoSomething()
{
}
}
public class TestInterceptor : IMethodInterceptor
{
public int invocationCount = 0;
public object Invoke(IMethodInvocation methodInvocation)
{
invocationCount++;
return methodInvocation.Proceed();
}
}
}
}

View File

@@ -0,0 +1,44 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the ProxyConfig class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: ProxyConfigTests.cs,v 1.2 2006/04/09 07:19:05 markpollack Exp $</version>
[TestFixture]
public sealed class ProxyConfigTests
{
[Test]
public void Instantiation()
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,608 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Aop.Interceptor;
using Spring.Aop.Support;
using Spring.Objects;
using Spring.Proxy;
using Spring.Util;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the ProxyFactory class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <author>Rick Evans (.NET)</author>
/// <version>$Id: ProxyFactoryTests.cs,v 1.22 2008/03/21 10:49:38 oakinger Exp $</version>
[TestFixture]
public sealed class ProxyFactoryTests
{
public interface IDoubleClickable
{
event EventHandler DoubleClick;
void FireDoubleClickEvent();
}
public interface IDoubleClickableIntroduction :
IDoubleClickable, IAdvice
{
}
private class DoubleClickableIntroduction :
IDoubleClickableIntroduction
{
public event EventHandler DoubleClick;
public void FireDoubleClickEvent()
{
if (DoubleClick != null)
{
DoubleClick(this, EventArgs.Empty);
}
}
}
[Test]
public void AddAndRemoveEventHandlerThroughIntroduction()
{
TestObject target = new TestObject();
DoubleClickableIntroduction dci = new DoubleClickableIntroduction();
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(dci);
CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
target.Name = "SOME-NAME";
ProxyFactory pf = new ProxyFactory(target);
pf.AddIntroduction(advisor);
pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
object proxy = pf.GetProxy();
ITestObject to = proxy as ITestObject;
Assert.IsNotNull(to);
Assert.AreEqual("SOME-NAME", to.Name);
IDoubleClickable doubleClickable = proxy as IDoubleClickable;
// add event handler through introduction
doubleClickable.DoubleClick += new EventHandler(OnClick);
OnClickWasCalled = false;
doubleClickable.FireDoubleClickEvent();
Assert.IsTrue(OnClickWasCalled);
Assert.AreEqual(3, countingBeforeAdvice.GetCalls());
// remove event handler through introduction
doubleClickable.DoubleClick -= new EventHandler(OnClick);
OnClickWasCalled = false;
doubleClickable.FireDoubleClickEvent();
Assert.IsFalse(OnClickWasCalled);
Assert.AreEqual(5, countingBeforeAdvice.GetCalls());
}
private bool OnClickWasCalled = false;
private void OnClick(object sender, EventArgs e)
{
OnClickWasCalled = true;
}
[Test]
public void CacheTest()
{
for (int i = 0; i < 2; i++)
{
TestObject target = new TestObject();
NopInterceptor nopInterceptor = new NopInterceptor();
CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
ProxyFactory pf = new ProxyFactory();
pf.Target = target;
pf.AddAdvice(nopInterceptor);
pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
object proxy = pf.GetProxy();
}
// fails when running in resharper/testdriven.net
// DynamicProxyManager.SaveAssembly();
}
[Test]
public void AddAndRemoveEventHandlerThroughInterceptor()
{
TestObject target = new TestObject();
NopInterceptor nopInterceptor = new NopInterceptor();
CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
target.Name = "SOME-NAME";
ProxyFactory pf = new ProxyFactory(target);
pf.AddAdvice(nopInterceptor);
pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
object proxy = pf.GetProxy();
ITestObject to = proxy as ITestObject;
// add event handler through proxy
to.Click += new EventHandler(OnClick);
OnClickWasCalled = false;
to.OnClick();
Assert.IsTrue(OnClickWasCalled);
Assert.AreEqual(2, countingBeforeAdvice.GetCalls());
// remove event handler through proxy
to.Click -= new EventHandler(OnClick);
OnClickWasCalled = false;
to.OnClick();
Assert.IsFalse(OnClickWasCalled);
Assert.AreEqual(4, countingBeforeAdvice.GetCalls());
}
private class TestObject2 : TestObject
{
public bool EqualsOverrideWasCalled = false;
public override bool Equals(object obj)
{
EqualsOverrideWasCalled = true;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
[Test]
public void CallsEqualsOverride()
{
TestObject2 target = new TestObject2();
target.Name = "SOME-NAME";
ProxyFactory pf = new ProxyFactory(target);
object proxy = pf.GetProxy();
ITestObject to = proxy as ITestObject;
Assert.IsNotNull(to);
Assert.AreEqual("SOME-NAME", to.Name);
target.EqualsOverrideWasCalled = false;
Assert.IsTrue(to.Equals(proxy));
Assert.IsTrue(target.EqualsOverrideWasCalled);
target.EqualsOverrideWasCalled = false;
Assert.IsTrue(proxy.Equals(to));
Assert.IsTrue(target.EqualsOverrideWasCalled);
target.EqualsOverrideWasCalled = false;
Assert.IsTrue(target.Equals(to));
Assert.IsTrue(target.EqualsOverrideWasCalled);
target.EqualsOverrideWasCalled = false;
Assert.IsTrue(to.Equals(target));
Assert.IsTrue(target.EqualsOverrideWasCalled);
}
[Test]
public void CreateProxyFactoryWithoutTargetThenSetTarget()
{
TestObject target = new TestObject();
target.Name = "Adam";
NopInterceptor nopInterceptor = new NopInterceptor();
CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
ProxyFactory pf = new ProxyFactory();
pf.Target = target;
pf.AddAdvice(nopInterceptor);
pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
object proxy = pf.GetProxy();
ITestObject to = (ITestObject) proxy;
Assert.AreEqual("Adam", to.Name);
Assert.AreEqual(1, countingBeforeAdvice.GetCalls());
}
[Test]
[ExpectedException(typeof (AopConfigException))]
public void InstantiateWithNullTarget()
{
new ProxyFactory((object) null);
}
[Test]
[ExpectedException(typeof (ArgumentNullException))]
public void AddNullInterface()
{
new ProxyFactory().AddInterface(null);
}
[Test]
[ExpectedException(typeof (AopConfigException))]
public void AddInterfaceWhenConfigurationIsFrozen()
{
ProxyFactory factory = new ProxyFactory();
factory.IsFrozen = true;
factory.AddInterface(typeof(ITestObject));
}
[Test]
public void IndexOfMethods()
{
TestObject target = new TestObject();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
IAdvisor advisor = new DefaultPointcutAdvisor(new CountingBeforeAdvice());
IAdvised advised = (IAdvised) pf.GetProxy();
// Can use advised and ProxyFactory interchangeably
advised.AddAdvice(nop);
pf.AddAdvisor(advisor);
Assert.AreEqual(- 1, pf.IndexOf((IInterceptor) null));
Assert.AreEqual(- 1, pf.IndexOf(new NopInterceptor()));
Assert.AreEqual(0, pf.IndexOf(nop));
Assert.AreEqual(- 1, advised.IndexOf((IAdvisor) null));
Assert.AreEqual(1, pf.IndexOf(advisor));
Assert.AreEqual(- 1, advised.IndexOf(new DefaultPointcutAdvisor(null)));
}
[Test]
public void RemoveAdvisorByReference()
{
TestObject target = new TestObject();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba = new CountingBeforeAdvice();
IAdvisor advisor = new DefaultPointcutAdvisor(cba);
pf.AddAdvice(nop);
pf.AddAdvisor(advisor);
ITestObject proxied = (ITestObject) pf.GetProxy();
proxied.Age = 5;
Assert.AreEqual(1, cba.GetCalls());
Assert.AreEqual(1, nop.Count);
Assert.IsFalse(pf.RemoveAdvisor(null));
Assert.IsTrue(pf.RemoveAdvisor(advisor));
Assert.AreEqual(5, proxied.Age);
Assert.AreEqual(1, cba.GetCalls());
Assert.AreEqual(2, nop.Count);
Assert.IsFalse(pf.RemoveAdvisor(new DefaultPointcutAdvisor(null)));
}
[Test]
public void RemoveAdvisorByIndex()
{
TestObject target = new TestObject();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba = new CountingBeforeAdvice();
IAdvisor advisor = new DefaultPointcutAdvisor(cba);
pf.AddAdvice(nop);
pf.AddAdvisor(advisor);
NopInterceptor nop2 = new NopInterceptor(2); // make instance unique (see SPRNET-847)
pf.AddAdvice(nop2);
ITestObject proxied = (ITestObject) pf.GetProxy();
proxied.Age = 5;
Assert.AreEqual(1, cba.GetCalls());
Assert.AreEqual(1, nop.Count);
Assert.AreEqual(1, nop2.Count);
// Removes counting before advisor
pf.RemoveAdvisor(1);
Assert.AreEqual(5, proxied.Age);
Assert.AreEqual(1, cba.GetCalls());
Assert.AreEqual(2, nop.Count);
Assert.AreEqual(2, nop2.Count);
// Removes Nop1
pf.RemoveAdvisor(0);
Assert.AreEqual(5, proxied.Age);
Assert.AreEqual(1, cba.GetCalls());
Assert.AreEqual(2, nop.Count);
Assert.AreEqual(3, nop2.Count);
// Check out of bounds
try
{
pf.RemoveAdvisor(- 1);
Assert.Fail("Supposed to throw exception");
}
catch (AopConfigException)
{
// Ok
}
try
{
pf.RemoveAdvisor(2);
Assert.Fail("Supposed to throw exception");
}
catch (AopConfigException)
{
// Ok
}
Assert.AreEqual(5, proxied.Age);
Assert.AreEqual(4, nop2.Count);
}
[Test]
public void TryRemoveNonProxiedInterface()
{
ProxyFactory factory = new ProxyFactory(new TestObject ());
Assert.IsFalse(factory.RemoveInterface(typeof(IServiceProvider)));
}
[Test]
public void RemoveProxiedInterface()
{
ProxyFactory factory = new ProxyFactory(new TestObject ());
Assert.IsTrue(factory.RemoveInterface(typeof(ITestObject)));
}
[Test]
public void ReplaceAdvisor()
{
TestObject target = new TestObject();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba1 = new CountingBeforeAdvice();
CountingBeforeAdvice cba2 = new CountingBeforeAdvice();
IAdvisor advisor1 = new DefaultPointcutAdvisor(cba1);
IAdvisor advisor2 = new DefaultPointcutAdvisor(cba2);
pf.AddAdvisor(advisor1);
pf.AddAdvice(nop);
ITestObject proxied = (ITestObject) pf.GetProxy();
// Use the type cast feature
// Replace etc methods on advised should be same as on ProxyFactory
IAdvised advised = (IAdvised) proxied;
proxied.Age = 5;
Assert.AreEqual(1, cba1.GetCalls());
Assert.AreEqual(0, cba2.GetCalls());
Assert.AreEqual(1, nop.Count);
Assert.IsFalse(advised.ReplaceAdvisor(null, null));
Assert.IsFalse(advised.ReplaceAdvisor(null, advisor2));
Assert.IsFalse(advised.ReplaceAdvisor(advisor1, null));
Assert.IsTrue(advised.ReplaceAdvisor(advisor1, advisor2));
Assert.AreEqual(advisor2, pf.Advisors[0]);
Assert.AreEqual(5, proxied.Age);
Assert.AreEqual(1, cba1.GetCalls());
Assert.AreEqual(2, nop.Count);
Assert.AreEqual(1, cba2.GetCalls());
Assert.IsFalse(pf.ReplaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
}
[Test]
public void IgnoresAdvisorDuplicates()
{
CountingBeforeAdvice cba1 = new CountingBeforeAdvice();
IAdvisor advisor1 = new DefaultPointcutAdvisor(cba1);
AdvisedSupport advSup = new AdvisedSupport();
advSup.AddAdvisor(advisor1);
advSup.AddAdvisor(advisor1);
Assert.AreEqual(1, advSup.Advisors.Length);
}
private class AnonymousClassTimeStamped : ITimeStamped
{
public AnonymousClassTimeStamped(ProxyFactoryTests enclosingInstance)
{
InitBlock(enclosingInstance);
}
private void InitBlock(ProxyFactoryTests enclosingInstance)
{
this.enclosingInstance = enclosingInstance;
}
private ProxyFactoryTests enclosingInstance;
public ProxyFactoryTests Enclosing_Instance
{
get { return enclosingInstance; }
}
public DateTime TimeStamp
{
get { throw new NotSupportedException("TimeStamp"); }
}
}
[Test]
public void AddRepeatedInterface()
{
ITimeStamped tst = new AnonymousClassTimeStamped(this);
ProxyFactory pf = new ProxyFactory(tst);
// We've already implicitly added this interface.
// This call should be ignored without error
pf.AddInterface(typeof (ITimeStamped));
// All cool
ITimeStamped ts = (ITimeStamped) pf.GetProxy();
}
internal class TestObjectSubclass : TestObject, IComparable
{
public override int CompareTo(Object arg0)
{
throw new NotSupportedException("compareTo");
}
}
[Test]
public void GetsAllInterfaces()
{
// Extend to get new interface
TestObjectSubclass raw = new TestObjectSubclass();
ProxyFactory factory = new ProxyFactory(raw);
Assert.AreEqual(7, factory.Interfaces.Length, "Found correct number of interfaces");
//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
ITestObject tb = (ITestObject) factory.GetProxy();
Assert.IsTrue(tb is IOther, "Picked up secondary interface");
raw.Age = 25;
Assert.IsTrue(tb.Age == raw.Age);
DateTime t = new DateTime(2004, 8, 1);
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
Console.WriteLine(StringUtils.ArrayToDelimitedString(factory.Interfaces, "/"));
//factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped)));
factory.AddIntroduction(
new DefaultIntroductionAdvisor(ti, typeof (ITimeStamped))
);
Console.WriteLine(StringUtils.ArrayToDelimitedString(factory.Interfaces, "/"));
ITimeStamped ts = (ITimeStamped) factory.GetProxy();
Assert.IsTrue(ts.TimeStamp == t);
// Shouldn't fail;
((IOther) ts).Absquatulate();
}
private class AnonymousClassInterceptor : IInterceptor
{
}
[Test]
public void CanOnlyAddMethodInterceptors()
{
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddAdvice(0, new NopInterceptor());
try
{
factory.AddAdvice(0, new AnonymousClassInterceptor());
Assert.Fail("Should only be able to add MethodInterceptors");
}
catch (AopConfigException)
{
}
// Check we can still use it
IOther other = (IOther) factory.GetProxy();
other.Absquatulate();
}
[Test]
public void InterceptorInclusionMethods()
{
NopInterceptor di = new NopInterceptor();
NopInterceptor diUnused = new NopInterceptor(1); // // make instance unique (see SPRNET-847)
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddAdvice(0, di);
ITestObject tb = (ITestObject) factory.GetProxy();
Assert.IsTrue(factory.AdviceIncluded(di));
Assert.IsTrue(!factory.AdviceIncluded(diUnused));
Assert.IsTrue(factory.CountAdviceOfType(typeof (NopInterceptor)) == 1);
factory.AddAdvice(0, diUnused);
Assert.IsTrue(factory.AdviceIncluded(diUnused));
Assert.IsTrue(factory.CountAdviceOfType(typeof (NopInterceptor)) == 2);
}
[Test]
public void AddAdvisedSupportListener()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener) mock.Object;
mock.Expect("Activated");
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
factory.GetProxy();
mock.Verify();
}
[Test]
public void AdvisedSupportListenerMethodsAreCalledAppropriately()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener) mock.Object;
mock.Expect("Activated");
mock.Expect("AdviceChanged");
mock.Expect("InterfacesChanged");
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
// must fire the Activated callback...
factory.GetProxy();
// must fire the AdviceChanged callback...
factory.AddAdvice(new NopInterceptor());
// must fire the InterfacesChanged callback...
factory.AddInterface(typeof(ISerializable));
mock.Verify();
}
[Test]
public void AdvisedSupportListenerMethodsAre_NOT_CalledIfProxyHasNotBeenCreated()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener) mock.Object;
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
// must not fire the AdviceChanged callback...
factory.AddAdvice(new NopInterceptor());
// must not fire the InterfacesChanged callback...
factory.AddInterface(typeof(ISerializable));
mock.Verify();
}
[Test]
public void AddNullAdvisedSupportListenerIsOk()
{
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(null);
}
[Test]
public void RemoveNullAdvisedSupportListenerIsOk()
{
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.RemoveListener(null);
}
[Test]
public void RemoveAdvisedSupportListener()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener) mock.Object;
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
factory.RemoveListener(listener);
factory.GetProxy();
// check that no lifecycle callback methods were invoked on the listener...
mock.Verify();
}
[Test]
[ExpectedException(typeof(AopConfigException))]
public void Frozen_RemoveAdvisor()
{
ProxyFactory factory = new ProxyFactory();
factory.IsFrozen = true;
factory.RemoveAdvisor(null);
}
}
}

View File

@@ -0,0 +1,47 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Collections;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Unit tests for the ReflectiveMethodInvocation class.
/// </summary>
/// <author>Rick Evans</author>
/// <author>Bruno Baia</author>
/// <version>$Id: ReflectiveMethodInvocationTests.cs,v 1.8 2008/02/06 18:29:05 bbaia Exp $</version>
[TestFixture]
public class ReflectiveMethodInvocationTests : AbstractMethodInvocationTests
{
protected override AbstractMethodInvocation CreateMethodInvocation(object proxy, object target, MethodInfo method, MethodInfo onProxyMethod, object[] arguments, Type targetType, IList interceptors)
{
return new ReflectiveMethodInvocation(proxy, target, method, onProxyMethod, arguments, targetType, interceptors);
}
}
}

View File

@@ -0,0 +1,67 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop.Framework
{
/// <summary>
/// Test introduction ported from Spring.Java.
/// </summary>
/// <remarks>
/// The name is deceptive because it isn't implemented as an interceptor.
/// It's an introduction which is handled differently in Spring.NET.
/// Keeping the name is useful as a placeholder for future porting work.
/// </remarks>
/// <author>Spring.Java Folks</author>
/// <author>Choy Rim (.NET)</author>
public class TimestampIntroductionInterceptor : IAdvice, ITimeStamped, IInterceptor
{
private DateTime ts;
public TimestampIntroductionInterceptor()
{
}
public TimestampIntroductionInterceptor(DateTime ts)
{
this.ts = ts;
}
#region ITimeStamped Members
public DateTime TimeStamp
{
get
{
return this.ts;
}
set
{
this.ts = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,13 @@
using System;
using AopAlliance.Intercept;
namespace Spring.Aop.Framework
{
public class UnsupportedInterceptor : IMethodInterceptor
{
public object Invoke(IMethodInvocation invocation)
{
throw new NotImplementedException(invocation.Method.Name);
}
}
}

View File

@@ -0,0 +1,34 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Simple BeforeAdvice targeted for testing
/// </summary>
/// <author>Dmitriy Kopylenko</author>
/// <author>Simon White (.NET)</author>
public interface ISimpleBeforeAdvice : IBeforeAdvice
{
void Before();
}
}

View File

@@ -0,0 +1,86 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
#endregion
namespace Spring.Aop.Interceptor
{
/// <summary>
/// Trivial interceptor that can be introduced into an interceptor chain to
/// aid in debugging.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: NopInterceptor.cs,v 1.6 2008/01/14 20:49:47 oakinger Exp $</version>
public class NopInterceptor : IMethodBeforeAdvice
{
protected int instanceId;
protected int count;
public NopInterceptor() : this(0)
{
}
public NopInterceptor(int instanceId)
{
this.instanceId = instanceId;
}
public int InstanceId
{
get { return instanceId; }
}
public int Count
{
get { return this.count; }
}
public void Before(MethodInfo method, object[] args, object target)
{
++count;
}
public override bool Equals(Object other)
{
if (!(other is NopInterceptor))
{
return false;
}
if (this == other)
{
return true;
}
return (instanceId == ((NopInterceptor) other).InstanceId)
&& (count == ((NopInterceptor) other).count);
}
public override int GetHashCode()
{
return instanceId + 13 * count;
}
}
}

View File

@@ -0,0 +1,52 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Runtime.Serialization;
#endregion
namespace Spring.Aop.Interceptor
{
/// <summary>
/// Subclass of NopInterceptor that is serializable and
/// can be used to test proxy serialization.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[Serializable]
public sealed class SerializableNopInterceptor : NopInterceptor, ISerializable
{
public SerializableNopInterceptor()
{
}
public SerializableNopInterceptor(SerializationInfo info, StreamingContext ctxt)
{
this.instanceId = (int) info.GetValue("InstanceId", typeof(int));
this.count = (int)info.GetValue("Count", typeof(int));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("InstanceId", InstanceId);
info.AddValue("Count", Count);
}
}
}

View File

@@ -0,0 +1,51 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using Spring.Aop.Framework.Adapter;
#endregion
namespace Spring.Aop
{
/// <summary>
///
/// </summary>
/// <author>Dmitriy Kopylenko</author>
/// <author>Simon White (.NET)</author>
public class SimpleBeforeAdviceAdapter : IAdvisorAdapter
{
#region IAdvisorAdapter Members
public bool SupportsAdvice(IAdvice advice)
{
return advice is ISimpleBeforeAdvice;
}
public IInterceptor GetInterceptor(IAdvisor advisor)
{
ISimpleBeforeAdvice advice = (ISimpleBeforeAdvice) advisor.Advice;
return new SimpleBeforeAdviceInterceptor(advice) ;
}
#endregion
}
}

View File

@@ -0,0 +1,57 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
#endregion
namespace Spring.Aop
{
/// <summary>
///
/// </summary>
/// <author>Dmitriy Kopylenko</author>
/// <author>Simon White (.NET)</author>
public class SimpleBeforeAdviceImpl : ISimpleBeforeAdvice
{
private int _invocationCounter;
#region Properties
public int InvocationCounter
{
get
{
return _invocationCounter;
}
}
#endregion
#region Constructors
public SimpleBeforeAdviceImpl()
{
}
#endregion
#region ISimpleBeforeAdvice Members
public void Before()
{
++_invocationCounter;
}
#endregion
}
}

View File

@@ -0,0 +1,51 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
#endregion
namespace Spring.Aop
{
/// <summary>
///
/// </summary>
/// <author>Dmitriy Kopylenko</author>
/// <author>Simon White (.NET)</author>
public class SimpleBeforeAdviceInterceptor : IMethodInterceptor
{
private ISimpleBeforeAdvice _advice;
#region Constructors
public SimpleBeforeAdviceInterceptor(ISimpleBeforeAdvice advice)
{
this._advice = advice;
}
#endregion
#region IMethodInterceptor Members
public object Invoke(IMethodInvocation mi)
{
_advice.Before();
return mi.Proceed();
}
#endregion
}
}

View File

@@ -0,0 +1,109 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Util;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for the AbstractRegularExpressionMethodPointcut class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Dmitriy Kopylenko</author>
/// <author>Simon White (.NET)</author>
public abstract class AbstractRegularExpressionMethodPointcutTests
{
private AbstractRegularExpressionMethodPointcut pointcut;
[SetUp]
protected void SetUp()
{
pointcut = GetRegexpMethodPointcut();
}
protected abstract AbstractRegularExpressionMethodPointcut GetRegexpMethodPointcut();
[Test]
public void NoPatternSupplied()
{
NoPatternSuppliedTests(pointcut);
}
[Test]
public void SerializationWithNoPatternSupplied()
{
pointcut = (AbstractRegularExpressionMethodPointcut) SerializationTestUtils.SerializeAndDeserialize(pointcut);
NoPatternSuppliedTests(pointcut);
}
protected void NoPatternSuppliedTests(AbstractRegularExpressionMethodPointcut rpc)
{
Assert.IsFalse(rpc.Matches(typeof(object).GetMethod("GetHashCode"), typeof(int)));
Assert.IsFalse(rpc.Matches(typeof(object).GetMethod("GetType"), typeof(Type)));
Assert.AreEqual(0, rpc.Patterns.Length);
}
[Test]
public void ExactMatch()
{
pointcut.Pattern = "System.Object.GetHashCode";
ExactMatchTests(pointcut);
pointcut = (AbstractRegularExpressionMethodPointcut) SerializationTestUtils.SerializeAndDeserialize(pointcut);
ExactMatchTests(pointcut);
}
protected void ExactMatchTests(AbstractRegularExpressionMethodPointcut rpc)
{
// assumes rpc.setPattern("java.lang.Object.hashCode");
Assert.IsTrue(rpc.Matches(typeof(object).GetMethod("GetHashCode"), typeof(int)));
Assert.IsFalse(rpc.Matches(typeof(object).GetMethod("GetType"), typeof(Type)));
}
[Test]
public void Wildcard()
{
pointcut.Pattern = ".*Object.GetHashCode";
Assert.IsTrue(pointcut.Matches(typeof(object).GetMethod("GetHashCode"), typeof(int)));
Assert.IsFalse(pointcut.Matches(typeof(object).GetMethod("GetType"), typeof(Type)));
}
[Test]
public void WildcardForOneClass()
{
pointcut.Pattern = "System.Object.*";
Assert.IsTrue(pointcut.Matches(typeof(object).GetMethod("GetHashCode"), typeof(int)));
Assert.IsTrue(pointcut.Matches(typeof(object).GetMethod("GetType"), typeof(Type)));
}
[Test]
public void MatchesObjectClass()
{
pointcut.Pattern = "System.Object.*";
Assert.IsTrue(pointcut.Matches(typeof(Exception).GetMethod("GetHashCode"), typeof(TargetException)));
// Doesn't match
Assert.IsFalse(pointcut.Matches(typeof(Exception).GetMethod("ToString"), typeof(Exception)));
}
}
}

View File

@@ -0,0 +1,229 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using System.Reflection;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for the AttributeMatchMethodPointcut class.
/// </summary>
/// <author>Rick Evans</author>
/// <author>Ronald Wildenberg</author>
/// <version>$Id: AttributeMatchMethodPointcutTests.cs,v 1.3 2007/05/21 16:44:08 bbaia Exp $</version>
[TestFixture]
public sealed class AttributeMatchMethodPointcutTests
{
[Test]
public void InstantiationWithASunnyDayAttributeType()
{
new AttributeMatchMethodPointcut(typeof(SerializableAttribute));
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void InstantiationWithNonAttributeType()
{
new AttributeMatchMethodPointcut(GetType());
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void AttributeSetterWithNonAttributeType()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = GetType();
}
[Test]
public void AttributeSetterWithNullType()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = null; // must allow this (no Exception)...
}
[Test]
public void AttributeSetterWithASunnyDayAttributeType()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(SerializableAttribute); // must allow this too (no Exception)...
}
[Test]
public void MatchesWithASunnyDayAttributeTypeAndNoInheritance()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
bool matches = cut.Matches(typeof(WithMarkup).GetMethod("Bing"), null);
Assert.IsTrue(matches, "Method was decorated with the target attribute, so this must match.");
}
[Test]
public void MatchesWithASunnyDayAttributeTypeAndInheritance()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
bool matches = cut.Matches(typeof(InheritedWithMarkup).GetMethod("Bing"), null);
Assert.IsTrue(matches, "Inherited method was decorated with the target attribute, so this must match.");
}
[Test]
public void MatchesWithAMethodThatDontMatchTheAttributeTypeAndNoInheritance()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
bool matches = cut.Matches(typeof(WithMarkup).GetMethod("RiloKiley"), null);
Assert.IsFalse(matches, "Method was not decorated with the target attribute, so this must not match.");
}
[Test]
public void MatchesWithAnInheritedMethodThatDontMatchTheAttributeTypeAndNoInheritance()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
bool matches = cut.Matches(typeof(InheritedWithMarkup).GetMethod("RiloKiley"), null);
Assert.IsFalse(matches, "Inherited method was not decorated with the target attribute, so this must not match.");
}
/// <summary>
/// Confirms that without interfaces checking, a method that is implemented from an interface, will not match.
/// </summary>
[Test]
public void MatchesWithAnInterfaceMethodThatMatchesTheAttributeTypeAndNoCheckInterfaces()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
cut.CheckInterfaces = false;
bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("OtherTestMethod"), null);
Assert.IsFalse(matches, "Implementing method was not decorated with the target attribute, so this must not match since CheckInterfaces is false.");
}
/// <summary>
/// Confirms that with interface checking, a method that is implementing an interface method
/// where the attribute is defined will match.
/// </summary>
[Test]
public void MatchesWithAnInterfaceMethodThatMatchesTheAttributeTypeAndCheckInterfaces()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
cut.CheckInterfaces = true;
bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("OtherTestMethod"), null);
Assert.IsTrue(matches, "Implementing method was not decorated with the target attribute, " +
"but the method from the interface was, so this must match.");
}
/// <summary>
/// Confirms that with interfaces checking, a method that is indirectly implementing an interface method
/// where the attribute is defined will match.
/// </summary>
[Test]
public void MatchesWithAnIndirectInterfaceMethodThatMatchesTheAttributeTypeAndCheckInterfaces()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
cut.CheckInterfaces = true;
bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("TestMethod", new Type[] { }), null);
Assert.IsTrue(matches, "Implementing method was not decorated with the target attribute, but the" +
" method from an indirectly implemented interface was, so this must match.");
}
/// <summary>
/// Confirms that overloading methods do not match, whatever the attributes.
/// </summary>
[Test]
public void MatchesWithAnOverloadedInterfaceMethod()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
cut.CheckInterfaces = true;
bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("TestMethod", new Type[] { typeof(string) }), null);
Assert.IsFalse(matches, "Overloaded method from an implemented interface is not decorated with" +
" the attribute, so should not match.");
}
/// <summary>
/// Confirms that methods, defined in a subclass of a class that implements an interface that
/// has methods that have been decorated with an attribute, match.
/// </summary>
[Test]
public void MatchesWithAnIndirectInterfaceMethodFromSubclassThatMatchesTheAttributeTypeAndCheckInterfaces()
{
AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();
cut.Attribute = typeof(MarkupAttribute);
cut.CheckInterfaces = true;
bool matches = cut.Matches(typeof(InheritedImplementingClass).GetMethod("TestMethod", new Type[] { }), null);
Assert.IsTrue(matches, "Implementing method from subclass was not decorated with the target attribute " +
"but the method from an indirectly implemented interface was, so this must match.");
}
#region Helper classes definitions
[AttributeUsage(AttributeTargets.Method)]
private sealed class MarkupAttribute : Attribute {}
private class WithMarkup
{
[Markup]
public void Bing() {}
public void RiloKiley() {}
}
private sealed class InheritedWithMarkup : WithMarkup
{
}
private interface SuperInterface
{
[Markup]
void TestMethod();
void TestMethod(string param);
}
private interface SubInterface : SuperInterface
{
[Markup]
void OtherTestMethod();
}
private class ImplementingClass : SubInterface
{
public void TestMethod() {}
public void TestMethod(string param) {}
public void OtherTestMethod() {}
}
private sealed class InheritedImplementingClass : ImplementingClass
{
}
#endregion
}
}

View File

@@ -0,0 +1,228 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using NUnit.Framework;
using Spring.Aop.Framework;
using Spring.Aop.Interceptor;
using Spring.Objects;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for the ControlFlowPointcut class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[TestFixture]
public sealed class ControlFlowPointcutTests
{
[Test]
[Category("Integration")]
public void Matches()
{
SerializablePerson target = new SerializablePerson();
target.SetAge(27);
ControlFlowPointcut cflow = new ControlFlowPointcut(typeof(One), "GetAge");
ProxyFactory factory = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
IPerson proxied = (IPerson) factory.GetProxy();
factory.AddAdvisor(new DefaultPointcutAdvisor(cflow, nop));
// not advised, not under One...
Assert.AreEqual(target.GetAge(), proxied.GetAge());
Assert.AreEqual(0, nop.Count, "Whoops, appear to be advising when not under One's cflow.");
// will be advised...
One one = new One();
Assert.AreEqual(27, one.GetAge(proxied));
Assert.AreEqual(1, nop.Count, "Not advising when under One's cflow (must be).");
// won't be advised...
Assert.AreEqual(target.GetAge(), new One().NoMatch(proxied));
Assert.AreEqual(1, nop.Count, "Whoops, appear to be advising when under One's cflow scope, BUT NOT under a target method's cflow scope.");
Assert.AreEqual(3, cflow.EvaluationCount, "Pointcut not invoked the correct number of times.");
}
private sealed class One
{
// attribute is required so that the delegated call is NOT jitted away...
[MethodImpl(MethodImplOptions.NoInlining)]
public int GetAge(IPerson proxied)
{
return proxied.GetAge();
}
public int NoMatch(IPerson proxied)
{
return proxied.GetAge();
}
// similarly, attribute is required so that the delegated call is NOT jitted away...
[MethodImpl(MethodImplOptions.NoInlining)]
public void Set(IPerson proxied)
{
proxied.SetAge(5);
}
}
/// <summary>
/// Check that we can use a cflow pointcut only in conjunction with
/// a static pointcut: e.g. all setter methods that are invoked under
/// a particular class.
/// </summary>
/// <remarks>
/// This greatly reduces the number of calls to the cflow pointcut,
/// meaning that it's not so prohibitively expensive.
/// </remarks>
[Test]
[Category("Integration")]
public void SelectiveApplication()
{
SerializablePerson target = new SerializablePerson();
target.SetAge(27);
NopInterceptor nop = new NopInterceptor();
ControlFlowPointcut cflow = new ControlFlowPointcut(typeof (One));
IPointcut settersUnderOne = Pointcuts.Intersection(SetterPointcut.Instance, cflow);
ProxyFactory pf = new ProxyFactory(target);
IPerson proxied = (IPerson) pf.GetProxy();
pf.AddAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop));
// Not advised, not under One
target.SetAge(16);
Assert.AreEqual(0, nop.Count);
// Not advised; under One but not a setter
Assert.AreEqual(16, new One().GetAge(proxied));
Assert.AreEqual(0, nop.Count);
// Won't be advised
new One().Set(proxied);
Assert.AreEqual(1, nop.Count);
// We saved most evaluations
Assert.AreEqual(1, cflow.EvaluationCount);
}
[Test]
public void EvaluationCountIncrementedEvenIfPointcutDoesNotMatch()
{
ControlFlowPointcut cut = new ControlFlowPointcut(typeof(One));
cut.Matches(null, null, null); // args are ingored in this impl...
Assert.AreEqual(1, cut.EvaluationCount);
cut.Matches(null, null, null); // args are ingored in this impl...
Assert.AreEqual(2, cut.EvaluationCount);
}
[Test]
public void EvaluationCountIncrementedOnEveryMatch()
{
Type oneType = typeof(One);
ControlFlowPointcut cut = new ControlFlowPointcut(oneType);
MethodInfo method = oneType.GetMethod("GetAge");
cut.Matches(method, oneType, null);
Assert.AreEqual(1, cut.EvaluationCount);
cut.Matches(method, oneType, null);
Assert.AreEqual(2, cut.EvaluationCount);
}
[Test]
public void DefaultClassFilterImplAlwaysMatchesRegardless()
{
Type oneType = typeof(One);
ControlFlowPointcut cut = new ControlFlowPointcut(oneType);
ITypeFilter filter = cut.TypeFilter;
Assert.IsTrue(filter.Matches(oneType),
"Must always match regardless of the supplied argument Type.");
Assert.IsTrue(filter.Matches(GetType()),
"Must always match even if the supplied argument Type is not " +
"a match for the Type supplied in the ctor.");
Assert.IsTrue(filter.Matches(null), // args are ingored in this impl...
"Must always match even if the supplied argument Type is null");
}
[Test]
public void StaticMethodMatchImplAlwaysMatchesRegardless()
{
Type oneType = typeof(One);
ControlFlowPointcut cut = new ControlFlowPointcut(oneType);
IMethodMatcher filter = cut.MethodMatcher;
MethodInfo method = oneType.GetMethod("GetAge");
Assert.IsTrue(filter.Matches(method, oneType),
"Must always match regardless of the supplied arguments.");
Assert.IsTrue(filter.Matches(method, GetType()),
"Must always match even if the supplied argument method and Type are not " +
"a match for the name and Type supplied in the ctor.");
Assert.IsTrue(filter.Matches(null, null), // args are ingored in this impl...
"Must always match even if the supplied arguments are null");
}
[Test]
public void DynamicMethodMatchWithJustTypeSpecifiedInCtor()
{
ControlFlowPointcut cut = new ControlFlowPointcut(GetType());
IMethodMatcher filter = cut.MethodMatcher;
Assert.IsTrue(filter.Matches(null, null, null), // args are ingored in this impl...
"Must match - under cflow of Type specified in ctor");
}
[Test]
public void DynamicMethodMatchWithTypeAndMethodNameSpecifiedInCtor()
{
ControlFlowPointcut cut = new ControlFlowPointcut(
GetType(), "DynamicMethodMatchWithTypeAndMethodNameSpecifiedInCtor");
IMethodMatcher filter = cut.MethodMatcher;
Assert.IsTrue(filter.Matches(null, null, null), // args are ingored in this impl...
"Must match - under cflow of Type specified in ctor");
}
[Test]
public void DynamicMethodMatchWithTypeAndMethodNameSpecifiedInCtorNoMatch()
{
ControlFlowPointcut cut = new ControlFlowPointcut(GetType(), "KiloRiley");
IMethodMatcher filter = cut.MethodMatcher;
Assert.IsFalse(filter.Matches(null, null, null), // args are ingored in this impl...
"Must not match - under cflow of Type specified in ctor, but no match on method name.");
}
#region Helper Classes
/// <summary>
/// Pointcut to catch all methods beginning with 'Set'.
/// </summary>
private class SetterPointcut : StaticMethodMatcherPointcut
{
public static SetterPointcut Instance = new SetterPointcut();
public override bool Matches(MethodInfo methodBase, Type targetType)
{
return methodBase.Name.StartsWith("Set");
}
}
#endregion
}
}

View File

@@ -0,0 +1,190 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using NUnit.Framework;
using DotNetMock.Dynamic;
using AopAlliance.Aop;
using Spring.Aop.Framework;
using Spring.Objects;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Translation of DelegatingIntroductionInterceptor unit tests to Spring.NET.
/// </summary>
/// <remarks>
/// Spring.NET doesn't have a DelegatingIntroductionInterceptor because it handles
/// introductions without using interception. So all the unit tests show how similar
/// things can be done in Spring.NET.
/// </remarks>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: DelegatingIntroductionInterceptorTests.cs,v 1.6 2004/10/10 08:01:49 gcaprio Exp $</version>
[TestFixture]
public class DelegatingIntroductionInterceptorTests
{
private static readonly DateTime EXPECTED_TIMESTAMP = new DateTime(2004,8,1);
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void testNullTarget()
{
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(null, typeof(ITimeStamped));
}
public interface ITimeStampedIntroduction: ITimeStamped, IAdvice
{
}
[Test]
public void testIntroductionInterceptorWithDelegation()
{
TestObject raw = new TestObject();
Assert.IsTrue(! (raw is ITimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction));
ITimeStampedIntroduction ts = (ITimeStampedIntroduction) tsControl.Object;
tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
factory.AddIntroduction(advisor);
ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
tsControl.Verify();
}
// we have to mark the ISubTimeStamped interface with the IAdvice marker
// in order to use it as an introduction.
public interface ISubTimeStampedIntroduction: ISubTimeStamped, IAdvice
{
}
public void testIntroductionInterceptorWithInterfaceHierarchy()
{
TestObject raw = new TestObject();
Assert.IsTrue(! (raw is ISubTimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction));
ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction) tsControl.Object;
tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
// we must add introduction, not an advisor
factory.AddIntroduction(advisor);
object proxy = factory.GetProxy();
ISubTimeStamped tsp = (ISubTimeStamped) proxy;
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
tsControl.Verify();
}
public void testIntroductionInterceptorWithSuperInterface()
{
TestObject raw = new TestObject();
Assert.IsTrue(! (raw is ITimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
IDynamicMock tsControl = new DynamicMock(typeof(ISubTimeStampedIntroduction));
ISubTimeStamped ts = (ISubTimeStamped) tsControl.Object;
tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);
factory.AddIntroduction(0, new DefaultIntroductionAdvisor(
(ISubTimeStampedIntroduction)ts,
typeof(ITimeStamped))
);
ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
Assert.IsTrue(!(tsp is ISubTimeStamped));
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
tsControl.Verify();
}
/// <summary>
/// test introduction.
/// <note>It must include the IAdvice marker interface to be a
/// valid introduction.</note>
/// </summary>
private class Test : ITimeStamped, ITest, IAdvice
{
private DateTime _timestamp;
public Test(DateTime timestamp)
{
_timestamp = timestamp;
}
public void foo()
{
}
public DateTime TimeStamp
{
get
{
return _timestamp;
}
}
}
public void testAutomaticInterfaceRecognitionInDelegate()
{
IIntroductionAdvisor ia = new DefaultIntroductionAdvisor(new Test(EXPECTED_TIMESTAMP));
TestObject target = new TestObject();
ProxyFactory pf = new ProxyFactory(target);
pf.AddIntroduction(0, ia);
ITimeStamped ts = (ITimeStamped) pf.GetProxy();
Assert.IsTrue(ts.TimeStamp == EXPECTED_TIMESTAMP);
((ITest) ts).foo();
int age = ((ITestObject) ts).Age;
}
/*
* The rest of the tests in the original tested subclassing the
* DelegatingIntroductionInterceptor.
*
* Since we don't need to subclass anything to make a delegating
* introduction, the rest of the tests are not necessary.
*/
// must be public to be used for AOP
// AOP creates a new assembly which must have access to the
// interfaces that it intends to expose.
public interface ITest
{
void foo();
}
public interface ISubTimeStamped : ITimeStamped
{
}
}
}

View File

@@ -0,0 +1,135 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using Spring.Aop.Framework;
using Spring.Aop.Interceptor;
using Spring.Context.Support;
using Spring.Objects;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
using Spring.Util;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for RegularExpressionMethodPointcutAdvisorTests.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Simon White (.NET)</author>
[TestFixture]
public class RegularExpressionMethodPointcutAdvisorTests
{
[TestFixtureSetUp]
public void FixtureSetUp()
{
SystemUtils.RegisterLoadedAssemblyResolver();
}
/// <summary>
/// Basic use case, a single pattern defined.
/// </summary>
[Test]
public void SinglePattern()
{
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("RegularExpressionSetterTests.xml", GetType()));
IPerson advised = (IPerson) iof.GetObject("SettersAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) iof.GetObject("NopInterceptor");
Assert.AreEqual(0, nop.Count);
int newAge = 12;
// Not advised
advised.Exceptional(null);
Assert.AreEqual(0, nop.Count);
advised.SetAge(newAge);
Assert.AreEqual(newAge, advised.GetAge());
// Only setter fired
Assert.AreEqual(1, nop.Count);
}
/// <summary>
/// Multiple patterns defined within a single advisor.
/// </summary>
[Test]
public void MultiplePatterns()
{
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("RegularExpressionSetterTests.xml", GetType()));
IPerson advised = (IPerson) iof.GetObject("SettersAndReturnsThisAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) iof.GetObject("NopInterceptor");
Assert.AreEqual(0, nop.Count);
int newAge = 12;
// Not advised
advised.Exceptional(null);
Assert.AreEqual(0, nop.Count);
// This is proxied
advised.ReturnsThis();
Assert.AreEqual(1, nop.Count);
// Only setter is advised
advised.SetAge(newAge);
Assert.AreEqual(2, nop.Count);
Assert.AreEqual(newAge, advised.GetAge());
Assert.AreEqual(2, nop.Count);
}
[Test]
public void Serialization()
{
IObjectFactory iof = new XmlObjectFactory(new ReadOnlyXmlTestResource("RegularExpressionSetterTests.xml", GetType()));
IPerson p = (IPerson) iof.GetObject("SerializableSettersAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) iof.GetObject("NopInterceptor");
Assert.AreEqual(0, nop.Count);
int newAge = 12;
// Not advised
Assert.AreEqual(0, p.GetAge());
Assert.AreEqual(0, nop.Count);
// This is proxied
p.SetAge(newAge);
Assert.AreEqual(1, nop.Count);
p.SetAge(newAge);
Assert.AreEqual(newAge, p.GetAge());
// Only setter fired
Assert.AreEqual(2, nop.Count);
// Serialize and continue...
p = (IPerson) SerializationTestUtils.SerializeAndDeserialize(p);
Assert.AreEqual(newAge, p.GetAge());
// Remembers count, but we need to get a new reference to nop...
nop = (SerializableNopInterceptor) ((IAdvised) p).Advisors[0].Advice;
Assert.AreEqual(2, nop.Count);
Assert.AreEqual("SerializableSettersAdvised", p.GetName());
p.SetAge(newAge + 1);
Assert.AreEqual(3, nop.Count);
Assert.AreEqual(newAge + 1, p.GetAge());
}
}
}

View File

@@ -0,0 +1,46 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for the RootTypeFilter class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: RootTypeFilterTests.cs,v 1.2 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class RootTypeFilterTests
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void InstantiationWithNullRootType()
{
new RootTypeFilter(null);
}
}
}

View File

@@ -0,0 +1,139 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Text.RegularExpressions;
using Common.Logging;
using Common.Logging.Simple;
using NUnit.Framework;
using Spring.Util;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for the SdkRegularExpressionMethodPointcut class.
/// </summary>
/// <author>Dmitriy Kopylenko</author>
/// <author>Rick Evans (.NET)</author>
[TestFixture]
public sealed class SdkRegularExpressionMethodPointcutTests : AbstractRegularExpressionMethodPointcutTests
{
/// <summary>
/// The setup logic executed before the execution of this test fixture.
/// </summary>
[TestFixtureSetUp]
public void FixtureSetUp()
{
// enable (null appender) logging, to ensure that the logging code is exercised
LogManager.Adapter = new NoOpLoggerFactoryAdapter();
}
/// <summary>
/// Returns the method pointcut implementation to be tested.
/// </summary>
/// <returns>The implementation.</returns>
protected override AbstractRegularExpressionMethodPointcut GetRegexpMethodPointcut()
{
return new SdkRegularExpressionMethodPointcut();
}
[Test]
public void InstantiationViaSerialization()
{
SdkRegularExpressionMethodPointcut initial = new SdkRegularExpressionMethodPointcut();
initial.Pattern = "Foo";
SdkRegularExpressionMethodPointcut pcut = (SdkRegularExpressionMethodPointcut) SerializationTestUtils.SerializeAndDeserialize(initial);
Assert.IsNotNull(pcut, "Deserialized instance must (obviously) not be null.");
Assert.AreEqual(initial.Pattern, pcut.Pattern, "Pattern property not deserialized correctly.");
}
/// <summary>
/// This exercises the logger after deserialization.
/// </summary>
[Test]
public void TryMatchesAfterSerialization()
{
SdkRegularExpressionMethodPointcut initial = new SdkRegularExpressionMethodPointcut();
initial.Pattern = "Foo";
SdkRegularExpressionMethodPointcut pcut = (SdkRegularExpressionMethodPointcut) SerializationTestUtils.SerializeAndDeserialize(initial);
Assert.IsNotNull(pcut, "Deserialized instance must (obviously) not be null.");
Type type = GetType();
bool isMatch = pcut.Matches(type.GetMethod("ForMatchingPurposesOnly"), type);
Assert.IsFalse(isMatch, "Whoops, should not be matching here at all.");
}
public void ForMatchingPurposesOnly ()
{
}
[Test]
public void MixedPatternsAndDefaultOptions()
{
Type type = GetType();
SdkRegularExpressionMethodPointcut pcut = new SdkRegularExpressionMethodPointcut();
pcut.DefaultOptions = RegexOptions.None;
pcut.Patterns = new object[] {"forMatching*", new Regex("xyz*", RegexOptions.Compiled)};
Assert.IsFalse(pcut.Matches(type.GetMethod("ForMatchingPurposesOnly"), type));
pcut.DefaultOptions = RegexOptions.IgnoreCase;
pcut.Patterns = new object[] { "forMatching*", new Regex("xyz*", RegexOptions.Compiled) };
Assert.IsTrue(pcut.Matches(type.GetMethod("ForMatchingPurposesOnly"), type));
pcut.DefaultOptions = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace;
pcut.Patterns = new object[] { "for matc \nhing*", new Regex("xyz*", RegexOptions.Compiled) };
Assert.IsTrue(pcut.Matches(type.GetMethod("ForMatchingPurposesOnly"), type));
}
[ExpectedException(typeof(ArgumentNullException))]
[Test]
public void SetPatternToNull()
{
SdkRegularExpressionMethodPointcut pcut = new SdkRegularExpressionMethodPointcut();
pcut.Pattern = null;
}
[ExpectedException(typeof(ArgumentNullException))]
[Test]
public void SetPatternsPluralToNull()
{
SdkRegularExpressionMethodPointcut pcut = new SdkRegularExpressionMethodPointcut();
pcut.Patterns = null;
}
[ExpectedException(typeof(ArgumentNullException))]
[Test]
public void SetPatternsPluralToStringArrayWithNullValue()
{
SdkRegularExpressionMethodPointcut pcut = new SdkRegularExpressionMethodPointcut();
pcut.Patterns = new string[] { null };
}
[Test]
public void InstantiationWithSuppliedPattern()
{
SdkRegularExpressionMethodPointcut pcut = new SdkRegularExpressionMethodPointcut("Foo");
Assert.AreEqual("Foo", pcut.Pattern, "Pattern supplied via the ctor was not set.");
}
}
}

View File

@@ -0,0 +1,68 @@
#region License
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Objects;
#endregion
namespace Spring.Aop.Support
{
/// <summary>
/// Unit tests for the TypeFilters class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Choy Rim (.NET)</author>
/// <version>$Id: TypeFiltersTests.cs,v 1.2 2005/07/21 16:01:12 springboy Exp $</version>
[TestFixture]
public sealed class TypeFiltersTests
{
private ITypeFilter exceptionFilter = new RootTypeFilter(typeof (Exception));
private ITypeFilter itoFilter = new RootTypeFilter(typeof (ITestObject));
private ITypeFilter hasRootCauseFilter = new RootTypeFilter(typeof (StackOverflowException));
[Test]
public void Union()
{
Assert.IsTrue(exceptionFilter.Matches(typeof (SystemException)));
Assert.IsFalse(exceptionFilter.Matches(typeof (TestObject)));
Assert.IsFalse(itoFilter.Matches(typeof (Exception)));
Assert.IsTrue(itoFilter.Matches(typeof (TestObject)));
ITypeFilter union = TypeFilters.Union(exceptionFilter, itoFilter);
Assert.IsTrue(union.Matches(typeof (SystemException)));
Assert.IsTrue(union.Matches(typeof (TestObject)));
}
[Test]
public void Intersection()
{
Assert.IsTrue(exceptionFilter.Matches(typeof (SystemException)));
Assert.IsTrue(hasRootCauseFilter.Matches(typeof (StackOverflowException)));
ITypeFilter intersection = TypeFilters.Intersection(exceptionFilter, hasRootCauseFilter);
Assert.IsFalse(intersection.Matches(typeof (SystemException)));
Assert.IsFalse(intersection.Matches(typeof (TestObject)));
Assert.IsTrue(intersection.Matches(typeof (StackOverflowException)));
}
}
}

View File

@@ -0,0 +1,63 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Util;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Unit tests for the EmptyTargetSource class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: EmptyTargetSourceTests.cs,v 1.2 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class EmptyTargetSourceTests
{
[Test]
public void Deserialization()
{
ITargetSource deserializedVersion
= (ITargetSource) SerializationTestUtils.SerializeAndDeserialize(
EmptyTargetSource.Empty);
Assert.IsTrue(Object.ReferenceEquals(EmptyTargetSource.Empty, deserializedVersion),
"Singleton instance not being deserialized correctly");
}
[Test]
public void IsSerializable()
{
Assert.IsTrue(SerializationTestUtils.IsSerializable(EmptyTargetSource.Empty),
"EmptyTargetSource.Empty must be serializable.");
}
[Test]
public void IsStatic()
{
Assert.IsTrue(EmptyTargetSource.Empty.IsStatic, "Must be static.");
}
}
}

View File

@@ -0,0 +1,124 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Unit tests for the HotSwappableTargetSource class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.NET)</author>
/// <version>$Id: HotSwappableTargetSourceTests.cs,v 1.4 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class HotSwappableTargetSourceTests
{
/// <summary>Initial count value set in Object factory XML </summary>
private const int INITIAL_COUNT = 10;
private IObjectFactory ObjectFactory;
[SetUp]
public void SetUp()
{
this.ObjectFactory = new XmlObjectFactory(
new ReadOnlyXmlTestResource("hotSwapTests.xml", GetType()));
}
/// <summary>
/// We must simulate container shutdown, which should clear threads.
/// </summary>
[TearDown]
public void TearDown()
{
this.ObjectFactory.Dispose();
}
[Test]
[Category("Integration")]
public void ValidSwaps()
{
ISideEffectObject target1 = (ISideEffectObject) ObjectFactory.GetObject("target1");
ISideEffectObject target2 = (ISideEffectObject) ObjectFactory.GetObject("target2");
ISideEffectObject proxied = (ISideEffectObject) ObjectFactory.GetObject("swappable");
// assertEquals(target1, ((Advised) proxied).getTarget());
Assert.AreEqual(target1.Count, proxied.Count);
proxied.doWork();
Assert.AreEqual(INITIAL_COUNT + 1, proxied.Count);
HotSwappableTargetSource swapper = (HotSwappableTargetSource) ObjectFactory.GetObject("swapper");
Object old = swapper.Swap(target2);
Assert.AreEqual(target1, old, "Correct old target was returned");
// TODO should be able to make this assertion: need to fix target handling
// in AdvisedSupport
//assertEquals(target2, ((Advised) proxied).getTarget());
Assert.AreEqual(20, proxied.Count);
proxied.doWork();
Assert.AreEqual(21, target2.Count);
// Swap it back
swapper.Swap(target1);
Assert.AreEqual(target1.Count, proxied.Count);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void RejectsSwapToNull()
{
HotSwappableTargetSource source = new HotSwappableTargetSource(null);
source.Swap(null);
}
[Test]
public void SwapDoesIndeedReturnTheOldTarget()
{
HotSwappableTargetSource source = new HotSwappableTargetSource(this);
object foo = source.Swap(new SideEffectObject());
Assert.IsTrue(object.ReferenceEquals(this, foo),
"Swap() is not returning the old target.");
}
[Test]
public void InstantiationWithNullIsOk()
{
new HotSwappableTargetSource(null);
}
[Test]
public void InstantiationWithInitialTarget()
{
HotSwappableTargetSource source = new HotSwappableTargetSource(this);
object foo = source.GetTarget();
Assert.IsTrue(object.ReferenceEquals(this, foo),
"Ctor is not storing the supplied target.");
}
}
}

View File

@@ -0,0 +1,141 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using Common.Logging;
using Common.Logging.Simple;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Unit tests for the PrototypeTargetSource class.
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi</author>
/// <version>$Id: PrototypeTargetSourceTests.cs,v 1.8 2007/07/28 07:33:22 markpollack Exp $</version>
[TestFixture]
public sealed class PrototypeTargetSourceTests
{
/// <summary>
/// The setup logic executed before the execution of this test fixture.
/// </summary>
[TestFixtureSetUp]
public void FixtureSetUp()
{
// enable (null appender) logging, just to ensure that the logging code is correct
LogManager.Adapter = new NoOpLoggerFactoryAdapter();
}
/// <summary>
/// Test that multiple invocations of the prototype object will result
/// in no change to visible state, as a new instance is used.
/// With the singleton, there will be change.
/// </summary>
[Test]
public void PrototypeAndSingletonBehaveDifferently()
{
int initialCount = 10;
IObjectFactory of = new XmlObjectFactory(new ReadOnlyXmlTestResource("prototypeTargetSourceTests.xml", GetType()));
ISideEffectObject singleton = (ISideEffectObject) of.GetObject("singleton");
Assert.AreEqual(initialCount, singleton.Count);
singleton.doWork();
Assert.AreEqual(initialCount + 1, singleton.Count);
ISideEffectObject prototype = (ISideEffectObject) of.GetObject("prototype");
Assert.AreEqual(initialCount, prototype.Count);
singleton.doWork();
Assert.AreEqual(initialCount, prototype.Count);
ISideEffectObject prototypeByName = (ISideEffectObject) of.GetObject("prototypeByName");
Assert.AreEqual(initialCount, prototypeByName.Count);
singleton.doWork();
Assert.AreEqual(initialCount, prototypeByName.Count);
}
[Test]
public void TargetType()
{
SideEffectObject target = new SideEffectObject();
IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));
mock.ExpectAndReturn("IsPrototype", true);
mock.ExpectAndReturn("GetType", typeof(SideEffectObject));
PrototypeTargetSource source = new PrototypeTargetSource();
source.ObjectFactory = (IObjectFactory) mock.Object;
Assert.AreEqual(target.GetType(), source.TargetType, "Wrong TargetType being returned.");
mock.Verify();
}
[Test]
public void IsStatic()
{
PrototypeTargetSource source = new PrototypeTargetSource();
Assert.IsFalse(source.IsStatic, "Must not be static.");
}
[Test]
public void WithNonSingletonTargetObject()
{
IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));
const string objectName = "Foo";
mock.ExpectAndReturn("IsPrototype", false, objectName);
PrototypeTargetSource source = new PrototypeTargetSource();
source.TargetObjectName = objectName;
try
{
source.ObjectFactory = (IObjectFactory) mock.Object;
Assert.Fail("Should have thrown an ObjectDefinitionStoreException by this point.");
}
catch (ObjectDefinitionStoreException)
{
mock.Verify();
}
}
[Test]
public void GetTarget()
{
SideEffectObject target = new SideEffectObject();
IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));
mock.ExpectAndReturn("IsPrototype", true);
mock.ExpectAndReturn("GetObject", target);
PrototypeTargetSource source = new PrototypeTargetSource();
source.ObjectFactory = (IObjectFactory) mock.Object;
Assert.IsTrue(object.ReferenceEquals(source.GetTarget(), target),
"Initial target source reference not being returned by GetTarget().");
mock.Verify();
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void AfterPropertiesSetWithoutTargetObjectNameBeingSet()
{
PrototypeTargetSource source = new PrototypeTargetSource();
source.AfterPropertiesSet();
}
}
}

View File

@@ -0,0 +1,96 @@
using NUnit.Framework;
using Spring.Aop.Target;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
/*
* Copyright 2002-2004 the original author or authors.
*
* 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 Spring.Aop.Target
{
/// <summary> Tests for pooling invoker interceptor
/// TODO need to make these tests stronger: it's hard to
/// make too many assumptions about a pool
/// </summary>
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi (.Net)</author>
/// <version> $Id: SimplePoolTargetSourceTests.cs,v 1.3 2006/02/08 08:31:05 aseovic Exp $
/// </version>
[TestFixture]
public class SimplePoolTargetSourceTests
{
/// <summary>Initial count value set in Object factory XML </summary>
private const int INITIAL_COUNT = 10;
private XmlObjectFactory objectFactory;
[SetUp]
public void SetUp()
{
objectFactory = new XmlObjectFactory(new ReadOnlyXmlTestResource("simplePoolTests.xml", GetType()));
}
/// <summary> We must simulate container shutdown, which should clear threads.</summary>
[TearDown]
public void TearDown()
{
// Will call pool.close()
this.objectFactory.Dispose();
}
private void Functionality(System.String name)
{
ISideEffectObject pooled = (ISideEffectObject) objectFactory.GetObject(name);
Assert.AreEqual(INITIAL_COUNT, pooled.Count);
pooled.doWork();
Assert.AreEqual(INITIAL_COUNT + 1, pooled.Count);
pooled = (ISideEffectObject) objectFactory.GetObject(name);
// Just check that it works--we can't make assumptions
// about the count
pooled.doWork();
//Assert.AreEqual(INITIAL_COUNT + 1, pooled.Count );
}
[Test]
public virtual void Functionality()
{
Functionality("pooled");
}
[Test]
public virtual void FunctionalityWithNoInterceptors()
{
Functionality("pooledNoInterceptors");
}
[Test]
public virtual void ConfigMixin()
{
ISideEffectObject pooled = (ISideEffectObject) objectFactory.GetObject("pooledWithMixin");
Assert.AreEqual(INITIAL_COUNT, pooled.Count);
PoolingConfig conf = (PoolingConfig) objectFactory.GetObject("pooledWithMixin");
// TODO one invocation from setup
// assertEquals(1, conf.getInvocations());
pooled.doWork();
// assertEquals("No objects active", 0, conf.getActive());
Assert.AreEqual(25, conf.MaxSize, "Correct target source");
// assertTrue("Some free", conf.getFree() > 0);
//assertEquals(2, conf.getInvocations());
Assert.AreEqual(25, conf.MaxSize);
}
}
}

View File

@@ -0,0 +1,82 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
#endregion
namespace Spring.Aop.Target
{
/// <summary>
/// Unit tests for the SingletonTargetSource class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: SingletonTargetSourceTests.cs,v 1.2 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class SingletonTargetSourceTests
{
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void InstantiationWithNullTargetSource()
{
new SingletonTargetSource(null);
}
[Test]
public void TargetType()
{
SingletonTargetSource source = new SingletonTargetSource(this);
Assert.AreEqual(GetType(), source.TargetType, "Wrong TargetType being returned.");
}
[Test]
public void IsStatic()
{
SingletonTargetSource source = new SingletonTargetSource(this);
Assert.IsTrue(source.IsStatic, "Must be static.");
}
[Test]
public void GetTarget()
{
SingletonTargetSource source = new SingletonTargetSource(this);
Assert.IsTrue(object.ReferenceEquals(source.GetTarget(), this),
"Same target source reference not being returned by GetTarget().");
}
[Test]
public void EqualsSameInstance()
{
SingletonTargetSource lhs = new SingletonTargetSource(this);
SingletonTargetSource rhs = new SingletonTargetSource(this);
Assert.AreEqual(lhs, rhs, "Equals() not correct for same instance comparison.");
}
[Test]
public void EqualsNullInstance()
{
SingletonTargetSource lhs = new SingletonTargetSource(this);
Assert.IsFalse(lhs.Equals(null), "Equals() not correct for null instance comparison.");
}
}
}

View File

@@ -0,0 +1,158 @@
/*
* Copyright 2002-2004 the original author or authors.
*
* 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.IO;
using System.Reflection;
using System.Threading;
using Common.Logging;
using NUnit.Framework;
using Spring.Objects;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Xml;
namespace Spring.Aop.Target
{
/// <author>Rod Johnson</author>
/// <author>Federico Spinazzi</author>
/// <version> $Id: ThreadLocalTargetSourceTests.cs,v 1.5 2006/11/13 07:04:51 markpollack Exp $
/// </version>
[TestFixture]
public class ThreadLocalTargetSourceTests
{
/// <summary>Initial count value set in Object factory XML </summary>
private const int INITIAL_COUNT = 10;
private XmlObjectFactory ObjectFactory;
private ILog log;
[SetUp]
public void SetUp ()
{
this.ObjectFactory = new XmlObjectFactory (
new ReadOnlyXmlTestResource ("threadLocalTests.xml", GetType ()));
//TODO-LOGGING XmlConfigurator.Configure (new FileInfo ("Spring.Aop.Tests.dll.config"));
log = LogManager.GetLogger (MethodBase.GetCurrentMethod ().DeclaringType);
}
/// <summary> We must simulate container shutdown, which should clear threads.</summary>
[TearDown]
public void TearDown ()
{
this.ObjectFactory.Dispose ();
}
/// <summary> Check we can use two different ThreadLocalTargetSources
/// managing objects of different types without them interfering
/// with one another.
/// </summary>
[Test]
public virtual void UseDifferentManagedInstancesInSameThread ()
{
ISideEffectObject apartment = (ISideEffectObject) ObjectFactory.GetObject ("apartment");
Assert.AreEqual (INITIAL_COUNT, apartment.Count);
apartment.doWork ();
Assert.AreEqual (INITIAL_COUNT + 1, apartment.Count);
ITestObject test = (ITestObject) ObjectFactory.GetObject ("threadLocal2");
Assert.AreEqual ("Rod", test.Name);
Assert.AreEqual ("Kerry", test.Spouse.Name);
}
[Test]
public virtual void ReuseInSameThread ()
{
ISideEffectObject apartment = (ISideEffectObject) ObjectFactory.GetObject ("apartment");
Assert.AreEqual (INITIAL_COUNT, apartment.Count);
apartment.doWork ();
Assert.AreEqual (INITIAL_COUNT + 1, apartment.Count);
apartment = (ISideEffectObject) ObjectFactory.GetObject ("apartment");
Assert.AreEqual (INITIAL_COUNT + 1, apartment.Count);
}
/// <summary> Relies on introduction
///
/// </summary>
[Test]
public virtual void CanGetStatsViaMixinIfThereIsAnInterceptorTakingCareOfThem ()
{
IThreadLocalTargetSourceStats stats = (IThreadLocalTargetSourceStats) ObjectFactory.GetObject ("apartment");
Assert.AreEqual (0, stats.Invocations);
ISideEffectObject apartment = (ISideEffectObject) ObjectFactory.GetObject ("apartment");
apartment.doWork ();
Assert.AreEqual (1, stats.Invocations);
Assert.AreEqual (0, stats.Hits);
apartment.doWork ();
Assert.AreEqual (2, stats.Invocations);
Assert.AreEqual (1, stats.Hits);
// Only one thread so only one object can have been bound
Assert.AreEqual (1, stats.Objects);
}
public class Runner
{
private ILog log = LogManager.GetLogger (MethodBase.GetCurrentMethod ().DeclaringType);
private ThreadLocalTargetSourceTests factory;
public ISideEffectObject mine;
public Runner (ThreadLocalTargetSourceTests enclosingInstance)
{
this.factory = enclosingInstance;
}
public virtual void Run ()
{
log.Debug ("getting object");
this.mine = (ISideEffectObject) factory.ObjectFactory.GetObject ("apartment");
log.Debug (String.Format ("got object; hash code: {0}", this.mine.GetHashCode ()));
Assert.AreEqual (ThreadLocalTargetSourceTests.INITIAL_COUNT, mine.Count);
mine.doWork ();
Assert.AreEqual (ThreadLocalTargetSourceTests.INITIAL_COUNT + 1, mine.Count);
}
}
[Test]
public virtual void NewThreadHasOwnInstance ()
{
ISideEffectObject apartment = (ISideEffectObject) ObjectFactory.GetObject ("apartment");
log.Debug (String.Format ("got object; hash code: {0}", apartment.GetHashCode ()));
Assert.AreEqual (INITIAL_COUNT, apartment.Count);
apartment.doWork ();
apartment.doWork ();
apartment.doWork ();
Assert.AreEqual (INITIAL_COUNT + 3, apartment.Count);
Runner r = new Runner (this);
Thread t = new Thread (new ThreadStart (r.Run));
t.Start ();
t.Join ();
Assert.IsNotNull (r);
// Check it didn't affect the other thread's copy
Assert.AreEqual (INITIAL_COUNT + 3, apartment.Count);
// When we use other thread's copy in this thread
// it should behave like ours
Assert.AreEqual (INITIAL_COUNT + 3, r.mine.Count);
// Bound to two threads
Assert.AreEqual (2, ((IThreadLocalTargetSourceStats) apartment).Objects);
}
}
}

View File

@@ -0,0 +1,78 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using NUnit.Framework;
using Spring.Util;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Unit tests for the TrueMethodMatcher class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: TrueMethodMatcherTests.cs,v 1.3 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class TrueMethodMatcherTests
{
[Test]
public void Deserialization()
{
IMethodMatcher deserializedVersion
= (IMethodMatcher) SerializationTestUtils.SerializeAndDeserialize(
TrueMethodMatcher.True);
Assert.IsTrue(Object.ReferenceEquals(TrueMethodMatcher.True, deserializedVersion),
"Singleton instance not being deserialized correctly");
}
[Test]
public void IsSerializable()
{
Assert.IsTrue(SerializationTestUtils.IsSerializable(TrueMethodMatcher.True),
"TrueMethodMatcher must be serializable.");
}
[Test]
public void AlwaysMatchesEvenOnNullArguments()
{
Assert.IsTrue(TrueMethodMatcher.True.Matches(null, null),
"Must always match (return true).");
}
[Test]
public void AlwaysMatches()
{
Assert.IsTrue(TrueMethodMatcher.True.Matches(
(MethodInfo) MethodBase.GetCurrentMethod(), GetType()),
"Must always match (return true).");
}
[Test]
public void IsRuntime()
{
Assert.IsFalse(TrueMethodMatcher.True.IsRuntime, "Must NOT be runtime.");
}
}
}

View File

@@ -0,0 +1,57 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Util;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Unit tests for the TruePointcut class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: TruePointcutTests.cs,v 1.2 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class TruePointcutTests
{
[Test]
public void Deserialization()
{
IPointcut deserializedVersion
= (IPointcut) SerializationTestUtils.SerializeAndDeserialize(
TruePointcut.True);
Assert.IsTrue(Object.ReferenceEquals(TruePointcut.True, deserializedVersion),
"Singleton instance not being deserialized correctly");
}
[Test]
public void IsSerializable()
{
Assert.IsTrue(SerializationTestUtils.IsSerializable(TruePointcut.True),
"TruePointcut must be serializable.");
}
}
}

View File

@@ -0,0 +1,75 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Util;
#endregion
namespace Spring.Aop
{
/// <summary>
/// Unit tests for the TrueTypeFilter class.
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: TrueTypeFilterTests.cs,v 1.3 2006/04/09 07:19:06 markpollack Exp $</version>
[TestFixture]
public sealed class TrueTypeFilterTests
{
[Test]
public void Deserialization()
{
ITypeFilter deserializedVersion
= (ITypeFilter) SerializationTestUtils.SerializeAndDeserialize(
TrueTypeFilter.True);
Assert.IsTrue(Object.ReferenceEquals(TrueTypeFilter.True, deserializedVersion),
"Singleton instance not being deserialized correctly");
}
[Test]
public void IsSerializable()
{
Assert.IsTrue(SerializationTestUtils.IsSerializable(TrueTypeFilter.True),
"TrueClassFilter must be serializable.");
}
[Test]
public void AlwaysMatchesEvenOnNullArgument()
{
Assert.IsTrue(TrueTypeFilter.True.Matches(null),
"Must always match (return true).");
}
[Test]
public void AlwaysMatches()
{
Assert.IsTrue(TrueTypeFilter.True.Matches(GetType()),
"Must always match (return true).");
}
[Test]
public void ToStringAlwaysTrue()
{
Assert.AreEqual("TrueTypeFilter.True", TrueTypeFilter.True.ToString() );
}
}
}

View File

@@ -0,0 +1,46 @@
#region License
/*
* Copyright 2004 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using NUnit.Framework;
#endregion
namespace Spring
{
/// <summary>
/// Unit tests for all of the exception classes in the Spring.Aop library...
/// </summary>
/// <author>Rick Evans</author>
/// <version>$Id: AopExceptionTests.cs,v 1.3 2006/04/09 07:19:04 markpollack Exp $</version>
[TestFixture]
public sealed class AopExceptionTests : ExceptionsTest
{
[TestFixtureSetUp]
public void FixtureSetUp ()
{
AssemblyToCheck = Assembly.GetAssembly (typeof (Spring.Aop.TruePointcut));
}
}
}

View File

@@ -0,0 +1,140 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Collections.Specialized;
using NUnit.Framework;
using Spring.Aop.Framework;
using Spring.Caching;
using Spring.Context;
using Spring.Context.Support;
#endregion
namespace Spring.Aspects.Cache
{
/// <summary>
/// Unit tests for the CacheParameterAdvice class.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: CacheAspectIntegrationTests.cs,v 1.4 2007/08/03 14:38:39 markpollack Exp $</version>
[TestFixture]
public sealed class CacheAspectIntegrationTests
{
private IApplicationContext context;
private CacheAspect cacheAspect;
private ICache cache;
[SetUp]
public void SetUp()
{
cache = new NonExpiringCache();
context = new XmlApplicationContext();
((IConfigurableApplicationContext) context).ObjectFactory.RegisterSingleton("inventors", cache);
cacheAspect = new CacheAspect();
cacheAspect.ApplicationContext = context;
}
[Test]
public void TestCaching()
{
ProxyFactory pf = new ProxyFactory(new InventorStore());
pf.AddAdvisors(cacheAspect);
IInventorStore store = (IInventorStore) pf.GetProxy();
Assert.AreEqual(0, cache.Count);
IList inventors = store.GetAll();
Assert.AreEqual(2, cache.Count);
store.Delete((Inventor) inventors[0]);
Assert.AreEqual(1, cache.Count);
Inventor tesla = store.Load("Nikola Tesla");
Assert.AreEqual(2, cache.Count);
store.Save(tesla);
Assert.AreEqual(2, cache.Count);
Assert.AreEqual("Serbian", ((Inventor)cache.Get("Nikola Tesla")).Nationality);
store.DeleteAll();
Assert.AreEqual(0, cache.Count);
}
}
#region Inner Class : CacheParameterTarget
public interface IInventorStore
{
IList GetAll();
Inventor Load(string name);
void Save(Inventor inventor);
void Delete(Inventor inventor);
void DeleteAll();
}
public sealed class InventorStore : IInventorStore
{
private IDictionary inventors = new ListDictionary();
public InventorStore()
{
Inventor tesla = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), null);
Inventor pupin = new Inventor("Mihajlo Pupin", new DateTime(1854, 10, 9), null);
inventors.Add("Nikola Tesla", tesla);
inventors.Add("Mihajlo Pupin", pupin);
}
[CacheResultItems("inventors", "Name")]
public IList GetAll()
{
return new ArrayList(inventors.Values);
}
[CacheResult("inventors", "#name")]
public Inventor Load(string name)
{
return (Inventor) inventors[name];
}
public void Save([CacheParameter("inventors", "Name")] Inventor inventor)
{
inventor.Nationality = "Serbian";
}
[InvalidateCache("inventors", Keys = "#inventor.Name")]
public void Delete(Inventor inventor)
{
}
[InvalidateCache("inventors")]
public void DeleteAll()
{
}
}
#endregion
}

View File

@@ -0,0 +1,143 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Caching;
using Spring.Context;
#endregion
namespace Spring.Aspects.Cache
{
/// <summary>
/// Unit tests for the CacheParameterAdvice class.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: CacheParameterAdviceTests.cs,v 1.6 2007/04/01 15:05:33 bbaia Exp $</version>
[TestFixture]
public sealed class CacheParameterAdviceTests
{
private IDynamicMock mockContext;
private CacheParameterAdvice advice;
private ICache cache;
[SetUp]
public void SetUp()
{
mockContext = new DynamicMock(typeof (IApplicationContext));
advice = new CacheParameterAdvice();
advice.ApplicationContext = (IApplicationContext) mockContext.Object;
cache = new NonExpiringCache();
}
[Test]
public void TestSimpleParameterCaching()
{
MethodInfo method = typeof(SimpleCacheParameterTarget).GetMethod("Save");
object[] args = new object[] {new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian")};
ExpectCacheInstanceRetrieval("cache", cache);
// parameter value should be added to cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(1, cache.Count);
Assert.AreEqual(args[0], cache.Get("Nikola Tesla"));
mockContext.Verify();
}
[Test]
public void TestMultipleParameterCaching()
{
MethodInfo method = typeof(MultipleCacheParameterTarget).GetMethod("Save");
object[] args = new object[] { new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian") };
ExpectCacheInstanceRetrieval("cache", cache);
ExpectCacheInstanceRetrieval("cache", cache);
// parameter value should be added to both cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(2, cache.Count);
Assert.AreEqual(args[0], cache.Get("Nikola Tesla"));
Assert.AreEqual(args[0], cache.Get("Serbian"));
mockContext.Verify();
}
[Test]
public void TestConditionParameterCaching()
{
MethodInfo method = typeof(ConditionCacheParameterTarget).GetMethod("Save");
object[] args = new object[] { new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian") };
// parameter value should not be added to cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(0, cache.Count);
mockContext.Verify();
}
#region Helper methods
private void ExpectCacheInstanceRetrieval(string cacheName, ICache cache)
{
mockContext.ExpectAndReturn("GetObject", cache, cacheName);
}
#endregion
}
#region Inner Class : CacheParameterTarget
public interface ICacheParameterTarget
{
void Save(Inventor inventor);
}
public sealed class SimpleCacheParameterTarget : ICacheParameterTarget
{
public void Save([CacheParameter("cache", "Name")] Inventor inventor)
{
}
}
public sealed class MultipleCacheParameterTarget : ICacheParameterTarget
{
public void Save([CacheParameter("cache", "Name")][CacheParameter("cache", "Nationality")] Inventor inventor)
{
}
}
public sealed class ConditionCacheParameterTarget : ICacheParameterTarget
{
public void Save([CacheParameter("cache", "Name", Condition = "Nationality == 'French'")] Inventor inventor)
{
}
}
#endregion
}

View File

@@ -0,0 +1,394 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System.Collections;
using System.Reflection;
using AopAlliance.Intercept;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Caching;
using Spring.Context;
#endregion
namespace Spring.Aspects.Cache
{
/// <summary>
/// Unit tests for the CacheResultAdvice class.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: CacheResultAdviceTests.cs,v 1.4 2007/08/22 20:16:51 oakinger Exp $</version>
[TestFixture]
public sealed class CacheResultAdviceTests
{
private IDynamicMock mockInvocation;
private IDynamicMock mockContext;
private CacheResultAdvice advice;
private ICache resultCache;
private ICache itemCache;
[SetUp]
public void SetUp()
{
mockInvocation = new DynamicMock(typeof(IMethodInvocation));
mockContext = new DynamicMock(typeof(IApplicationContext));
advice = new CacheResultAdvice();
advice.ApplicationContext = (IApplicationContext) mockContext.Object;
resultCache = new NonExpiringCache();
itemCache = new NonExpiringCache();
}
/// <summary>
/// Change History:
/// 2007-08-22 (oakinger): changed behaviour to cache null values as well
/// </summary>
[Test]
public void CacheResultOfMethodThatReturnsNull()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("ReturnsNothing");
object expectedReturnValue = null;
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, null);
ExpectCacheInstanceRetrieval("results", resultCache);
ExpectCallToProceed(expectedReturnValue);
// check that the null retVal is cached as well - it might be
// the result of an expensive webservice/database call etc.
object returnValue = advice.Invoke((IMethodInvocation) mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(1, resultCache.Count);
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheResultOfMethodThatReturnsObject()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("ReturnsScalar");
object expectedReturnValue = CacheResultTarget.Scalar;
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, null);
ExpectCacheInstanceRetrieval("results", resultCache);
ExpectCallToProceed(expectedReturnValue);
// return value should be added to cache
object returnValue = advice.Invoke((IMethodInvocation) mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(1, resultCache.Count);
// and again, but without Proceed()...
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, null);
ExpectCacheInstanceRetrieval("results", resultCache);
// cached value should be returned
object cachedValue = advice.Invoke((IMethodInvocation) mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, cachedValue);
Assert.AreEqual(1, resultCache.Count);
Assert.AreSame(returnValue, cachedValue);
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheResultOfMethodThatReturnsCollection()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("ReturnsCollection");
object expectedReturnValue = new object[] {"one", "two", "three"};
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, 5, expectedReturnValue);
ExpectCacheInstanceRetrieval("results", resultCache);
ExpectCallToProceed(new object[] { "one", "two", "three" });
// return value should be added to cache
object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(1, resultCache.Count);
// and again, but without Proceed()...
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, 5, expectedReturnValue);
ExpectCacheInstanceRetrieval("results", resultCache);
// cached value should be returned
object cachedValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, cachedValue);
Assert.AreNotSame(expectedReturnValue, cachedValue);
Assert.AreEqual(expectedReturnValue, resultCache.Get(5));
Assert.AreEqual(1, resultCache.Count);
Assert.AreSame(returnValue, cachedValue);
Assert.AreSame(cachedValue, resultCache.Get(5));
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheResultAndItemsOfMethodThatReturnsCollection()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("ReturnsCollectionAndItems");
object expectedReturnValue = new object[] { "one", "two", "three" };
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, 5, expectedReturnValue);
ExpectCacheInstanceRetrieval("results", resultCache);
ExpectCallToProceed(new object[] { "one", "two", "three" });
ExpectCacheInstanceRetrieval("items", itemCache);
// return value should be added to result cache and each item to item cache
object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(1, resultCache.Count);
Assert.AreEqual(3, itemCache.Count);
// and again, but without Proceed() and item cache access...
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, 5, expectedReturnValue);
ExpectCacheInstanceRetrieval("results", resultCache);
// cached value should be returned
object cachedValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, cachedValue);
Assert.AreNotSame(expectedReturnValue, cachedValue);
Assert.AreEqual(expectedReturnValue, resultCache.Get(5));
Assert.AreEqual(1, resultCache.Count);
Assert.AreEqual(3, itemCache.Count);
Assert.AreSame(returnValue, cachedValue);
Assert.AreSame(cachedValue, resultCache.Get(5));
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheOnlyItemsOfMethodThatReturnsCollection()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("ReturnsItems");
object expectedReturnValue = new object[] { "one", "two", "three" };
ExpectAttributeRetrieval(method);
ExpectCallToProceed(new object[] { "one", "two", "three" });
ExpectCacheInstanceRetrieval("items", itemCache);
// return value should be added to result cache and each item to item cache
object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(0, resultCache.Count);
Assert.AreEqual(3, itemCache.Count);
// and again, but without Proceed() and item cache access...
ExpectAttributeRetrieval(method);
ExpectCallToProceed(new object[] { "one", "two", "three" });
ExpectCacheInstanceRetrieval("items", itemCache);
// new return value should be returned
object newReturnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, newReturnValue);
Assert.AreEqual(0, resultCache.Count);
Assert.AreEqual(3, itemCache.Count);
Assert.AreEqual("two", itemCache.Get("two"));
Assert.AreNotSame(returnValue, newReturnValue);
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheOnlyItemsOfMethodThatReturnsCollectionWithinTwoDifferentCaches()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("MultipleCacheResultItems");
object expectedReturnValue = new object[] { "one", "two", "three" };
ExpectAttributeRetrieval(method);
ExpectCallToProceed(new object[] { "one", "two", "three" });
ExpectCacheInstanceRetrieval("items", itemCache);
ExpectCacheInstanceRetrieval("items", itemCache);
// return value should be added to result cache and each item to item cache
object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(0, resultCache.Count);
Assert.AreEqual(6, itemCache.Count);
// and again, but without Proceed() and item cache access...
ExpectAttributeRetrieval(method);
ExpectCallToProceed(new object[] { "one", "two", "three" });
ExpectCacheInstanceRetrieval("items", itemCache);
ExpectCacheInstanceRetrieval("items", itemCache);
// new return value should be returned
object newReturnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, newReturnValue);
Assert.AreEqual(0, resultCache.Count);
Assert.AreEqual(6, itemCache.Count);
Assert.AreEqual("two", itemCache.Get("two"));
Assert.AreEqual("two", itemCache.Get("TWO"));
Assert.AreNotSame(returnValue, newReturnValue);
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheOnlyItemsOfMethodThatReturnsCollectionOnCondition()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("CacheResultItemsWithCondition");
object expectedReturnValue = new object[] { "one", "two", "three" };
ExpectAttributeRetrieval(method);
ExpectCallToProceed(new object[] { "one", "two", "three" });
ExpectCacheInstanceRetrieval("items", itemCache);
// return value should be added to result cache and each item to item cache
object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(2, itemCache.Count);
Assert.AreEqual("two", itemCache.Get("two"));
Assert.AreEqual("three", itemCache.Get("three"));
mockInvocation.Verify();
mockContext.Verify();
}
[Test]
public void CacheResultOfMethodThatReturnsCollectionOnCondition()
{
MethodInfo method = typeof(CacheResultTarget).GetMethod("CacheResultWithCondition");
object expectedReturnValue = new object[] { };
ExpectAttributeRetrieval(method);
ExpectCacheKeyGeneration(method, 5, expectedReturnValue);
ExpectCacheInstanceRetrieval("results", resultCache);
ExpectCallToProceed(new object[] { });
// return value should not be added to cache
object returnValue = advice.Invoke((IMethodInvocation)mockInvocation.Object);
Assert.AreEqual(expectedReturnValue, returnValue);
Assert.AreEqual(0, resultCache.Count);
mockInvocation.Verify();
mockContext.Verify();
}
#region Helper methods
private void ExpectAttributeRetrieval(MethodInfo method)
{
mockInvocation.ExpectAndReturn("Method", method);
mockInvocation.ExpectAndReturn("Method", method);
}
private void ExpectCacheKeyGeneration(MethodInfo method, params object[] arguments)
{
mockInvocation.ExpectAndReturn("Method", method);
mockInvocation.ExpectAndReturn("Arguments", arguments);
}
private void ExpectCacheInstanceRetrieval(string cacheName, ICache cache)
{
mockContext.ExpectAndReturn("GetObject", cache, cacheName);
}
private void ExpectCallToProceed(object expectedReturnValue)
{
mockInvocation.ExpectAndReturn("Proceed", expectedReturnValue);
}
#endregion
}
#region Inner Class : CacheResultTarget
public interface ICacheResultTarget
{
void ReturnsNothing();
int ReturnsScalar();
ICollection ReturnsCollection(int key, params object[] elements);
ICollection ReturnsCollectionAndItems(int key, params object[] elements);
ICollection ReturnsItems(int key, params object[] elements);
}
public sealed class CacheResultTarget : ICacheResultTarget
{
public const int Scalar = int.MaxValue;
[CacheResult("results", "'key'")]
public void ReturnsNothing()
{
}
[CacheResult("results", "'key'")]
public int ReturnsScalar()
{
return Scalar;
}
[CacheResult("results", "#key")]
public ICollection ReturnsCollection(int key, params object[] elements)
{
return elements;
}
[CacheResult("results", "#key")]
[CacheResultItems("items", "#this")]
public ICollection ReturnsCollectionAndItems(int key, params object[] elements)
{
return elements;
}
[CacheResultItems("items", "#this")]
public ICollection ReturnsItems(int key, params object[] elements)
{
return elements;
}
[CacheResultItems("items", "#this")]
[CacheResultItems("items", "#this.ToUpper()")]
public ICollection MultipleCacheResultItems(int key, params object[] elements)
{
return elements;
}
[CacheResultItems("items", "#this", Condition="#this.StartsWith('t')")]
public ICollection CacheResultItemsWithCondition(int key, params object[] elements)
{
return elements;
}
[CacheResult("results", "#key", Condition="#this.Length > 0")]
public ICollection CacheResultWithCondition(int key, params object[] elements)
{
return elements;
}
}
#endregion
}

View File

@@ -0,0 +1,189 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Caching;
using Spring.Context;
#endregion
namespace Spring.Aspects.Cache
{
/// <summary>
/// Unit tests for the InvalidateCacheAdvice class.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: InvalidateCacheAdviceTests.cs,v 1.4 2007/04/01 15:05:34 bbaia Exp $</version>
[TestFixture]
public sealed class InvalidateCacheAdviceTests
{
private IDynamicMock mockContext;
private InvalidateCacheAdvice advice;
private ICache cache;
[SetUp]
public void SetUp()
{
mockContext = new DynamicMock(typeof (IApplicationContext));
advice = new InvalidateCacheAdvice();
advice.ApplicationContext = (IApplicationContext) mockContext.Object;
cache = new NonExpiringCache();
cache.Insert(1, "one");
cache.Insert(2, "two");
cache.Insert(3, "three");
}
[Test]
public void TestSingleKeyInvalidation()
{
MethodInfo method = typeof(InvalidateCacheTarget).GetMethod("InvalidateSingle");
object[] args = new object[] { 2 };
ExpectCacheInstanceRetrieval("cache", cache);
Assert.AreEqual(3, cache.Count);
// item "two" should be removed from cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(2, cache.Count);
Assert.IsNull(cache.Get(2));
mockContext.Verify();
}
[Test]
public void TestMultiKeyInvalidation()
{
MethodInfo method = typeof(InvalidateCacheTarget).GetMethod("InvalidateMulti");
object[] args = new object[] { 2 };
ExpectCacheInstanceRetrieval("cache", cache);
Assert.AreEqual(3, cache.Count);
// all items except item "two" should be removed from cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(1, cache.Count);
Assert.AreEqual("two", cache.Get(2));
mockContext.Verify();
}
[Test]
public void TestWholeCacheInvalidation()
{
MethodInfo method = typeof(InvalidateCacheTarget).GetMethod("InvalidateAll");
ExpectCacheInstanceRetrieval("cache", cache);
Assert.AreEqual(3, cache.Count);
// all items should be removed from cache
advice.AfterReturning(null, method, null, null);
Assert.AreEqual(0, cache.Count);
mockContext.Verify();
}
[Test]
public void TestMultipleCachesInvalidation()
{
MethodInfo method = typeof(InvalidateCacheTarget).GetMethod("InvalidateMultipleCaches");
object[] args = new object[] { 2 };
ExpectCacheInstanceRetrieval("cache", cache);
ExpectCacheInstanceRetrieval("cache", cache);
Assert.AreEqual(3, cache.Count);
// item "two" should be removed from cache
// all items except item "two" should be removed from cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(0, cache.Count);
mockContext.Verify();
}
[Test]
public void TestConditionInvalidation()
{
MethodInfo method = typeof(InvalidateCacheTarget).GetMethod("InvalidateWithCondition");
object[] args = new object[] { 3 };
Assert.AreEqual(3, cache.Count);
// no items should be removed from cache
advice.AfterReturning(null, method, args, null);
Assert.AreEqual(3, cache.Count);
Assert.AreEqual("three", cache.Get(3));
mockContext.Verify();
}
#region Helper methods
private void ExpectCacheInstanceRetrieval(string cacheName, ICache cache)
{
mockContext.ExpectAndReturn("GetObject", cache, cacheName);
}
#endregion
}
#region Inner Class : InvalidateCacheTarget
public sealed class InvalidateCacheTarget
{
[InvalidateCache("cache", Keys = "#key")]
public void InvalidateSingle(int key)
{
}
[InvalidateCache("cache", Keys = "{1, 2, 3} - { #key }")]
public void InvalidateMulti(int key)
{
}
[InvalidateCache("cache")]
public void InvalidateAll()
{
}
[InvalidateCache("cache", Keys = "#key")]
[InvalidateCache("cache", Keys = "{1, 2, 3} - { #key }")]
public void InvalidateMultipleCaches(int key)
{
}
[InvalidateCache("cache", Keys = "{1, 2, 3} - { #key }", Condition="#key != 3")]
public void InvalidateWithCondition(int key)
{
}
}
#endregion
}

View File

@@ -0,0 +1,336 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Collections;
using System.Collections.Specialized;
using Common.Logging;
using Common.Logging.Simple;
using NUnit.Framework;
using Spring.Aop.Framework;
using Spring.Aspects.Exceptions;
using Spring.Expressions;
using Spring.Objects;
#endregion
namespace Spring.Aspects.Exceptions
{
/// <summary>
/// This class contains tests for ExceptionHandlerAdvice
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: ExceptionHandlerAspectIntegrationTests.cs,v 1.6 2008/02/26 00:03:43 markpollack Exp $</version>
[TestFixture]
public class ExceptionHandlerAspectIntegrationTests
{
private ExceptionHandlerAdvice exceptionHandlerAdvice;
[SetUp]
public void Setup()
{
LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(new NameValueCollection());
exceptionHandlerAdvice = new ExceptionHandlerAdvice();
}
[Test]
public void LoggingTest()
{
LogExceptionHandler logHandler = new LogExceptionHandler();
string testText = @"#log.Debug('Hello World, exception message = ' + #e.Message + ', target method = ' + #method.Name)";
logHandler.SourceExceptionNames.Add("ArithmeticException");
logHandler.ActionExpressionText = testText;
exceptionHandlerAdvice.ExceptionHandlers.Add(logHandler);
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
ITestObject to = (ITestObject) pf.GetProxy();
try
{
to.Exceptional(new ArithmeticException());
Assert.Fail("Should have thrown exception when only logging");
} catch (ArithmeticException)
{
//TODO need to create adapter implementation to replay logged text.
}
}
[Test]
public void LoggingTestWithString()
{
string logHandlerText = "on exception name ArithmeticException log 'My Message, Method Name ' + #method.Name";
ExecuteLoggingHandler(logHandlerText);
}
[Test]
public void LoggingTestWithConstraintExpression()
{
string logHandlerText = "on exception (#e is T(System.ArithmeticException)) log 'My Message, Method Name ' + #method.Name";
ExecuteLoggingHandler(logHandlerText);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void LoggingTestWithBadString()
{
string logHandlerText = "on foobar name ArithmeticException log 'My Message, Method Name ' + #method.Name";
ExecuteLoggingHandler(logHandlerText);
}
[Test]
public void LoggingTestWithInvalidConstraintExpression()
{
string logHandlerText = "on exception (#e is System.FooBar) log 'My Message, Method Name ' + #method.Name";
ExecuteLoggingHandler(logHandlerText);
//No exception is expected.
//TODO need to make sure log statement was executed.
}
[Test]
public void LoggingTestWithNonBooleanConstraintExpression()
{
string logHandlerText = "on exception (1+1) log 'My Message, Method Name ' + #method.Name";
ExecuteLoggingHandler(logHandlerText);
//No exception is expected.
//TODO need to make sure log statement was executed.
}
private void ExecuteLoggingHandler(string logHandlerText)
{
ITestObject to = CreateTestObjectProxy(logHandlerText);
try
{
to.Exceptional(new ArithmeticException());
}
catch (ArithmeticException)
{
//TODO assert logging occured.
}
}
[Test]
public void TranslationWithString()
{
string translationHandlerText =
"on exception name ArithmeticException translate new System.InvalidOperationException('My Message, Method Name ' + #method.Name, #e)";
ITestObject to = CreateTestObjectProxy(translationHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
Assert.Fail("Should have thrown exception");
}
catch (InvalidOperationException e)
{
Assert.IsInstanceOfType(typeof(ArithmeticException), e.InnerException, "Inner exception.");
Assert.AreEqual("My Message, Method Name Exceptional", e.Message);
} catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e, "wrong exception type thrown.");
}
}
[Test]
public void WrapWithString()
{
string translationHandlerText =
"on exception name ArithmeticException wrap System.InvalidOperationException 'My Message'";
ITestObject to = CreateTestObjectProxy(translationHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
Assert.Fail("Should have thrown exception");
}
catch (InvalidOperationException e)
{
Assert.IsInstanceOfType(typeof(ArithmeticException), e.InnerException);
Assert.AreEqual("My Message", e.Message);
}
catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e);
}
}
[Test]
public void WrapWithStringDefaultMessage()
{
string translationHandlerText =
"on exception name ArithmeticException wrap System.InvalidOperationException";
ITestObject to = CreateTestObjectProxy(translationHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
Assert.Fail("Should have thrown exception");
}
catch (InvalidOperationException e)
{
Assert.IsInstanceOfType(typeof(ArithmeticException), e.InnerException);
Assert.AreEqual("Wrapped ArithmeticException", e.Message);
}
catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e);
}
}
[Test]
public void ReplaceWithString()
{
string translationHandlerText =
"on exception name ArithmeticException replace System.InvalidOperationException 'My Message'";
ITestObject to = CreateTestObjectProxy(translationHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
Assert.Fail("Should have thrown exception");
}
catch (InvalidOperationException e)
{
Assert.IsNull(e.InnerException);
Assert.AreEqual("My Message", e.Message);
}
catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e);
}
}
[Test]
public void ReplaceWithStringDefaultMessage()
{
string translationHandlerText =
"on exception name ArithmeticException replace System.InvalidOperationException";
ITestObject to = CreateTestObjectProxy(translationHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
Assert.Fail("Should have thrown exception");
}
catch (InvalidOperationException e)
{
Assert.IsNull(e.InnerException);
Assert.AreEqual("Replaced ArithmeticException", e.Message);
}
catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e);
}
}
[Test]
public void SwallowWithString()
{
string returnHandlerText = "on exception name ArithmeticException swallow";
ITestObject to = CreateTestObjectProxy(returnHandlerText);
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
} catch (Exception)
{
Assert.Fail("Should not have thrown exception");
}
}
[Test]
public void ReturnWithString()
{
string returnHandlerText = "on exception name ArithmeticException return 12";
ITestObject to = CreateTestObjectProxy(returnHandlerText);
try
{
int retVal = to.ExceptionalWithReturnValue(new ArithmeticException("Bad Math"));
Assert.AreEqual(12, retVal);
}
catch (Exception)
{
Assert.Fail("Should not have thrown exception");
}
}
[Test]
public void ChainLogAndWrap()
{
string logHandlerText = "on exception name ArithmeticException log 'My Message, Method Name ' + #method.Name";
string translationHandlerText = "on exception name ArithmeticException wrap System.InvalidOperationException 'My Message'";
exceptionHandlerAdvice.ExceptionHandlers.Add(logHandlerText);
exceptionHandlerAdvice.ExceptionHandlers.Add(translationHandlerText);
exceptionHandlerAdvice.AfterPropertiesSet();
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
ITestObject to = (ITestObject)pf.GetProxy();
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
Assert.Fail("Should have thrown exception");
}
catch (InvalidOperationException e)
{
Assert.IsNotNull(e.InnerException);
Exception innerEx = e.InnerException;
Assert.AreEqual("My Message", e.Message);
Assert.AreEqual("Bad Math", innerEx.Message);
}
catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e);
}
}
private ITestObject CreateTestObjectProxy(string logHandlerText)
{
exceptionHandlerAdvice.ExceptionHandlers.Add(logHandlerText);
exceptionHandlerAdvice.AfterPropertiesSet();
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
return (ITestObject)pf.GetProxy();
}
}
}

View File

@@ -0,0 +1,190 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using System.Text;
using AopAlliance.Intercept;
using Common.Logging;
using NUnit.Framework;
using Rhino.Mocks;
#endregion
namespace Spring.Aspects.Logging
{
/// <summary>
/// This class contains tests for SimpleLoggingAdvice
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: SimpleLoggingAdviceTests.cs,v 1.4 2008/04/04 14:59:47 bbaia Exp $</version>
[TestFixture]
public class SimpleLoggingAdviceTests
{
private MockRepository mocks;
[SetUp]
public void Setup()
{
mocks = new MockRepository();
}
[Test]
public void SunnyDayLoggingCorrectly()
{
ILog log = (ILog)mocks.CreateMock(typeof(ILog));
IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation));
MethodInfo mi = typeof(string).GetMethod("ToString", Type.EmptyTypes);
//two additional calls the method are to retrieve the method name on entry/exit...
Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any();
Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
log.Trace("Entering ToString");
Expect.Call(methodInvocation.Proceed()).Return(null);
log.Trace("Exiting ToString");
mocks.ReplayAll();
TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
mocks.VerifyAll();
}
[Test]
public void SunnyDayLoggingCorrectlyDebugLevel()
{
ILog log = (ILog)mocks.CreateMock(typeof(ILog));
IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation));
MethodInfo mi = typeof(string).GetMethod("ToString", Type.EmptyTypes);
//two additional calls the method are to retrieve the method name on entry/exit...
Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any();
Expect.Call(log.IsTraceEnabled).Return(false).Repeat.Any();
Expect.Call(log.IsDebugEnabled).Return(true).Repeat.Any();
log.Debug("Entering ToString");
Expect.Call(methodInvocation.Proceed()).Return(null);
log.Debug("Exiting ToString");
mocks.ReplayAll();
TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
loggingAdvice.LogLevel = LogLevel.Debug;
Assert.IsTrue(loggingAdvice.CallIsInterceptorEnabled(methodInvocation, log));
loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
mocks.VerifyAll();
}
[Test]
public void ExceptionPathStillLogsCorrectly()
{
ILog log = (ILog)mocks.CreateMock(typeof(ILog));
IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation));
MethodInfo mi = typeof(string).GetMethod("ToString", Type.EmptyTypes);
//two additional calls the method are to retrieve the method name on entry/exit...
Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any();
Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
log.Trace("Entering...");
LastCall.On(log).IgnoreArguments();
Exception e = new ArgumentException("bad value");
Expect.Call(methodInvocation.Proceed()).Throw(e);
log.Trace("Exception...", e);
LastCall.On(log).IgnoreArguments();
mocks.ReplayAll();
TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
try
{
loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
Assert.Fail("Must have propagated the IllegalArgumentException.");
}
catch (ArgumentException)
{
}
mocks.VerifyAll();
}
[Test]
public void SunnyDayLoggingAllOptionalInformationCorrectly()
{
ILog log = (ILog)mocks.CreateMock(typeof(ILog));
IMethodInvocation methodInvocation = (IMethodInvocation)mocks.CreateMock(typeof(IMethodInvocation));
MethodInfo mi = typeof(Dog).GetMethod("Bark");
//two additional calls the method are to retrieve the method name on entry/exit...
Expect.Call(methodInvocation.Method).Return(mi).Repeat.Any();
int[] luckyNumbers = new int[]{1, 2, 3};
object[] args = new object[] {"hello", luckyNumbers};
Expect.Call(methodInvocation.Arguments).Return(args);
Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
log.Trace("Entering...");
LastCall.IgnoreArguments();
Expect.Call(methodInvocation.Proceed()).Return(4);
log.Trace("Exiting...");
LastCall.IgnoreArguments();
mocks.ReplayAll();
TestableSimpleLoggingAdvice loggingAdvice = new TestableSimpleLoggingAdvice(true);
loggingAdvice.LogExecutionTime = true;
loggingAdvice.LogMethodArguments = true;
loggingAdvice.LogUniqueIdentifier = true;
loggingAdvice.CallInvokeUnderLog(methodInvocation, log);
mocks.VerifyAll();
}
}
public class Dog
{
public int Bark(string message, int[] luckyNumbers)
{
return 4;
}
}
}

View File

@@ -0,0 +1,71 @@
#region License
/*
* Copyright 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
using AopAlliance.Intercept;
using Common.Logging;
namespace Spring.Aspects.Logging
{
/// <summary>
/// This is simple wrapper to expose the protected methood InvokeUnderLog in the class
/// SimpleLoggingAdvice for testing purposes.
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: TestableSimpleLoggingAdvice.cs,v 1.2 2007/12/06 17:17:24 markpollack Exp $</version>
public class TestableSimpleLoggingAdvice : SimpleLoggingAdvice
{
/// <summary>
/// Initializes a new instance of the <see cref="TestableSimpleLoggingAdvice"/> class.
/// </summary>
/// <param name="useDynamicLogger">if set to <c>true</c> [use dynamic logger].</param>
public TestableSimpleLoggingAdvice(bool useDynamicLogger) : base(useDynamicLogger)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="TestableSimpleLoggingAdvice"/> class.
/// </summary>
public TestableSimpleLoggingAdvice()
{
}
/// <summary>
/// Calls the protected InvokeUnderLog method
/// </summary>
/// <param name="invocation">The invocation.</param>
/// <param name="log">The log.</param>
/// <returns>The result of the call to IMethodInvocation.Proceed()</returns>
public object CallInvokeUnderLog(IMethodInvocation invocation, ILog log)
{
return InvokeUnderLog(invocation, log);
}
/// <summary>
/// Calls the IsInterceptorEnabled method.
/// </summary>
/// <param name="invocation">The invocation.</param>
/// <param name="log">The log.</param>
/// <returns>The result of the protected method IsInterceptorEnabled</returns>
public bool CallIsInterceptorEnabled(IMethodInvocation invocation, ILog log)
{
return IsInterceptorEnabled(invocation, log);
}
}
}

View File

@@ -0,0 +1,176 @@
#region License
/*
* Copyright <20> 2002-2007 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using NUnit.Framework;
using Spring.Aop.Framework;
#endregion
namespace Spring.Aspects
{
/// <summary>
/// This class contains tests for RetryAdvice
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id: RetryAdviceTests.cs,v 1.3 2008/03/17 20:25:41 markpollack Exp $</version>
[TestFixture]
public class RetryAdviceTests
{
[SetUp]
public void Setup()
{
}
[Test]
public void TestSunnyDay()
{
InvokeOncePassOnceFail(false, false);
InvokeOncePassOnceFail(false, true);
InvokeOncePassOnceFail(true, false);
InvokeOncePassOnceFail(true, true);
}
[Test]
public void TestUnexpectedException()
{
InvokeOnceFailWithUnexceptedException(false, false);
}
private static void InvokeOncePassOnceFail(bool useExceptionName, bool isDelay)
{
ITestRemoteService rs = GetRemoteService(2, useExceptionName, isDelay);
rs.DoTransfer();
rs = GetRemoteService(3, useExceptionName, isDelay);
try
{
rs.DoTransfer();
Assert.Fail("Should have failed.");
} catch (ArithmeticException)
{
}
}
private static void InvokeOnceFailWithUnexceptedException(bool useExceptionName, bool isDelay)
{
ITestRemoteService rs = GetRemoteService(3, useExceptionName, isDelay);
try
{
rs.DoTransfer2();
Assert.Fail("Should have failed.");
}
catch (ArgumentException)
{
}
}
private static ITestRemoteService GetRemoteService(int numFailures, bool usingExceptionName, bool isDelay)
{
TestRemoteService remoteService = new TestRemoteService();
remoteService.NumFailures = numFailures;
ProxyFactory factory = new ProxyFactory(remoteService);
RetryAdvice retryAdvice = new RetryAdvice();
if (usingExceptionName)
{
if (isDelay)
{
retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x delay 1s";
}
else
{
retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x rate (1*#n + 0.5)";
}
}
else
{
if (isDelay)
{
retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x delay 1s";
}
else
{
retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x rate (1*#n + 0.5)";
}
}
retryAdvice.AfterPropertiesSet();
factory.AddAdvice(retryAdvice);
ITestRemoteService rs = factory.GetProxy() as ITestRemoteService;
Assert.IsNotNull(rs);
return rs;
}
}
public interface ITestRemoteService
{
void DoTransfer();
void DoTransfer2();
}
public class TestRemoteService : ITestRemoteService
{
private int numFailures;
private int count = 0;
private bool throwArithmeticException = false;
public int NumFailures
{
get { return numFailures; }
set { numFailures = value; }
}
public bool ThrowArithmeticException
{
get
{
if (count < NumFailures)
{
count++;
return true;
}
else
{
return throwArithmeticException;
}
}
set { throwArithmeticException = value; }
}
public void DoTransfer()
{
if (ThrowArithmeticException)
{
throw new ArithmeticException("can't do the math");
}
}
public void DoTransfer2()
{
throw new ArgumentException("bad argument");
}
}
}

View File

@@ -0,0 +1,113 @@
#region License
/*
* Copyright <20> 2002-2005 the original author or authors.
*
* 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.
*/
#endregion
#region Imports
using System;
using System.Reflection;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Spring.Context;
using Spring.Validation;
using Spring.Validation.Actions;
#endregion
namespace Spring.Aspects.Validation
{
/// <summary>
/// Unit tests for the CacheParameterAdvice class.
/// </summary>
/// <author>Aleksandar Seovic</author>
/// <version>$Id: ParameterValidationAdviceTests.cs,v 1.2 2008/04/02 23:00:46 markpollack Exp $</version>
[TestFixture]
public sealed class ParameterValidationAdviceTests
{
private IDynamicMock mockContext;
private ParameterValidationAdvice advice;
private RequiredValidator requiredValidator;
[SetUp]
public void SetUp()
{
mockContext = new DynamicMock(typeof (IApplicationContext));
advice = new ParameterValidationAdvice();
advice.ApplicationContext = (IApplicationContext) mockContext.Object;
requiredValidator = new RequiredValidator();
requiredValidator.Actions.Add(new ErrorMessageAction("error.required", "errors"));
}
[Test]
public void TestValidArgument()
{
MethodInfo method = typeof(ValidationTarget).GetMethod("Save");
Inventor inventor = new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian");
ValidationTarget target = new ValidationTarget();
object[] args = new object[] {inventor};
ExpectValidatorRetrieval("required", requiredValidator);
advice.Before(method, args, target);
method.Invoke(target, args);
Assert.AreEqual("NIKOLA TESLA", inventor.Name);
mockContext.Verify();
}
[Test]
[ExpectedException(typeof(ValidationException))]
public void TestInvalidArgument()
{
MethodInfo method = typeof(ValidationTarget).GetMethod("Save");
ExpectValidatorRetrieval("required", requiredValidator);
advice.Before(method, new object[] { null }, new ValidationTarget());
mockContext.Verify();
}
#region Helper methods
private void ExpectValidatorRetrieval(string validatorName, IValidator validator)
{
mockContext.ExpectAndReturn("GetObject", validator, validatorName);
}
#endregion
}
#region Inner Class : ValidationTarget
public interface IValidationTarget
{
void Save(Inventor inventor);
}
public sealed class ValidationTarget : IValidationTarget
{
public void Save([Validated("required")] Inventor inventor)
{
inventor.Name = inventor.Name.ToUpper();
}
}
#endregion
}

View File

@@ -0,0 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("Spring.Aop Tests")]
[assembly: AssemblyDescription("Unit tests for Spring.Aop assembly")]

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<description>
Matches all Advisors in the factory: we don't use a prefix
</description>
<object id="aapc" type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop"/>
<!--
Depending on the order value, these object should appear
before or after the LTCRegExpAdvisor. Thus we configure
them to check for the presence of a thread local variable.
The LTCRegExpAdvisor's order value is 10.
-->
<object id="orderedBeforeLTCSet" type="Spring.Aop.Framework.AutoProxy.OrderedLogicalThreadContextCheckAdvisor, Spring.Aop.Tests">
<property name="Order" value="9"/>
<property name="RequireLTCHasValue" value="false"/>
</object>
<object id="orderedAfterLTCSet" type="Spring.Aop.Framework.AutoProxy.OrderedLogicalThreadContextCheckAdvisor, Spring.Aop.Tests">
<property name="Order" value="11"/>
<property name="RequireLTCHasValue" value="true"/>
</object>
<object id="orderedAfterLTCSet2" type="Spring.Aop.Framework.AutoProxy.OrderedLogicalThreadContextCheckAdvisor, Spring.Aop.Tests">
<description>Don't set order value: should remain int.MAXVALUE, so it's non-ordered</description>
<property name="RequireLTCHasValue" value="true"/>
</object>
<object id="LTCAdvice" type="Spring.Aop.Framework.AutoProxy.LogicalThreadContextAdvice, Spring.Aop.Tests"/>
<object id="LTCRegExpAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcutAdvisor, Spring.Aop">
<property name="advice" ref="LTCAdvice"/>
<property name="pattern" value=".*set_A.*"/>
<property name="Order" value="10"/>
</object>
<object id="CountingAdvice" type="Spring.Aop.Framework.CountingAfterReturningAdvice, Spring.Aop.Tests"/>
<object id="CountingAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcutAdvisor, Spring.Aop">
<property name="advice" ref="CountingAdvice"/>
<property name="pattern" value=".*set_N.*"/>
</object>
<object id="testObject" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="SimpleTestObject"/>
<property name="Age" value="4"/>
</object>
<object id="otherTestObject" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="OtherSimpleTestObject"/>
<property name="Age" value="2"/>
</object>
<object id="testObjectFactory" type="Spring.Objects.Factory.DummyFactory">
<property name="otherTestObject" ref="otherTestObject" />
</object>
<object id="noSetterPropertiesObject" type="Spring.Aop.Framework.AutoProxy.NoSetterProperties, Spring.Aop.Tests"/>
</objects>

View File

@@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="FrozenProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>frozen</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>nopInterceptor</value>
</list>
</property>
<property name="IsFrozen" value="true"/>
</object>
<object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*Wildcards*</value>
<value>testObject</value>
<value>myTestObj*</value>
<value>*FamilyMember</value>
<value>doubleProxy</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>nopInterceptor</value>
</list>
</property>
</object>
<object id="FactoryProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>factoryObject</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>nopInterceptor</value>
</list>
</property>
</object>
<object id="DoubleFactoryProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>doubleProxy</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>nopInterceptor</value>
</list>
</property>
</object>
<object id="DecoratorFactoryProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>decoratorProx*</value>
</list>
</property>
<property name="ProxyTargetType" value="true"/>
<property name="InterceptorNames">
<list>
<value>nopInterceptor</value>
<value>countingBeforeAdvice</value>
</list>
</property>
</object>
<object id="IntroductionBeanNameProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
<property name="ObjectNames">
<list>
<value>*introductionUsingDecorator</value>
</list>
</property>
<property name="InterceptorNames">
<list>
<value>introductionNopInterceptor</value>
<value>isModifiedAdvisor</value>
</list>
</property>
</object>
<object id="factoryObject" type="Spring.Aop.Framework.AutoProxy.CreatesTestObject, Spring.Aop.Tests">
</object>
<object id="noproxy" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="noproxy"/>
</object>
<object id="testObject" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="SimpleTestObject"/>
</object>
<object id="myTestObj1Name" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="SimpleTestObject1"/>
</object>
<object id="SmithFamilyMember" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="John Smith"/>
</object>
<object id="twoWildcardsTestObject" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="Damjan Tomic"/>
</object>
<object id="doubleProxy" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="doubleProxy"/>
</object>
<object id="decoratorProxy" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="decoratorProxy"/>
</object>
<object id="frozen" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="frozen"/>
</object>
<object id="introductionUsingDecorator" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="introductionUsingDecorator"/>
</object>
<object id="second-introductionUsingDecorator" type="Spring.Objects.TestObject, Spring.Core.Tests">
<property name="Name" value="second-introductionUsingDecorator"/>
</object>
<object id="nopInterceptor" type="Spring.Aop.Interceptor.NopInterceptor, Spring.Aop.Tests"/>
<object id="countingBeforeAdvice" type="Spring.Aop.Framework.CountingBeforeAdvice, Spring.Aop.Tests"/>
<!--
<object id="factory-introductionUsingDecorator" type="Spring.Aop.Framework.AutoProxy.CreatesTestObject, Spring.Aop.Tests"/>
-->
<object id="isModifiedAdvisor" type="Spring.Aop.Framework.IsModifiedAdvisor, Spring.Aop.Tests"/>
<object id="introductionNopInterceptor" type="Spring.Aop.Interceptor.NopInterceptor, Spring.Aop.Tests"/>
</objects>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net">
<object id="testObjectTarget" type="Spring.Objects.TestObject"/>
<object id="simpleBeforeAdvice" type="Spring.Aop.SimpleBeforeAdviceImpl"/>
<object id="simpleBeforeAdviceAdvisor" type="Spring.Aop.Support.DefaultPointcutAdvisor">
<constructor-arg><ref local="simpleBeforeAdvice"/></constructor-arg>
</object>
<object id="testObject" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName"><value>testObjectTarget</value></property>
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="interceptorNames"><value>simpleBeforeAdviceAdvisor</value></property>
</object>
<object id="testAdvisorAdapter" type="Spring.Aop.SimpleBeforeAdviceAdapter"/>
<object id="adapterRegistrationManager" type="Spring.Aop.Framework.Adapter.AdvisorAdapterRegistrationManager"/>
</objects>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net">
<object id="testObjectTarget" type="Spring.Objects.TestObject"/>
<object id="simpleBeforeAdvice" type="Spring.Aop.SimpleBeforeAdviceImpl"/>
<object id="simpleBeforeAdviceAdvisor" type="Spring.Aop.Support.DefaultPointcutAdvisor">
<constructor-arg><ref local="simpleBeforeAdvice"/></constructor-arg>
</object>
<object id="testObject" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName"><value>testObjectTarget</value></property>
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="interceptorNames"><value>simpleBeforeAdviceAdvisor</value></property>
</object>
<object id="testAdvisorAdapter" type="Spring.Aop.SimpleBeforeAdviceAdapter"/>
</objects>

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Test that inner object for target means that we can use
autowire without ambiguity from target and proxy.
$Id: innerBeanTarget.xml,v 1.4 2005/03/05 23:54:02 gcaprio Exp $
-->
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="nopInterceptor" type="Spring.Aop.Interceptor.NopInterceptor">
</object>
<object id="testObject"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="target">
<object type="Spring.Objects.TestObject">
<property name="name"><value>innerObjectTarget</value></property>
</object>
</property>
<property name="interceptorNames">
<value>nopInterceptor</value>
</property>
</object>
<!--
Autowire would fail if distinct target and proxy:
we expect just to have proxy
-->
<object id="autowireCheck"
type="Spring.Aop.Framework.ProxyFactoryObjectTests$DependsOnITestObject"
autowire="constructor" />
</objects>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="testObjectTarget"
type="Spring.Aop.Framework.PrototypeTargetTests+TestObjectImpl"
singleton="false"/>
<object id="testInterceptor" type="Spring.Aop.Framework.PrototypeTargetTests+TestInterceptor"/>
<object id="testObjectPrototype" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName"><value>testObjectTarget</value></property>
<!--<property name="target"><ref local="testObjectTarget"/></property>-->
<property name="proxyInterfaces">
<value>Spring.Aop.Framework.PrototypeTargetTests+TestObject</value>
</property>
<property name="IsSingleton">
<value>false</value>
</property>
<property name="interceptorNames">
<list>
<value>testInterceptor</value>
</list>
</property>
</object>
<object id="testObjectSingleton" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName"><value>testObjectTarget</value></property>
<property name="proxyInterfaces">
<value>Spring.Aop.Framework.PrototypeTargetTests+TestObject</value>
</property>
<property name="IsSingleton">
<value>true</value>
</property>
<property name="interceptorNames">
<list>
<value>testInterceptor</value>
</list>
</property>
</object>
</objects>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Tests for independent prototype behaviour.
-->
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="test" type="Spring.Objects.Factory.SideEffectObject">
<property name="count"><value>10</value></property>
</object>
<object id="prototypeTarget" type="Spring.Objects.Factory.SideEffectObject" singleton="false">
<property name="count"><value>10</value></property>
</object>
<object id="debugInterceptor" type="Spring.Aop.Interceptor.NopInterceptor"/>
<object id="singleton" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="TargetName"><value>test</value></property>
<property name="InterceptorNames"><value>debugInterceptor</value></property>
</object>
<object id="prototype" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="TargetName"><value>prototypeTarget</value></property>
<property name="InterceptorNames"><value>debugInterceptor</value></property>
<property name="IsSingleton"><value>false</value></property>
</object>
<!-- OLD XML
<object id="target" type="Spring.Objects.TestObject">
<property name="name"><value>Adam</value></property>
</object>
-->
</objects>

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Tests for misconfiguring the proxy factory object using target name
as well as set by the targetSource property
-->
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="eveTargetSource" type="Spring.Aop.Target.SingletonTargetSource">
<constructor-arg>
<object type="Spring.Objects.TestObject">
<property name="name"><value>Eve</value></property>
</object>
</constructor-arg>
</object>
<object id="adam" type="Spring.Objects.TestObject">
<property name="name"><value>Adam</value></property>
</object>
<object id="adamTargetSource" type="Spring.Aop.Target.SingletonTargetSource">
<constructor-arg>
<ref local="adam"/>
</constructor-arg>
</object>
<object id="countingBeforeAdvice"
type="Spring.Aop.Framework.CountingBeforeAdvice"
/>
<object id="doubleTarget"
type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<!-- this is the one used and NOT the one set by targetSource -->
<property name="targetName"><value>adamTargetSource</value></property>
<property name="interceptorNames"><value>countingBeforeAdvice</value></property>
<property name="targetSource"><ref object="eveTargetSource"/></property>
</object>
<!-- but this is also possible -->
<object id="arbitraryTarget"
type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<!-- this is the one used and NOT the one set by targetSource -->
<property name="targetName"><value>adam</value></property>
<property name="targetSource"><ref local="eveTargetSource"/></property>
</object>
</objects>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Tests for independent prototype behaviour.
-->
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<!-- Simple target -->
<object id="target" type="Spring.Objects.TestObject">
<property name="name" value="Adam"/>
</object>
<!-- Simple target -->
<object id="testPrototypeTarget" type="Spring.Objects.TestObject" singleton="false">
<property name="name" value="Eve"/>
</object>
<object id="nopInterceptor" type="Spring.Aop.Interceptor.NopInterceptor"/>
<object id="countingBeforeAdvice" type="Spring.Aop.Framework.CountingBeforeAdvice"/>
<object id="targetSource" type="Spring.Aop.Target.SingletonTargetSource">
<constructor-arg ref="target"/>
</object>
<object id="directTarget" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName" value="target"/>
<property name="interceptorNames" value="countingBeforeAdvice,nopInterceptor"/>
</object>
<object id="viaPrototypeTargetSource" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName" value="testPrototypeTarget"/>
</object>
<object id="viaTargetSource" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetName" value="targetSource"/>
<property name="interceptorNames" value="nopInterceptor"/>
</object>
<object id="unsupportedInterceptor" type="Spring.Aop.Framework.UnsupportedInterceptor"/>
<!--
specifies no target or target source, just the interceptor names...
-->
<object id="noTarget" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="interceptorNames"><value>nopInterceptor,unsupportedInterceptor</value></property>
</object>
<object id="prototypeTarget" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="interceptorNames" value="nopInterceptor,target"/>
</object>
</objects>

View File

@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<!-- Simple target -->
<object id="test" type="Spring.Objects.TestObject">
<property name="name"><value>custom</value></property>
<property name="age"><value>666</value></property>
</object>
<object id="debugInterceptor" type="Spring.Aop.Interceptor.NopInterceptor"/>
<object id="test1" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="target"><ref local="test"/></property>
<property name="interceptorNames"><value>debugInterceptor</value></property>
</object>
<!--
Check that invoker is automatically added to wrap target.
Non pointcut object name should be wrapped in invoker.
-->
<object id="autoInvoker" type="Spring.Aop.Framework.ProxyFactoryObject">
<!--
Aspect interfaces don't need to be included here.
They may, for example, be added by global introductions.
-->
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="targetName"><value>test</value></property>
<property name="interceptorNames"><value>global*</value></property>
<property name="introductionNames"><value>global*</value></property>
</object>
<object id="prototype" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="isSingleton"><value>false</value></property>
<property name="targetName"><value>test</value></property>
</object>
<object id="concurrentPrototypeTest" type="Spring.Objects.TestObject" singleton="false">
<property name="name"><value>custom</value></property>
<property name="age"><value>666</value></property>
</object>
<object id="concurrentPrototypeTarget" type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop" singleton="false">
<property name="TargetObjectName"><idref object="concurrentPrototypeTest"/></property>
</object>
<object id="concurrentPrototype" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="isSingleton"><value>false</value></property>
<property name="isFrozen"><value>false</value></property>
<property name="targetName"><value>concurrentPrototypeTarget</value></property>
<property name="interceptorNames"><value>global*</value></property>
</object>
<object id="test2" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="isSingleton"><value>false</value></property>
<property name="targetName"><value>test</value></property>
</object>
<object id="pointcuts" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="targetName"><value>test</value></property>
<property name="interceptorNames"><value>pointcutForVoid</value></property>
</object>
<object id="pointcutForVoid" type="Spring.Aop.Framework.ProxyFactoryObjectTests+PointcutForVoid"/>
<!--
Invalid test for global pointcuts.
Must have target because there are no interceptors.
-->
<!--
<object id="noInterceptorNamesWithoutTarget"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
</object>
<object id="noInterceptorNamesWithTarget"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="target"><ref local="test"/></property>
</object>
-->
<!-- Same effect as noInterceptor names: also invalid -->
<!--
<object id="emptyInterceptorNames" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="interceptorNames"><value/></property>
</object>
-->
<!--
Invalid test for global pointcuts.
Must have target after *.
-->
<!--
<object id="globalsWithoutTarget"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="proxyInterfaces"><value>Spring.Objects.ITestObject</value></property>
<property name="interceptorNames"><value>global*</value></property>
</object>
-->
<object id="validGlobals" singleton="true" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Context.IApplicationEventListener</value></property>
<property name="targetName"><value>target2</value></property>
<property name="interceptorNames"><value>debugInterceptor,global*</value></property>
<property name="introductionNames"><value>global*</value></property>
</object>
<!--
Global debug interceptor
-->
<object id="global_debug" type="Spring.Aop.Advice.DebugAdvice"/>
<!--
Will add introduction to all Objects exposing globals
-->
<object id="global_introduction" type="Spring.Aop.Framework.ProxyFactoryObjectTests+GlobalIntroduction" singleton="false" />
<object id="target2" type="Spring.Context.Events.ConsoleListener,Spring.Core"/>
</objects>

View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Tests for independent prototype behaviour.
-->
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="nopInterceptor" type="Spring.Aop.Interceptor.NopInterceptor">
</object>
<object id="serializableNopInterceptor" type="Spring.Aop.Interceptor.SerializableNopInterceptor">
</object>
<object id="serializableSingleton"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="interceptorNames"><value>serializableNopInterceptor</value></property>
<property name="proxyInterfaces"><value>Spring.Objects.Person</value></property>
<property name="target">
<object type="Spring.Objects.SerializablePerson">
<property name="name"><value>serializableSingleton</value></property>
</object>
</property>
</object>
<object id="prototypeTarget" type="Spring.Objects.SerializablePerson">
<property name="name"><value>serializablePrototype</value></property>
</object>
<object id="serializablePrototype"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="interceptorNames"><value>serializableNopInterceptor,prototypeTarget</value></property>
<property name="proxyInterfaces"><value>Spring.Objects.Person</value></property>
<property name="singleton"><value>false</value></property>
</object>
<object id="interceptorNotSerializableSingleton"
type="Spring.Aop.Framework.ProxyFactoryObject"
>
<property name="interceptorNames"><value>nopInterceptor</value></property>
<property name="target">
<object type="Spring.Objects.SerializablePerson" />
</property>
</object>
</objects>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Tests for throws advice.
$Id: throwsAdvice.xml,v 1.6 2007/03/09 17:44:40 aseovic Exp $
-->
<objects xmlns="http://www.springframework.net">
<!-- Simple target -->
<object id="target" type="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptorTests+Echo"/>
<object id="nopInterceptor" type="Spring.Aop.Interceptor.NopInterceptor"/>
<object id="countingBeforeAdvice" type="Spring.Aop.Framework.CountingBeforeAdvice"/>
<object id="throwsAdvice"
type="Spring.Aop.Framework.Adapter.ThrowsAdviceInterceptorTests+MyThrowsHandler"/>
<object id="throwsAdvised" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="target" ref="target"/>
<property name="interceptorNames"
value="countingBeforeAdvice,nopInterceptor,throwsAdvice"/>
</object>
</objects>

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<!-- Simple target -->
<object id="Test" type="Spring.Objects.SerializablePerson">
<property name="name"><value>custom</value></property>
<property name="age"><value>666</value></property>
</object>
<object id="NopInterceptor" type="Spring.Aop.Interceptor.SerializableNopInterceptor">
</object>
<object id="SettersAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcutAdvisor">
<property name="advice"><ref local="NopInterceptor"/></property>
<property name="pattern"><value>.*Set.*</value></property>
</object>
<object id="SettersAdvised" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.IPerson</value></property>
<property name="target"><ref local="Test"/></property>
<property name="interceptorNames"><value>SettersAdvisor</value></property>
</object>
<object id="SerializableSettersAdvised" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.IPerson</value></property>
<property name="target">
<object type="Spring.Objects.SerializablePerson">
<property name="name"><value>SerializableSettersAdvised</value></property>
</object>
</property>
<property name="interceptorNames"><value>SettersAdvisor</value></property>
</object>
<!-- Illustrates use of multiple patterns -->
<object id="SettersAndReturnsThisAdvisor" type="Spring.Aop.Support.RegularExpressionMethodPointcutAdvisor">
<property name="advice"><ref local="NopInterceptor"/></property>
<property name="patterns">
<list>
<value>.*Set.*</value>
<value>.*ReturnsThis</value>
</list>
</property>
</object>
<object id="SettersAndReturnsThisAdvised" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="proxyInterfaces"><value>Spring.Objects.IPerson</value></property>
<property name="proxyTargetType"><value>true</value></property>
<property name="target"><ref local="Test"/></property>
<property name="interceptorNames"><value>SettersAndReturnsThisAdvisor</value></property>
</object>
</objects>

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="prototypeTest" type="Spring.Objects.Factory.SideEffectObject" singleton="false">
<property name="count">
<value>10</value>
</property>
</object>
<object id="poolTargetSource" type="Spring.Aop.Target.CommonsPoolTargetSource">
<property name="targetobjectName">
<value>prototypeTest</value>
</property>
<property name="maxSize">
<value>25</value>
</property>
</object>
<object id="poolConfigAdvisor" type="Spring.Objects.Factory.Config.MethodInvokingFactoryObject">
<property name="targetObject">
<ref local="poolTargetSource" />
</property>
<property name="targetMethod">
<value>GetPoolingConfigMixin</value>
</property>
</object>
<object id="nop" type="Spring.Aop.Interceptor.NopInterceptor" />
<!--
This will create a object for each thread ("apartment")
-->
<object id="pooled" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="poolTargetSource" />
</property>
<property name="interceptorNames">
<value>nop</value>
</property>
</object>
<object id="pooledNoInterceptors" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="poolTargetSource" />
</property>
</object>
<object id="pooledWithMixin" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="poolTargetSource" />
</property>
<property name="interceptorNames">
<value>poolConfigAdvisor</value>
</property>
<!-- Necessary as have a mixin and want to avoid losing the class,
because there's no target interface -->
<property name="proxyTargetType">
<value>true</value>
</property>
</object>
</objects>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<objects xmlns="http://www.springframework.net">
<!-- Simple target -->
<object id="target1" type="Spring.Objects.Factory.SideEffectObject">
<property name="count" value="10"/>
</object>
<object id="target2" type="Spring.Objects.Factory.SideEffectObject" singleton="true">
<property name="count" value="20"/>
</object>
<!--
Hot swappable target source...
-->
<object id="swapper" type="Spring.Aop.Target.HotSwappableTargetSource">
<constructor-arg ref="target1"/>
</object>
<object id="swappable" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource" ref="swapper"/>
</object>
</objects>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Tests for independent prototype behaviour.
-->
<objects xmlns="http://www.springframework.net">
<object id="test" type="Spring.Objects.Factory.SideEffectObject">
<property name="count"><value>10</value></property>
</object>
<object id="prototypeTest" type="Spring.Objects.Factory.SideEffectObject" singleton="false">
<property name="count"><value>10</value></property>
</object>
<object id="prototypeTargetSource" type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop">
<property name="TargetObjectName"><value>prototypeTest</value></property>
</object>
<object id="debugInterceptor" type="Spring.Aop.Interceptor.NopInterceptor, Spring.Aop.Tests"/>
<object id="singleton" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="TargetName"><value>test</value></property>
<property name="InterceptorNames"><value>debugInterceptor</value></property>
</object>
<object id="prototype" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="TargetSource"><ref object="prototypeTargetSource"/></property>
<property name="InterceptorNames"><value>debugInterceptor</value></property>
</object>
<object id="prototypeByName" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="TargetName"><value>prototypeTest</value></property>
<property name="InterceptorNames"><value>debugInterceptor</value></property>
</object>
</objects>

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="prototypeTest" type="Spring.Objects.Factory.SideEffectObject" singleton="false">
<property name="count">
<value>10</value>
</property>
</object>
<object id="poolTargetSource" type="Spring.Aop.Target.SimplePoolTargetSource">
<property name="targetobjectName">
<value>prototypeTest</value>
</property>
<property name="maxSize">
<value>25</value>
</property>
</object>
<object id="poolConfigAdvisor" type="Spring.Objects.Factory.Config.MethodInvokingFactoryObject">
<property name="targetObject">
<ref local="poolTargetSource" />
</property>
<property name="targetMethod">
<value>GetPoolingConfigMixin</value>
</property>
</object>
<object id="nop" type="Spring.Aop.Interceptor.NopInterceptor" />
<!--
This will create a object for each thread ("apartment")
-->
<object id="pooled" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="poolTargetSource" />
</property>
<property name="interceptorNames">
<value>nop</value>
</property>
</object>
<object id="pooledNoInterceptors" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="poolTargetSource" />
</property>
</object>
<object id="pooledWithMixin" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="poolTargetSource" />
</property>
<property name="introductionNames">
<value>poolConfigAdvisor</value>
</property>
<!-- Necessary as have a mixin and want to avoid losing the class,
because there's no target interface -->
<property name="proxyTargetType">
<value>true</value>
</property>
</object>
</objects>

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="prototypeTest" type="Spring.Objects.Factory.SideEffectObject" singleton="false">
<property name="count">
<value>10</value>
</property>
</object>
<object id="threadLocalTs" type="Spring.Aop.Target.ThreadLocalTargetSource">
<property name="targetobjectName">
<value>prototypeTest</value>
</property>
</object>
<object id="debugInterceptor" type="Spring.Aop.Interceptor.NopInterceptor" />
<!--
We want to invoke the getStatsMixin method on our ThreadLocal invoker
-->
<object id="statsAdvisor" type="Spring.Objects.Factory.Config.MethodInvokingFactoryObject">
<property name="targetObject">
<ref local="threadLocalTs" />
</property>
<property name="targetMethod">
<value>GetStatsMixin</value>
</property>
</object>
<!--
This will create a object for each thread ("apartment")
-->
<object id="apartment" type="Spring.Aop.Framework.ProxyFactoryObject">
<!-- in java:
<property name="interceptorNames"><value>debugInterceptor,statsAdvisor</value></property>
-->
<property name="introductionNames">
<value>statsAdvisor</value>
</property>
<property name="interceptorNames">
<value>debugInterceptor</value>
</property>
<property name="targetSource">
<ref local="threadLocalTs" />
</property>
<!-- Necessary as have a mixin and want to avoid losing the class,
because there's no target interface
-->
<property name="proxyTargetType">
<value>true</value>
</property>
</object>
<!-- ================ Definitions for second ThreadLocalTargetSource ====== -->
<object id="wife" type="Spring.Objects.TestObject">
<property name="name">
<value>Kerry</value>
</property>
</object>
<object id="test" singleton="false" type="Spring.Objects.TestObject">
<property name="name">
<value>Rod</value>
</property>
<property name="spouse">
<ref local="wife" />
</property>
</object>
<object id="threadLocalTs2" type="Spring.Aop.Target.ThreadLocalTargetSource">
<property name="targetobjectName">
<value>test</value>
</property>
</object>
<object id="threadLocal2" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="targetSource">
<ref local="threadLocalTs2" />
</property>
</object>
</objects>

View File

@@ -0,0 +1,516 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.0.9955"
SchemaVersion = "1.0"
ProjectGuid = "{F856BCAE-421E-469A-B75F-E41E5BA7F160}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Spring.Aop.Tests"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
RootNamespace = "Spring"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE;NET_1_0"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
Optimize = "false"
OutputPath = "..\..\..\build\VS.Net.2002\Spring.Aop.Tests\Debug-1.0\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "1"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
Optimize = "true"
OutputPath = "..\..\..\build\VS.Net.2002\Spring.Aop.Tests\Release-1.0\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
/>
<Reference
Name = "System.Drawing"
AssemblyName = "System.Drawing"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Drawing.dll"
/>
<Reference
Name = "Spring.Core.Tests.2002"
Project = "{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Spring.Aop.2002"
Project = "{828F16E3-20A4-4EC4-A8F4-CD95B8ED44C9}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Spring.Core.2002"
Project = "{710961A3-0DF4-49E4-A26E-F5B9C044AC84}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "System.Web"
AssemblyName = "System.Web"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Web.dll"
/>
<Reference
Name = "Common.Logging"
AssemblyName = "Common.Logging"
HintPath = "..\..\..\lib\Net\1.0\Common.Logging.dll"
/>
<Reference
Name = "antlr.runtime"
AssemblyName = "antlr.runtime"
HintPath = "..\..\..\lib\Net\1.0\antlr.runtime.dll"
/>
<Reference
Name = "DotNetMock"
AssemblyName = "DotNetMock"
HintPath = "..\..\..\lib\Net\1.0\DotNetMock.dll"
/>
<Reference
Name = "DotNetMock.Framework"
AssemblyName = "DotNetMock.Framework"
HintPath = "..\..\..\lib\Net\1.0\DotNetMock.Framework.dll"
/>
<Reference
Name = "nunit.framework"
AssemblyName = "nunit.framework"
HintPath = "..\..\..\lib\Net\1.0\nunit.framework.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "AopExceptionTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\ISimpleBeforeAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\SimpleBeforeAdviceAdapter.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\SimpleBeforeAdviceImpl.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\SimpleBeforeAdviceInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\TrueMethodMatcherTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\TruePointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\TrueTypeFilterTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Advice\DebugAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Config\AopNamespaceParserTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Config\AopNamespaceParserTests.xml"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "Aop\Framework\AbstractMethodInvocationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AopContextTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingAfterReturningAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingBeforeAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingMultiAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingThrowsAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicMethodInvocationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\HashtableCachingAdvisorChainFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ITimeStamped.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\MethodCounter.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\PrototypeTargetTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ProxyConfigTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ProxyFactoryObjectTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ProxyFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ReflectiveMethodInvocationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\TimestampIntroductionInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\UnsupportedInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\AdvisorAdapterRegistrationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\AfterReturningAdviceInterceptorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\ThrowsAdviceInterceptorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\UnknownAdviceTypeExceptionTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\AdvisorAutoProxyCreatorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\LogicalThreadContextAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\NoSetterProperties.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\ObjectNameAutoProxyCreatorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\OrderedLogicalThreadContextCheckAdvisor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\AbstractAopProxyTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\CompositionAopProxyTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\DecoratorAopProxyTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\MockTargetSource.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Interceptor\NopInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Interceptor\SerializableNopInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\AbstractRegularExpressionMethodPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\AttributeMatchMethodPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\ControlFlowPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\DelegatingIntroductionInterceptorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\RegularExpressionMethodPointcutAdvisorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\RootTypeFilterTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\SdkRegularExpressionMethodPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\TypeFiltersTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\EmptyTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\HotSwappableTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\PrototypeTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\SimplePoolTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\SingletonTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\ThreadLocalTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\CacheAspectIntegrationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\CacheParameterAdviceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\CacheResultAdviceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\InvalidateCacheAdviceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Exception\ExceptionHandlerAspectIntegrationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Data\Spring\Aop\Framework\innerBeanTarget.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\prototypeTarget.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\prototypeTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\proxyFactoryDoubleTargetSourceTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\proxyFactoryTargetSourceTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\proxyFactoryTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\serializationTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\throwsAdvice.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\adapter\withBPPContext.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\adapter\withoutBPPContext.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\AutoProxy\advisorAutoProxyCreator.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\AutoProxy\objectNameAutoProxyCreatorTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Support\RegularExpressionSetterTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\commonsPoolTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\hotSwapTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\prototypeTargetSourceTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\simplePoolTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\threadLocalTests.xml"
BuildAction = "Content"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

View File

@@ -0,0 +1,554 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{2111596A-0327-4C9D-8919-294FBD988A23}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Spring.Aop.Tests"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = ""
PostBuildEvent = 'echo "Copying .xml files for tests"&#xd;&#xa;xcopy "$(ProjectDir)Data" "..\..\..\..\build\VS.Net.2003\Spring.Aop.Tests\$(ConfigurationName)\" /y /s /q&#xd;&#xa;'
RootNamespace = "Spring"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""
>
<Config
Name = "Debug-1.1"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE;NET_1_1;DEBUG_DYNAMIC"
DocumentationFile = "Spring.Aop.Tests.xml"
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = "0618"
Optimize = "false"
OutputPath = "..\..\..\build\VS.Net.2003\Spring.Aop.Tests\Debug-1.1\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "3"
/>
<Config
Name = "Release-1.1"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE;NET_1_1"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "..\..\..\build\VS.Net.2003\Spring.Aop.Tests\Release-1.1\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference
Name = "System.Web"
AssemblyName = "System.Web"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
/>
<Reference
Name = "DotNetMock"
AssemblyName = "DotNetMock"
HintPath = "..\..\..\lib\Net\1.1\DotNetMock.dll"
/>
<Reference
Name = "nunit.framework"
AssemblyName = "nunit.framework"
HintPath = "..\..\..\lib\Net\1.1\nunit.framework.dll"
Private = "True"
/>
<Reference
Name = "Spring.Aop.2003"
Project = "{3A3A4E65-45A6-4B20-B460-0BEDC302C02C}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Spring.Core.2003"
Project = "{710961A3-0DF4-49E4-A26E-F5B9C044AC84}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Spring.Core.Tests.2003"
Project = "{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Common.Logging"
AssemblyName = "Common.Logging"
HintPath = "..\..\..\lib\Net\1.1\Common.Logging.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "AopExceptionTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Spring.Aop.Tests.build"
BuildAction = "None"
/>
<File
RelPath = "Aop\ISimpleBeforeAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\SimpleBeforeAdviceAdapter.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\SimpleBeforeAdviceImpl.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\SimpleBeforeAdviceInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\TrueMethodMatcherTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\TruePointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\TrueTypeFilterTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Advice\DebugAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Config\AopNamespaceParserTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Config\AopNamespaceParserTests.xml"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "Aop\Framework\AbstractMethodInvocationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AopContextTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingAfterReturningAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingBeforeAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingMultiAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\CountingThrowsAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicMethodInvocationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\HashtableCachingAdvisorChainFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\IIsModified.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\IsModifiedMixin.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ITimeStamped.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\MethodCounter.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\PrototypeTargetTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ProxyConfigTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ProxyFactoryObjectTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ProxyFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\ReflectiveMethodInvocationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\TimestampIntroductionInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\UnsupportedInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\AdvisorAdapterRegistrationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\AfterReturningAdviceInterceptorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\ThrowsAdviceInterceptorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\Adapter\UnknownAdviceTypeExceptionTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\AdvisorAutoProxyCreatorCircularReferencesTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\advisorAutoProxyCreatorCircularReferencesTests.xml"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "Aop\Framework\AutoProxy\AdvisorAutoProxyCreatorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\CreatesTestObject.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\LogicalThreadContextAdvice.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\NoSetterProperties.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\ObjectNameAutoProxyCreatorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\AutoProxy\OrderedLogicalThreadContextCheckAdvisor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\AbstractAopProxyTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\AopUtilsTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\CachedAopProxyFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\CompositionAopProxyTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\DecoratorAopProxyTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\DefaultAopProxyFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Framework\DynamicProxy\MockTargetSource.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Interceptor\NopInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Interceptor\SerializableNopInterceptor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\AbstractRegularExpressionMethodPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\AttributeMatchMethodPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\ControlFlowPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\DelegatingIntroductionInterceptorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\RegularExpressionMethodPointcutAdvisorTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\RootTypeFilterTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\SdkRegularExpressionMethodPointcutTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Support\TypeFiltersTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\EmptyTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\HotSwappableTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\PrototypeTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\SimplePoolTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\SingletonTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aop\Target\ThreadLocalTargetSourceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\CacheAspectIntegrationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\CacheParameterAdviceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\CacheResultAdviceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Cache\InvalidateCacheAdviceTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Aspects\Exception\ExceptionHandlerAspectIntegrationTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Data\Spring\Aop\Framework\innerBeanTarget.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\prototypeTarget.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\prototypeTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\proxyFactoryDoubleTargetSourceTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\proxyFactoryTargetSourceTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\proxyFactoryTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\serializationTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\throwsAdvice.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\adapter\withBPPContext.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\adapter\withoutBPPContext.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\AutoProxy\advisorAutoProxyCreator.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Framework\AutoProxy\objectNameAutoProxyCreatorTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Support\RegularExpressionSetterTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\commonsPoolTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\hotSwapTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\prototypeTargetSourceTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\simplePoolTests.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\Aop\Target\threadLocalTests.xml"
BuildAction = "Content"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

View File

@@ -0,0 +1,306 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2111596A-0327-4C9D-8919-294FBD988A23}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>Spring.Aop.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<RootNamespace>Spring</RootNamespace>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<StartupObject>
</StartupObject>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\..\..\build\VS.Net.2005\Spring.Aop.Tests\Debug\</OutputPath>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG;NET_2_0;DEBUG_DYNAMIC</DefineConstants>
<DocumentationFile>Spring.Aop.Tests.xml</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<NoStdLib>false</NoStdLib>
<NoWarn>0618</NoWarn>
<Optimize>false</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningLevel>3</WarningLevel>
<DebugType>full</DebugType>
<ErrorReport>prompt</ErrorReport>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>..\..\..\build\VS.Net.2005\Spring.Aop.Tests\Release\</OutputPath>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;NET_2_0</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>false</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<NoStdLib>false</NoStdLib>
<NoWarn>618</NoWarn>
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<DebugType>none</DebugType>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\antlr.runtime.dll</HintPath>
</Reference>
<Reference Include="Common.Logging, Version=2.1.0.0, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="DotNetMock, Version=0.7.4.0, Culture=neutral, PublicKeyToken=805ea88df19095f6">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\DotNetMock.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=2.9.6.40380, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="System">
<Name>System</Name>
</Reference>
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
<Reference Include="System.Web">
<Name>System.Web</Name>
</Reference>
<Reference Include="System.Xml">
<Name>System.XML</Name>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AopExceptionTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Advice\DebugAdvice.cs" />
<Compile Include="Aop\Config\AopNamespaceParserTests.cs" />
<Compile Include="Aop\Framework\Adapter\AdvisorAdapterRegistrationTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\Adapter\AfterReturningAdviceInterceptorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\Adapter\ThrowsAdviceInterceptorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\Adapter\UnknownAdviceTypeExceptionTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\AopContextTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\AutoProxy\AdvisorAutoProxyCreatorCircularReferencesTests.cs" />
<Compile Include="Aop\Framework\AutoProxy\AdvisorAutoProxyCreatorTests.cs" />
<Compile Include="Aop\Framework\AutoProxy\LogicalThreadContextAdvice.cs" />
<Compile Include="Aop\Framework\AutoProxy\NoSetterProperties.cs" />
<Compile Include="Aop\Framework\AutoProxy\ObjectNameAutoProxyCreatorTests.cs" />
<Compile Include="Aop\Framework\AutoProxy\OrderedLogicalThreadContextCheckAdvisor.cs" />
<Compile Include="Aop\Framework\AbstractMethodInvocationTests.cs" />
<Compile Include="Aop\Framework\AutoProxy\CreatesTestObject.cs" />
<Compile Include="Aop\Framework\DynamicMethodInvocationTests.cs" />
<Compile Include="Aop\Framework\CountingAfterReturningAdvice.cs" />
<Compile Include="Aop\Framework\CountingBeforeAdvice.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\CountingMultiAdvice.cs" />
<Compile Include="Aop\Framework\CountingThrowsAdvice.cs" />
<Compile Include="Aop\Framework\DynamicProxy\AbstractAopProxyTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\AopUtilsTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\CachedAopProxyFactoryTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\CompositionAopProxyTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\InheritanceAopProxyTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\DecoratorAopProxyTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\DefaultAopProxyFactoryTests.cs" />
<Compile Include="Aop\Framework\DynamicProxy\MockTargetSource.cs" />
<Compile Include="Aop\Framework\HashtableCachingAdvisorChainFactoryTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\IIsModified.cs" />
<Compile Include="Aop\Framework\IsModifiedMixin.cs" />
<Compile Include="Aop\Framework\ITimeStamped.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\MethodCounter.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\PrototypeTargetTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\ProxyConfigTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\ProxyFactoryObjectTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\ProxyFactoryTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\ReflectiveMethodInvocationTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\TimestampIntroductionInterceptor.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Framework\UnsupportedInterceptor.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Interceptor\NopInterceptor.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Interceptor\SerializableNopInterceptor.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\ISimpleBeforeAdvice.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\SimpleBeforeAdviceAdapter.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\SimpleBeforeAdviceImpl.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\SimpleBeforeAdviceInterceptor.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\AbstractRegularExpressionMethodPointcutTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\AttributeMatchMethodPointcutTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\ControlFlowPointcutTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\DelegatingIntroductionInterceptorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\RegularExpressionMethodPointcutAdvisorTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\RootTypeFilterTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\SdkRegularExpressionMethodPointcutTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Support\TypeFiltersTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Target\EmptyTargetSourceTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Target\HotSwappableTargetSourceTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Target\PrototypeTargetSourceTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Target\SimplePoolTargetSourceTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Target\SingletonTargetSourceTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\Target\ThreadLocalTargetSourceTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\TrueMethodMatcherTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\TruePointcutTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aop\TrueTypeFilterTests.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Aspects\Cache\CacheResultAdviceTests.cs" />
<Compile Include="Aspects\Cache\CacheParameterAdviceTests.cs" />
<Compile Include="Aspects\Cache\CacheAspectIntegrationTests.cs" />
<Compile Include="Aspects\Cache\InvalidateCacheAdviceTests.cs" />
<Compile Include="Aspects\Exception\ExceptionHandlerAspectIntegrationTests.cs" />
<Compile Include="Aspects\Logging\SimpleLoggingAdviceTests.cs" />
<Compile Include="Aspects\Logging\TestableSimpleLoggingAdvice.cs" />
<Compile Include="Aspects\RetryAdviceTests.cs" />
<Compile Include="Aspects\Validation\ParameterValidationAdviceTests.cs" />
<Compile Include="AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<None Include="Spring.Aop.Tests.build" />
<None Include="Spring.Aop.Tests.dll.config" />
<EmbeddedResource Include="Aop\Config\AopNamespaceParserTests.xml" />
<EmbeddedResource Include="Data\Spring\Aop\Framework\adapter\withBPPContext.xml" />
<EmbeddedResource Include="Data\Spring\Aop\Framework\adapter\withoutBPPContext.xml" />
<EmbeddedResource Include="Aop\Framework\AutoProxy\advisorAutoProxyCreatorCircularReferencesTests.xml" />
<Content Include="Data\Spring\Aop\Framework\AutoProxy\advisorAutoProxyCreator.xml" />
<Content Include="Data\Spring\Aop\Framework\AutoProxy\objectNameAutoProxyCreatorTests.xml" />
<Content Include="Data\Spring\Aop\Framework\innerBeanTarget.xml" />
<Content Include="Data\Spring\Aop\Framework\prototypeTarget.xml" />
<Content Include="Data\Spring\Aop\Framework\prototypeTests.xml" />
<Content Include="Data\Spring\Aop\Framework\proxyFactoryDoubleTargetSourceTests.xml" />
<Content Include="Data\Spring\Aop\Framework\proxyFactoryTargetSourceTests.xml" />
<Content Include="Data\Spring\Aop\Framework\proxyFactoryTests.xml" />
<Content Include="Data\Spring\Aop\Framework\serializationTests.xml" />
<Content Include="Data\Spring\Aop\Framework\throwsAdvice.xml" />
<Content Include="Data\Spring\Aop\Support\RegularExpressionSetterTests.xml" />
<Content Include="Data\Spring\Aop\Target\commonsPoolTests.xml" />
<Content Include="Data\Spring\Aop\Target\hotSwapTests.xml" />
<Content Include="Data\Spring\Aop\Target\prototypeTargetSourceTests.xml" />
<Content Include="Data\Spring\Aop\Target\simplePoolTests.xml" />
<Content Include="Data\Spring\Aop\Target\threadLocalTests.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spring\Spring.Aop\Spring.Aop.2005.csproj">
<Project>{3A3A4E65-45A6-4B20-B460-0BEDC302C02C}</Project>
<Name>Spring.Aop.2005</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Spring\Spring.Core\Spring.Core.2005.csproj">
<Project>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</Project>
<Name>Spring.Core.2005</Name>
</ProjectReference>
<ProjectReference Include="..\Spring.Core.Tests\Spring.Core.Tests.2005.csproj">
<Project>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</Project>
<Name>Spring.Core.Tests.2005</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>echo "Copying .xml files for tests"
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Aop.Tests\$(ConfigurationName)\ /y /s /q /d
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Aop.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" ?>
<project name="Spring.Aop.Tests" default="test" xmlns="http://nant.sf.net/schemas/nant.xsd">
<!--
Required properties:
* current.bin.dir - (path) root level to build to
* current.build.debug - (true|false) debug build?
* current.build.defines.csc - framework-specific build defines for C# compiler
-->
<target name="build">
<!-- build Spring.Aop -->
<csc target="library" define="${current.build.defines.csc}"
warnaserror="true"
debug="${current.build.debug}"
output="${current.bin.dir}/${project::get-name()}.dll"
doc="${current.bin.dir}/${project::get-name()}.xml">
<nowarn>
<warning number="${nowarn.numbers.test}" />
</nowarn>
<sources failonempty="true">
<include name="**/*.cs" />
<include name="../CommonAssemblyInfo.cs" />
</sources>
<resources basedir="Resources">
<include name="**/*" />
</resources>
<resources basedir="Data" prefix="" dynamicprefix="true" failonempty="true">
<include name="**/*" />
</resources>
<resources prefix="Spring" dynamicprefix="true" failonempty="true">
<include name="**/*.xml" />
<exclude name="Data/**/*" />
<exclude name="obj/**/*" />
</resources>
<references basedir="${current.bin.dir}">
<include name="*.dll" />
<exclude name="${project::get-name()}.dll" />
<exclude name="CloverRuntime.dll" />
</references>
</csc>
<copy todir="${current.bin.dir}">
<fileset basedir="${project::get-base-directory()}/Data">
<include name="**/*.xml" />
</fileset>
</copy>
</target>
<target name="test" depends="build">
<nunit2outproc>
<formatter type="Plain" />
<formatter type="Xml" usefile="true" extension=".xml"
outputdir="${current.bin.dir}/results" />
<test assemblyname="${current.bin.dir}/${project::get-name()}.dll" />
</nunit2outproc>
</target>
<target name="test-mono-1.0" >
<nunit2outproc>
<formatter type="Plain" />
<formatter type="Xml" usefile="true" extension=".xml"
outputdir="${current.bin.dir}/results" />
<test assemblyname="${bin.dir}/net/1.1/${current.build.config}/${project::get-name()}.dll"
appconfig="${bin.dir}/net/1.1/${current.build.config}/${project::get-name()}.dll.config" />
</nunit2outproc>
</target>
</project>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2002-2005 the original author or authors.
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.
-->
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging">
</factoryAdapter>
</logging>
</common>
</configuration>

Some files were not shown because too many files have changed in this diff Show More