Removing a couple more dependencies to DotNetMock
This commit is contained in:
@@ -26,7 +26,6 @@ using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
using AopAlliance.Intercept;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
@@ -42,7 +41,15 @@ namespace Spring.Aop.Framework
|
||||
[TestFixture]
|
||||
public abstract class AbstractMethodInvocationTests
|
||||
{
|
||||
protected abstract AbstractMethodInvocation CreateMethodInvocation(
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public virtual void SetUp()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
protected abstract AbstractMethodInvocation CreateMethodInvocation(
|
||||
object proxy, object target, MethodInfo method, MethodInfo onProxyMethod,
|
||||
object[] arguments, Type targetType, IList interceptors);
|
||||
|
||||
@@ -181,14 +188,17 @@ namespace Spring.Aop.Framework
|
||||
*/
|
||||
|
||||
Target target = new Target();
|
||||
IDynamicMock mock = new DynamicMock(typeof (IMethodInterceptor));
|
||||
IMethodInterceptor mock = (IMethodInterceptor) mocks.CreateMock(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), null);
|
||||
null, target, target.GetTargetMethodNoArgs(), null, null, target.GetType(), new object[] { mock });
|
||||
|
||||
Expect.Call(mock.Invoke(null)).IgnoreArguments().Return(target.BullseyeMethod().ToLower(CultureInfo.InvariantCulture));
|
||||
mocks.ReplayAll();
|
||||
|
||||
string score = (string) join.Proceed();
|
||||
Assert.AreEqual(Target.DefaultScore.ToLower(CultureInfo.InvariantCulture) + Target.Suffix, score);
|
||||
mock.Verify();
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
}
|
||||
|
||||
@@ -216,10 +226,13 @@ namespace Spring.Aop.Framework
|
||||
public void UnwrapsTargetInvocationException_WithInterceptor()
|
||||
{
|
||||
BadCommand target = new BadCommand();
|
||||
IDynamicMock mock = new DynamicMock(typeof (IMethodInterceptor));
|
||||
IMethodInterceptor mock = (IMethodInterceptor) mocks.CreateMock(typeof(IMethodInterceptor));
|
||||
AbstractMethodInvocation join = CreateMethodInvocation(
|
||||
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock.Object });
|
||||
mock.ExpectAndReturn("Invoke", null, null);
|
||||
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock });
|
||||
|
||||
Expect.Call(mock.Invoke(null)).IgnoreArguments().Return(null);
|
||||
mocks.ReplayAll();
|
||||
|
||||
try
|
||||
{
|
||||
join.Proceed();
|
||||
@@ -232,17 +245,19 @@ namespace Spring.Aop.Framework
|
||||
{
|
||||
Assert.Fail("Must have unwrapped this.");
|
||||
}
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnwrapsTargetInvocationException_WithInterceptorThatThrowsAnException()
|
||||
{
|
||||
BadCommand target = new BadCommand();
|
||||
IDynamicMock mock = new DynamicMock(typeof (IMethodInterceptor));
|
||||
IMethodInterceptor mock = (IMethodInterceptor) mocks.CreateMock(typeof(IMethodInterceptor));
|
||||
AbstractMethodInvocation join = CreateMethodInvocation(
|
||||
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock.Object });
|
||||
mock.ExpectAndThrow("Invoke", new NotImplementedException(), null);
|
||||
null, target, target.GetTargetMethod(), null, null, target.GetType(), new object[] { mock });
|
||||
Expect.Call(mock.Invoke(null)).IgnoreArguments().Throw(new NotImplementedException());
|
||||
mocks.ReplayAll();
|
||||
|
||||
try
|
||||
{
|
||||
join.Proceed();
|
||||
@@ -255,7 +270,7 @@ namespace Spring.Aop.Framework
|
||||
{
|
||||
Assert.Fail("Must have unwrapped this.");
|
||||
}
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ using System.Reflection;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Web;
|
||||
using AopAlliance.Intercept;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Util;
|
||||
|
||||
@@ -46,7 +46,6 @@ using Spring.Proxy;
|
||||
using Spring.Threading;
|
||||
using Spring.Util;
|
||||
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
|
||||
#endregion
|
||||
@@ -62,6 +61,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
public abstract class AbstractAopProxyTests
|
||||
{
|
||||
protected MockTargetSource mockTargetSource = new MockTargetSource();
|
||||
private MockRepository mocks;
|
||||
|
||||
/*
|
||||
* Make a clean target source available if code wants to use it.
|
||||
@@ -78,6 +78,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[SetUp]
|
||||
protected void SetUp()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
mockTargetSource.Reset();
|
||||
}
|
||||
|
||||
@@ -423,18 +424,19 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
public void InterceptorHandledCallWithNoTarget()
|
||||
{
|
||||
int age = 26;
|
||||
DynamicMock mock = new DynamicMock(typeof(IMethodInterceptor));
|
||||
mock.SetValue("Invoke", age);
|
||||
IMethodInterceptor mi = (IMethodInterceptor)mock.Object;
|
||||
IMethodInterceptor mock = (IMethodInterceptor) mocks.CreateMock(typeof(IMethodInterceptor));
|
||||
Expect.Call(mock.Invoke(null)).IgnoreArguments().Return(age);
|
||||
mocks.ReplayAll();
|
||||
|
||||
AdvisedSupport advised = new AdvisedSupport();
|
||||
advised.AddAdvice(mi);
|
||||
advised.AddAdvice(mock);
|
||||
advised.Interfaces = new Type[] { typeof(ITestObject) };
|
||||
|
||||
ITestObject to = CreateProxy(advised) as ITestObject;
|
||||
Assert.IsNotNull(to);
|
||||
Assert.IsTrue(to.Age == age, "Incorrect age");
|
||||
mock.Verify();
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -23,9 +23,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Spring.Aop.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Aop.Interceptor;
|
||||
using Spring.Aop.Support;
|
||||
using Spring.Collections;
|
||||
@@ -43,6 +42,14 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[TestFixture]
|
||||
public sealed class AopUtilsTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PointcutCanNeverApply()
|
||||
{
|
||||
@@ -83,7 +90,7 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[Test]
|
||||
public void CanApplyWithAdvisorYieldsTrueIfAdvisorIsNotKnownAdvisorType()
|
||||
{
|
||||
IAdvisor advisor = (IAdvisor) new DynamicMock(typeof (IAdvisor)).Object;
|
||||
IAdvisor advisor = (IAdvisor) mocks.CreateMock(typeof (IAdvisor));
|
||||
Assert.IsTrue(AopUtils.CanApply(advisor, typeof (TestObject), null));
|
||||
}
|
||||
|
||||
@@ -165,11 +172,12 @@ namespace Spring.Aop.Framework.DynamicProxy
|
||||
[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();
|
||||
IIntroductionAdvisor mockIntroAdvisor = (IIntroductionAdvisor) mocks.CreateMock(typeof(IIntroductionAdvisor));
|
||||
Expect.Call(mockIntroAdvisor.TypeFilter).Return(TrueTypeFilter.True);
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.IsTrue(AopUtils.CanApply(mockIntroAdvisor, typeof (TestObject), null));
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
#region Helper Classes
|
||||
|
||||
@@ -21,18 +21,7 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using AopAlliance.Intercept;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Aop.Interceptor;
|
||||
using Spring.Aop.Support;
|
||||
using Spring.Objects;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -31,11 +31,12 @@ using System.Web;
|
||||
|
||||
using AopAlliance.Aop;
|
||||
using AopAlliance.Intercept;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Aop.Advice;
|
||||
using Spring.Aop.Framework.Adapter;
|
||||
using Spring.Aop.Framework.DynamicProxy;
|
||||
using Spring.Aop.Interceptor;
|
||||
using Spring.Aop.Support;
|
||||
using Spring.Aop.Target;
|
||||
@@ -62,12 +63,14 @@ namespace Spring.Aop.Framework
|
||||
[TestFixture]
|
||||
public sealed class ProxyFactoryObjectTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
private IObjectFactory factory;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
this.factory = new XmlObjectFactory(new ReadOnlyXmlTestResource("proxyFactoryTests.xml", GetType()));
|
||||
mocks = new MockRepository();
|
||||
factory = new XmlObjectFactory(new ReadOnlyXmlTestResource("proxyFactoryTests.xml", GetType()));
|
||||
}
|
||||
|
||||
|
||||
@@ -475,46 +478,45 @@ namespace Spring.Aop.Framework
|
||||
[Test]
|
||||
public void IsSingletonFalseReturnsNew_ProxyInstance_NotNewProxyTargetSource()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof(IObjectFactory));
|
||||
GoodCommand target = new GoodCommand();
|
||||
mock.ExpectAndReturn("GetObject", target, "singleton");
|
||||
mock.ExpectAndReturn("GetObject", target, "singleton");
|
||||
IObjectFactory factory = (IObjectFactory)mock.Object;
|
||||
IObjectFactory mock = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));
|
||||
Expect.Call(mock.GetObject("singleton")).Return(target).Repeat.Twice();
|
||||
mocks.ReplayAll();
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
|
||||
fac.IsSingleton = false;
|
||||
fac.TargetName = "singleton";
|
||||
fac.ObjectFactory = factory;
|
||||
fac.ObjectFactory = mock;
|
||||
fac.AddAdvice(new NopInterceptor());
|
||||
|
||||
ICommand one = (ICommand)fac.GetObject();
|
||||
ICommand two = (ICommand)fac.GetObject();
|
||||
Assert.IsFalse(ReferenceEquals(one, two));
|
||||
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsSingletonTrueReturnsNew_ProxyInstance_NotNewProxyTargetSource()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof(IObjectFactory));
|
||||
GoodCommand target = new GoodCommand();
|
||||
mock.ExpectAndReturn("GetObject", target, "singleton");
|
||||
IObjectFactory factory = (IObjectFactory)mock.Object;
|
||||
IObjectFactory mock = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
|
||||
Expect.Call(mock.GetObject("singleton")).Return(target);
|
||||
mocks.ReplayAll();
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
|
||||
fac.IsSingleton = true; // default, just being explicit...
|
||||
fac.TargetName = "singleton";
|
||||
fac.ObjectFactory = factory;
|
||||
fac.ObjectFactory = mock;
|
||||
fac.AddAdvice(new NopInterceptor());
|
||||
|
||||
ICommand one = (ICommand)fac.GetObject();
|
||||
ICommand two = (ICommand)fac.GetObject();
|
||||
Assert.IsTrue(ReferenceEquals(one, two));
|
||||
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -550,17 +552,17 @@ namespace Spring.Aop.Framework
|
||||
GoodCommand target = new GoodCommand();
|
||||
NopInterceptor advice = new NopInterceptor();
|
||||
|
||||
IDynamicMock mock = new DynamicMock(typeof(IObjectFactory));
|
||||
mock.ExpectAndReturn("GetObject", advice, "advice");
|
||||
mock.ExpectAndReturn("GetObject", target, "singleton");
|
||||
mock.ExpectAndReturn("GetType", typeof(GoodCommand), "singleton");
|
||||
IObjectFactory factory = (IObjectFactory)mock.Object;
|
||||
IObjectFactory mock = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));
|
||||
Expect.Call(mock.GetObject("advice")).Return(advice);
|
||||
Expect.Call(mock.GetObject("singleton")).Return(target);
|
||||
Expect.Call(mock.GetType("singleton")).Return(typeof(GoodCommand));
|
||||
mocks.ReplayAll();
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
|
||||
fac.IsSingleton = true; // default, just being explicit...
|
||||
fac.InterceptorNames = new string[] { "advice", "singleton" };
|
||||
fac.ObjectFactory = factory;
|
||||
fac.ObjectFactory = mock;
|
||||
|
||||
ICommand one = (ICommand)fac.GetObject();
|
||||
ICommand two = (ICommand)fac.GetObject();
|
||||
@@ -570,7 +572,7 @@ namespace Spring.Aop.Framework
|
||||
two.Execute();
|
||||
Assert.AreEqual(2, advice.Count);
|
||||
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -579,24 +581,23 @@ namespace Spring.Aop.Framework
|
||||
GoodCommand target = new GoodCommand();
|
||||
NopInterceptor advice = new NopInterceptor();
|
||||
|
||||
IDynamicMock mock = new DynamicMock(typeof(IObjectFactory));
|
||||
mock.ExpectAndReturn("IsSingleton", true, "advice"); // advice is a singleton...
|
||||
mock.ExpectAndReturn("GetObject", advice, "advice");
|
||||
mock.ExpectAndReturn("GetType", typeof(GoodCommand), "prototype");
|
||||
IObjectFactory mock = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
|
||||
Expect.Call(mock.IsSingleton("advice")).Return(true); // advice is a singleton...
|
||||
Expect.Call(mock.GetObject("advice")).Return(advice);
|
||||
Expect.Call(mock.GetType("prototype")).Return(typeof(GoodCommand));
|
||||
|
||||
mock.ExpectAndReturn("GetObject", advice, "advice");
|
||||
mock.ExpectAndReturn("GetObject", target, "prototype");
|
||||
|
||||
IObjectFactory factory = (IObjectFactory)mock.Object;
|
||||
Expect.Call(mock.GetObject("advice")).Return(advice);
|
||||
Expect.Call(mock.GetObject("prototype")).Return(target);
|
||||
mocks.ReplayAll();
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
|
||||
fac.IsSingleton = false;
|
||||
fac.InterceptorNames = new string[] { "advice", "prototype" };
|
||||
fac.ObjectFactory = factory;
|
||||
fac.ObjectFactory = mock;
|
||||
|
||||
fac.GetObject();
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -687,7 +688,7 @@ namespace Spring.Aop.Framework
|
||||
[ExpectedException(typeof(AopConfigException))]
|
||||
public void NullNameInInterceptorNamesArray()
|
||||
{
|
||||
IObjectFactory factory = (IObjectFactory)new DynamicMock(typeof(IObjectFactory)).Object;
|
||||
IObjectFactory factory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName };
|
||||
@@ -699,7 +700,7 @@ namespace Spring.Aop.Framework
|
||||
[Test]
|
||||
public void PassEmptyInterceptorNamesArray_WithTargetThatImplementsAnInterfaceCanBeCastToSaidInterface()
|
||||
{
|
||||
IObjectFactory factory = (IObjectFactory)new DynamicMock(typeof(IObjectFactory)).Object;
|
||||
IObjectFactory factory = (IObjectFactory) mocks.CreateMock(typeof(IObjectFactory));
|
||||
|
||||
ProxyFactoryObject fac = new ProxyFactoryObject();
|
||||
fac.ProxyInterfaces = new string[] { };
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Caching;
|
||||
using Spring.Context;
|
||||
|
||||
@@ -38,17 +38,19 @@ namespace Spring.Aspects.Cache
|
||||
[TestFixture]
|
||||
public sealed class CacheParameterAdviceTests
|
||||
{
|
||||
private IDynamicMock mockContext;
|
||||
private MockRepository mocks;
|
||||
private IApplicationContext mockContext;
|
||||
private CacheParameterAdvice advice;
|
||||
private ICache cache;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mockContext = new DynamicMock(typeof (IApplicationContext));
|
||||
mocks = new MockRepository();
|
||||
mockContext = (IApplicationContext) mocks.CreateMock(typeof (IApplicationContext));
|
||||
|
||||
advice = new CacheParameterAdvice();
|
||||
advice.ApplicationContext = (IApplicationContext) mockContext.Object;
|
||||
advice.ApplicationContext = mockContext;
|
||||
|
||||
cache = new NonExpiringCache();
|
||||
}
|
||||
@@ -60,13 +62,14 @@ namespace Spring.Aspects.Cache
|
||||
object[] args = new object[] {new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian")};
|
||||
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
mocks.ReplayAll();
|
||||
|
||||
// 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();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -76,7 +79,8 @@ namespace Spring.Aspects.Cache
|
||||
object[] args = new object[] { new Inventor("Nikola Tesla", new DateTime(1856, 7, 9), "Serbian") };
|
||||
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
mocks.ReplayAll();
|
||||
|
||||
// parameter value should be added to both cache
|
||||
advice.AfterReturning(null, method, args, null);
|
||||
@@ -84,7 +88,7 @@ namespace Spring.Aspects.Cache
|
||||
Assert.AreEqual(args[0], cache.Get("Nikola Tesla"));
|
||||
Assert.AreEqual(args[0], cache.Get("Serbian"));
|
||||
|
||||
mockContext.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -96,15 +100,13 @@ namespace Spring.Aspects.Cache
|
||||
// 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)
|
||||
private void ExpectCacheInstanceRetrieval(string cacheName, ICache cacheToReturn)
|
||||
{
|
||||
mockContext.ExpectAndReturn("GetObject", cache, cacheName);
|
||||
Expect.Call(mockContext.GetObject(cacheName)).Return(cacheToReturn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Caching;
|
||||
using Spring.Context;
|
||||
|
||||
@@ -38,17 +39,19 @@ namespace Spring.Aspects.Cache
|
||||
[TestFixture]
|
||||
public sealed class InvalidateCacheAdviceTests
|
||||
{
|
||||
private IDynamicMock mockContext;
|
||||
private IApplicationContext mockContext;
|
||||
private InvalidateCacheAdvice advice;
|
||||
private ICache cache;
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mockContext = new DynamicMock(typeof (IApplicationContext));
|
||||
mocks = new MockRepository();
|
||||
mockContext = (IApplicationContext) mocks.CreateMock(typeof (IApplicationContext));
|
||||
|
||||
advice = new InvalidateCacheAdvice();
|
||||
advice.ApplicationContext = (IApplicationContext) mockContext.Object;
|
||||
advice.ApplicationContext = mockContext;
|
||||
|
||||
cache = new NonExpiringCache();
|
||||
cache.Insert(1, "one");
|
||||
@@ -63,6 +66,7 @@ namespace Spring.Aspects.Cache
|
||||
object[] args = new object[] { 2 };
|
||||
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.AreEqual(3, cache.Count);
|
||||
|
||||
@@ -71,7 +75,7 @@ namespace Spring.Aspects.Cache
|
||||
Assert.AreEqual(2, cache.Count);
|
||||
Assert.IsNull(cache.Get(2));
|
||||
|
||||
mockContext.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -81,6 +85,7 @@ namespace Spring.Aspects.Cache
|
||||
object[] args = new object[] { 2 };
|
||||
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.AreEqual(3, cache.Count);
|
||||
|
||||
@@ -89,7 +94,7 @@ namespace Spring.Aspects.Cache
|
||||
Assert.AreEqual(1, cache.Count);
|
||||
Assert.AreEqual("two", cache.Get(2));
|
||||
|
||||
mockContext.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -98,6 +103,7 @@ namespace Spring.Aspects.Cache
|
||||
MethodInfo method = typeof(InvalidateCacheTarget).GetMethod("InvalidateAll");
|
||||
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.AreEqual(3, cache.Count);
|
||||
|
||||
@@ -105,7 +111,7 @@ namespace Spring.Aspects.Cache
|
||||
advice.AfterReturning(null, method, null, null);
|
||||
Assert.AreEqual(0, cache.Count);
|
||||
|
||||
mockContext.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -116,6 +122,7 @@ namespace Spring.Aspects.Cache
|
||||
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
ExpectCacheInstanceRetrieval("cache", cache);
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.AreEqual(3, cache.Count);
|
||||
|
||||
@@ -124,7 +131,7 @@ namespace Spring.Aspects.Cache
|
||||
advice.AfterReturning(null, method, args, null);
|
||||
Assert.AreEqual(0, cache.Count);
|
||||
|
||||
mockContext.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -139,15 +146,13 @@ namespace Spring.Aspects.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)
|
||||
private void ExpectCacheInstanceRetrieval(string cacheName, ICache cacheToReturn)
|
||||
{
|
||||
mockContext.ExpectAndReturn("GetObject", cache, cacheName);
|
||||
Expect.Call(mockContext.GetObject(cacheName)).Return(cacheToReturn);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Core.TypeResolution
|
||||
@@ -35,12 +36,19 @@ namespace Spring.Core.TypeResolution
|
||||
[TestFixture]
|
||||
public sealed class CachedTypeResolverTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(TypeLoadException))]
|
||||
public void ResolveWithNullTypeName() {
|
||||
|
||||
IDynamicMock mock = new DynamicMock(typeof(ITypeResolver));
|
||||
ITypeResolver mockResolver = (ITypeResolver) mock.Object;
|
||||
ITypeResolver mockResolver = (ITypeResolver) mocks.DynamicMock(typeof(ITypeResolver));
|
||||
|
||||
CachedTypeResolver resolver = new CachedTypeResolver(mockResolver);
|
||||
resolver.Resolve(null);
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Core.IO;
|
||||
using Spring.Util;
|
||||
|
||||
@@ -34,6 +36,14 @@ namespace Spring.Objects.Factory.Config
|
||||
[TestFixture]
|
||||
public class ResourceHandlerConfigurerTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialization()
|
||||
{
|
||||
@@ -60,7 +70,7 @@ namespace Spring.Objects.Factory.Config
|
||||
resourceHandlerConfiguer.ResourceHandlers = resourceHandlers;
|
||||
|
||||
|
||||
resourceHandlerConfiguer.PostProcessObjectFactory((IConfigurableListableObjectFactory)new DynamicMock(typeof(IConfigurableListableObjectFactory)).Object);
|
||||
resourceHandlerConfiguer.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)));
|
||||
|
||||
}
|
||||
|
||||
@@ -75,7 +85,7 @@ namespace Spring.Objects.Factory.Config
|
||||
resourceHandlerConfiguer.ResourceHandlers = resourceHandlers;
|
||||
|
||||
|
||||
resourceHandlerConfiguer.PostProcessObjectFactory((IConfigurableListableObjectFactory)new DynamicMock(typeof(IConfigurableListableObjectFactory)).Object);
|
||||
resourceHandlerConfiguer.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)));
|
||||
|
||||
}
|
||||
|
||||
@@ -99,7 +109,7 @@ namespace Spring.Objects.Factory.Config
|
||||
|
||||
}
|
||||
|
||||
private static void CreateConfigurerAndTestNewProtcol(IDictionary resourceHandlers)
|
||||
private void CreateConfigurerAndTestNewProtcol(IDictionary resourceHandlers)
|
||||
{
|
||||
ResourceHandlerConfigurer resourceHandlerConfiguer = new ResourceHandlerConfigurer();
|
||||
resourceHandlerConfiguer.ResourceHandlers = resourceHandlers;
|
||||
@@ -107,7 +117,7 @@ namespace Spring.Objects.Factory.Config
|
||||
resourceHandlerConfiguer.Order = 1;
|
||||
|
||||
|
||||
resourceHandlerConfiguer.PostProcessObjectFactory((IConfigurableListableObjectFactory)new DynamicMock(typeof(IConfigurableListableObjectFactory)).Object);
|
||||
resourceHandlerConfiguer.PostProcessObjectFactory((IConfigurableListableObjectFactory) mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)));
|
||||
|
||||
//todo investigate mocking the typeregistry, for now ask the actual one for information.
|
||||
Assert.IsTrue(ResourceHandlerRegistry.IsHandlerRegistered("httpsss"),
|
||||
|
||||
@@ -31,8 +31,10 @@ using System.Threading;
|
||||
using System.Web.Services;
|
||||
using Common.Logging;
|
||||
using Common.Logging.Simple;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Core.IO;
|
||||
@@ -59,6 +61,8 @@ namespace Spring.Objects.Factory.Xml
|
||||
[TestFixture]
|
||||
public sealed class XmlObjectFactoryTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
/// <summary>
|
||||
/// The setup logic executed before the execution of this test fixture.
|
||||
/// </summary>
|
||||
@@ -70,6 +74,12 @@ namespace Spring.Objects.Factory.Xml
|
||||
LogManager.Adapter = new NoOpLoggerFactoryAdapter();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ObjectDefinitionStoreException))]
|
||||
public void ReplacedMethodWithNoReplacerObjectNameSpecified()
|
||||
@@ -1499,8 +1509,7 @@ namespace Spring.Objects.Factory.Xml
|
||||
//FactoryMethods fm = (FactoryMethods) factory.GetObject("instanceFactoryMethodOverloads", new object[] {row});
|
||||
// Assert.AreEqual("DataRowCtor", fm.Name);
|
||||
|
||||
DynamicMock mock = new DynamicMock(typeof(IDataRecord));
|
||||
IDataRecord dataRecord = (IDataRecord) mock.Object;
|
||||
IDataRecord dataRecord = (IDataRecord) mocks.DynamicMock(typeof(IDataRecord));
|
||||
FactoryMethods fm = (FactoryMethods)factory.GetObject("instanceFactoryMethodOverloads", new object[] { dataRecord });
|
||||
Assert.AreEqual("DataRecordCtor", fm.Name);
|
||||
|
||||
|
||||
@@ -28,17 +28,13 @@ using System.EnterpriseServices;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using System.Runtime.Remoting;
|
||||
|
||||
using AopAlliance.Intercept;
|
||||
using NUnit.Framework;
|
||||
using DotNetMock.Dynamic;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Aop.Framework;
|
||||
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user