SPRNET-1367 - Remove dependency of unit tests on DotNetMock framework
Spring.Core.Tests completed
This commit is contained in:
@@ -20,315 +20,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using DotNetMock;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Config;
|
||||
|
||||
namespace Spring
|
||||
{
|
||||
public class MockConfigurableObjectFactory : MockObject, IConfigurableObjectFactory
|
||||
{
|
||||
private ExpectationCounter _destroyCalls = new ExpectationCounter("MockConfigurableObjectFactory.DestroySingletonCalls");
|
||||
|
||||
public void SetDisposeCalls(int expectedCalls)
|
||||
{
|
||||
_destroyCalls.Expected = expectedCalls;
|
||||
}
|
||||
|
||||
#region IConfigurableObjectFactory Members
|
||||
|
||||
public void RegisterSingleton(string objectName, object singletonObject)
|
||||
{
|
||||
}
|
||||
|
||||
public object GetSingleton(string objectName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_destroyCalls.Inc();
|
||||
}
|
||||
|
||||
public void IgnoreDependencyType(Type type)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public bool IsCurrentlyInCreation(string objectName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AddObjectPostProcessor(IObjectPostProcessor objectPostProcessor)
|
||||
{
|
||||
}
|
||||
|
||||
public int ObjectPostProcessorCount
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public void RegisterAlias(string objectName, string alias)
|
||||
{
|
||||
}
|
||||
|
||||
public void RegisterCustomConverter(Type requiredType, TypeConverter converter)
|
||||
{
|
||||
}
|
||||
|
||||
public bool ContainsSingleton(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string[] SingletonNames
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
#region ISingletonObjectRegistry Members
|
||||
|
||||
public int SingletonCount
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string objectName)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IObjectFactory ParentObjectFactory
|
||||
{
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHierarchicalObjectFactory Members
|
||||
|
||||
IObjectFactory IHierarchicalObjectFactory.ParentObjectFactory
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public bool ContainsLocalObject(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IObjectFactory Members
|
||||
|
||||
public bool IsCaseSensitive
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public object this[string name]
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public bool ContainsObject(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public object CreateObject(string name, Type requiredType, object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public string[] GetAliases(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, Type requiredType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
object IObjectFactory.GetObject(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, Type requiredType, object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsSingleton(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public bool IsPrototype(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Type GetType(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool IsTypeMatch(string name, Type targetType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target, string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class MockObjectFactory : MockObject, IObjectFactory
|
||||
{
|
||||
private Exception _exceptionToThrow = null;
|
||||
|
||||
public Exception ExceptionToThrow
|
||||
{
|
||||
get { return _exceptionToThrow; }
|
||||
set { _exceptionToThrow = value; }
|
||||
}
|
||||
|
||||
#region IObjectFactory Members
|
||||
|
||||
public bool IsCaseSensitive
|
||||
{
|
||||
get { innerExecute();
|
||||
return true; }
|
||||
}
|
||||
|
||||
public object this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsObject(string name)
|
||||
{
|
||||
innerExecute();
|
||||
return false;
|
||||
}
|
||||
|
||||
public string[] GetAliases(string name)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
public object CreateObject(string name, Type requiredType, object[] arguments)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, Type requiredType)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
object IObjectFactory.GetObject(string name)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, object[] arguments)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, Type requiredType, object[] arguments)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsSingleton(string name)
|
||||
{
|
||||
innerExecute();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public bool IsPrototype(string name)
|
||||
{
|
||||
innerExecute();
|
||||
return false;
|
||||
}
|
||||
|
||||
public Type GetType(string name)
|
||||
{
|
||||
innerExecute();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool IsTypeMatch(string name, Type targetType)
|
||||
{
|
||||
innerExecute();
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target, string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void innerExecute()
|
||||
{
|
||||
if (_exceptionToThrow != null)
|
||||
{
|
||||
throw _exceptionToThrow;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class Inventor
|
||||
{
|
||||
public string Name;
|
||||
|
||||
@@ -21,13 +21,10 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using DotNetMock;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Objects;
|
||||
using Spring.Objects.Factory;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
|
||||
@@ -39,168 +36,6 @@ namespace Spring.Context
|
||||
/// This class contains common mock implementations of Context interfaces,
|
||||
/// used for testing.
|
||||
/// </summary>
|
||||
public class MockMessageSource : MockObject, IMessageSource
|
||||
{
|
||||
private ExpectationCounter _getMessageCalls = new ExpectationCounter("MockMessageSource.GetMessageCounter");
|
||||
private ExpectationString _getMessageCode = new ExpectationString("MockMessageSource.GetMessageCode");
|
||||
private ExpectationString _getMessageDefaultMessage = new ExpectationString("MockMessageSource.GetMessageDefaultMessage");
|
||||
private ExpectationArray _getMessageArguments = new ExpectationArray("MockMessageSource.GetMessageArguments");
|
||||
|
||||
private string _getMessageReturn = null;
|
||||
|
||||
|
||||
public MockMessageSource()
|
||||
{
|
||||
// this is to ensure, that no expectations may be violated
|
||||
_getMessageCalls.Expected = -1;
|
||||
_getMessageCode.Expected = "something very, very unlikely " + Guid.NewGuid();
|
||||
_getMessageDefaultMessage.Expected = "something very, very unlikely " + Guid.NewGuid();
|
||||
_getMessageArguments.Expected = new object[] { "something very, very unlikely " + Guid.NewGuid() };
|
||||
}
|
||||
|
||||
public void SetExpectedGetMessageCalls(int calls)
|
||||
{
|
||||
_getMessageCalls.Expected = calls;
|
||||
}
|
||||
|
||||
public void SetExpectedGetMessageDefaultMessage(string defaultMessage)
|
||||
{
|
||||
_getMessageDefaultMessage.Expected = defaultMessage;
|
||||
}
|
||||
|
||||
public void SetExpectedGetMessageArguments(object[] arguments)
|
||||
{
|
||||
_getMessageArguments.Expected = arguments;
|
||||
}
|
||||
|
||||
public void SetExpectedGetMessageReturn(string message)
|
||||
{
|
||||
_getMessageReturn = message;
|
||||
}
|
||||
|
||||
public void SetExpectedGetMessageCode(string code)
|
||||
{
|
||||
_getMessageCode.Expected = code;
|
||||
}
|
||||
|
||||
#region IMessageSource Members
|
||||
|
||||
public string GetMessage(IMessageSourceResolvable resolvable, CultureInfo culture)
|
||||
{
|
||||
_getMessageCalls.Inc();
|
||||
return _getMessageReturn;
|
||||
}
|
||||
|
||||
public string GetMessage(string name, CultureInfo culture, params object[] args)
|
||||
{
|
||||
_getMessageCalls.Inc();
|
||||
_getMessageCode.Actual = name;
|
||||
_getMessageArguments.Actual = args;
|
||||
return _getMessageReturn;
|
||||
}
|
||||
|
||||
public string GetMessage(string name)
|
||||
{
|
||||
_getMessageCalls.Inc();
|
||||
_getMessageCode.Actual = name;
|
||||
return _getMessageReturn;
|
||||
}
|
||||
|
||||
public string GetMessage(string name, params object[] args)
|
||||
{
|
||||
_getMessageCalls.Inc();
|
||||
_getMessageCode.Actual = name;
|
||||
_getMessageArguments.Actual = args;
|
||||
return _getMessageReturn;
|
||||
}
|
||||
|
||||
|
||||
public string GetMessage(string name, string defaultMessage, CultureInfo culture, params object[] arguments)
|
||||
{
|
||||
_getMessageCalls.Inc();
|
||||
_getMessageCode.Actual = name;
|
||||
_getMessageDefaultMessage.Actual = defaultMessage;
|
||||
_getMessageArguments.Actual = arguments;
|
||||
return _getMessageReturn;
|
||||
}
|
||||
|
||||
public string GetMessage(string name, CultureInfo cultureInfo)
|
||||
{
|
||||
_getMessageCalls.Inc();
|
||||
_getMessageCode.Actual = name;
|
||||
return _getMessageReturn;
|
||||
}
|
||||
|
||||
public object GetResourceObject(string name, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetResourceObject(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ApplyResources(object value, string objectName, CultureInfo cultureInfo)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class MockMessageResolvable : MockObject, IMessageSourceResolvable
|
||||
{
|
||||
private string[] _codes;
|
||||
private string _defaultMessage;
|
||||
private object[] _arguments;
|
||||
private ExpectationCounter _getCodesCalls = new ExpectationCounter("MockMessageSource.Codes");
|
||||
|
||||
public void SetExpectedCodesCalls(int calls)
|
||||
{
|
||||
_getCodesCalls.Expected = calls;
|
||||
}
|
||||
|
||||
public void SetCode(string code)
|
||||
{
|
||||
SetCodes(new string[] {code});
|
||||
}
|
||||
|
||||
public void SetCodes(string[] codes)
|
||||
{
|
||||
_codes = codes;
|
||||
}
|
||||
|
||||
public void SetDefaultMessage(String defaultMessage)
|
||||
{
|
||||
_defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
public void SetArguments(object[] arguments)
|
||||
{
|
||||
_arguments = arguments;
|
||||
}
|
||||
|
||||
#region IMessageSourceResolvable Members
|
||||
|
||||
public object[] GetArguments()
|
||||
{
|
||||
return _arguments;
|
||||
}
|
||||
|
||||
public string[] GetCodes()
|
||||
{
|
||||
_getCodesCalls.Inc();
|
||||
return _codes;
|
||||
}
|
||||
|
||||
public string DefaultMessage
|
||||
{
|
||||
get { return _defaultMessage; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MockContextAwareObject : MarshalByRefObject,
|
||||
IApplicationContextAware, IMessageSourceAware, IResourceLoaderAware
|
||||
@@ -233,16 +68,19 @@ namespace Spring.Context
|
||||
}
|
||||
}
|
||||
|
||||
public class MockApplicationContext : AbstractApplicationContext, IMockObject
|
||||
public class MockApplicationContext : AbstractApplicationContext
|
||||
{
|
||||
private string _mockName;
|
||||
private bool _isVerified;
|
||||
private DefaultListableObjectFactory factory;
|
||||
private ExpectationCounter _closeCalls = new ExpectationCounter("MockConfigurableApplicationContext.CloseCalls");
|
||||
private int expectedCloseCalls;
|
||||
private int actualCloseCalls;
|
||||
//private ExpectationCounter _closeCalls = new ExpectationCounter("MockConfigurableApplicationContext.CloseCalls");
|
||||
|
||||
public void SetCloseCalls(int expectedCalls)
|
||||
{
|
||||
_closeCalls.Expected = expectedCalls;
|
||||
//_closeCalls.Expected = expectedCalls;
|
||||
expectedCloseCalls = expectedCalls;
|
||||
}
|
||||
|
||||
public MockApplicationContext() : this(null, null)
|
||||
@@ -299,7 +137,8 @@ namespace Spring.Context
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_closeCalls.Inc();
|
||||
actualCloseCalls++;
|
||||
//_closeCalls.Inc();
|
||||
}
|
||||
|
||||
#region IMockObject Members
|
||||
@@ -321,7 +160,9 @@ namespace Spring.Context
|
||||
|
||||
public void Verify()
|
||||
{
|
||||
Verifier.Verify(this);
|
||||
//Verifier.Verify(this);
|
||||
Assert.AreEqual(actualCloseCalls, expectedCloseCalls, "Did not receive the expected Count for object " + MockName);
|
||||
|
||||
_isVerified = true;
|
||||
}
|
||||
|
||||
@@ -333,291 +174,4 @@ namespace Spring.Context
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class MockDefaultApplicationContext : MockObject, IApplicationContext
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
#region IApplicationContext Members
|
||||
|
||||
public DateTime StartupDate
|
||||
{
|
||||
get { return new DateTime(); }
|
||||
}
|
||||
|
||||
public event ApplicationEventHandler ContextEvent;
|
||||
|
||||
public long StartupDateMilliseconds
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return AbstractApplicationContext.DefaultRootContextName; }
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public IApplicationContext ParentContext
|
||||
{
|
||||
get { return null; }
|
||||
set
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IListableObjectFactory Members
|
||||
|
||||
public string[] GetObjectDefinitionNames(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IObjectDefinition GetObjectDefinition(string name, bool includeAncestors)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string[] IListableObjectFactory.GetObjectDefinitionNames()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public string[] GetObjectNamesForType(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public string[] GetObjectNamesForType(
|
||||
Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary GetObjectsOfType(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IDictionary GetObjectsOfType(
|
||||
Type type, bool includePrototypes, bool includeFactoryObjects)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public int ObjectDefinitionCount
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public bool ContainsObjectDefinition(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IObjectFactory Members
|
||||
|
||||
public bool IsCaseSensitive
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public object this[string name]
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public bool ContainsObject(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public string[] GetAliases(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object CreateObject(string name, Type requiredType, object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, Type requiredType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
object IObjectFactory.GetObject(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object GetObject(string name, Type requiredType, object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsSingleton(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public bool IsPrototype(string name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Type GetType(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool IsTypeMatch(string name, Type targetType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target, string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConfigureObject(object target, string name, IObjectDefinition definition)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IHierarchicalObjectFactory Members
|
||||
|
||||
public IObjectFactory ParentObjectFactory
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
public bool ContainsLocalObject(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMessageSource Members
|
||||
|
||||
string IMessageSource.GetMessage(IMessageSourceResolvable resolvable, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string IMessageSource.GetMessage(string name, CultureInfo culture, params object[] args)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string IMessageSource.GetMessage(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string IMessageSource.GetMessage(string name, params object[] args)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string IMessageSource.GetMessage(string name, CultureInfo cultureInfo)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
object IMessageSource.GetResourceObject(string name, CultureInfo culture)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
object IMessageSource.GetResourceObject(string name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public string GetMessage(string name, string defaultMessage, CultureInfo culture, params object[] arguments)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
void IMessageSource.ApplyResources(object value, string objectName, CultureInfo cultureInfo)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IResourceLoader Members
|
||||
|
||||
public IResource GetResource(string location)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEventRegistry Members
|
||||
|
||||
public void PublishEvents(object sourceObject)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Subscribe(object subscriber)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Subscribe(object subscriber, Type targetSourceType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void PublishEvent(object sender, ApplicationEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public void Unsubscribe(object subscriber)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Unsubscribe(object subscriber, Type targetSourceType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
@@ -43,11 +42,13 @@ namespace Spring.Context.Support
|
||||
[Test]
|
||||
[ExpectedException(typeof (NoSuchMessageException))]
|
||||
public void GetResolvableNullCodes()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetExpectedCodesCalls(1);
|
||||
GetMessage(res, CultureInfo.CurrentCulture);
|
||||
res.Verify();
|
||||
{
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable) mocks.CreateMock(typeof (IMessageSourceResolvable));
|
||||
Expect.Call(res.GetCodes()).Return(null);
|
||||
Expect.Call(res.DefaultMessage).Return(null);
|
||||
mocks.ReplayAll();
|
||||
GetMessage(res, CultureInfo.CurrentCulture);
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -56,86 +57,93 @@ namespace Spring.Context.Support
|
||||
string MSGCODE = "nullCode";
|
||||
object[] MSGARGS = new object[] { "arg1", "arg2" };
|
||||
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetExpectedCodesCalls(1);
|
||||
res.SetArguments(MSGARGS);
|
||||
res.SetCode(MSGCODE);
|
||||
|
||||
MockMessageSource parentSource = new MockMessageSource();
|
||||
parentSource.SetExpectedGetMessageCalls(1);
|
||||
parentSource.SetExpectedGetMessageCode(MSGCODE);
|
||||
parentSource.SetExpectedGetMessageDefaultMessage(null);
|
||||
parentSource.SetExpectedGetMessageArguments(res.GetArguments());
|
||||
parentSource.SetExpectedGetMessageReturn("MockMessageSource");
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.GetArguments()).Return(MSGARGS);
|
||||
Expect.Call(res.GetCodes()).Return(new string[] {MSGCODE}).Repeat.Once();
|
||||
|
||||
IMessageSource parentSource = (IMessageSource)mocks.CreateMock(typeof(IMessageSource));
|
||||
Expect.Call(parentSource.GetMessage(MSGCODE, null, CultureInfo.CurrentCulture, MSGARGS)).Return(
|
||||
"MockMessageSource");
|
||||
ParentMessageSource = parentSource;
|
||||
|
||||
mocks.ReplayAll();
|
||||
Assert.AreEqual("MockMessageSource", GetMessage(res, CultureInfo.CurrentCulture), "My Message");
|
||||
parentSource.Verify();
|
||||
res.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageParentMessageSource()
|
||||
{
|
||||
object[] args = new object[] {"arguments"};
|
||||
MockMessageSource parentSource = new MockMessageSource();
|
||||
parentSource.SetExpectedGetMessageCalls(1);
|
||||
parentSource.SetExpectedGetMessageCode("null");
|
||||
parentSource.SetExpectedGetMessageDefaultMessage(null);
|
||||
parentSource.SetExpectedGetMessageArguments(args);
|
||||
parentSource.SetExpectedGetMessageReturn("my parent message");
|
||||
IMessageSource parentSource = (IMessageSource)mocks.CreateMock(typeof(IMessageSource));
|
||||
Expect.Call(parentSource.GetMessage("null", null, CultureInfo.CurrentCulture, args)).Return(
|
||||
"my parent message");
|
||||
ParentMessageSource = parentSource;
|
||||
mocks.ReplayAll();
|
||||
Assert.AreEqual("my parent message", GetMessage("null", "message", CultureInfo.CurrentCulture, args[0]));
|
||||
parentSource.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageResolvableDefaultMessage()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetDefaultMessage("MyDefaultMessage");
|
||||
res.SetCode(null);
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable) mocks.CreateMock(typeof (IMessageSourceResolvable));
|
||||
Expect.Call(res.DefaultMessage).Return("MyDefaultMessage").Repeat.AtLeastOnce();
|
||||
Expect.Call(res.GetCodes()).Return(null);
|
||||
Expect.Call(res.GetArguments()).Return(null);
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.AreEqual("MyDefaultMessage", GetMessage(res, CultureInfo.CurrentCulture), "Default");
|
||||
res.Verify();
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageResolvableReturnsFirstCode()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.DefaultMessage).Return(null).Repeat.AtLeastOnce();
|
||||
Expect.Call(res.GetCodes()).Return(new string[] {"null"});
|
||||
Expect.Call(res.GetArguments()).Return(null).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
UseCodeAsDefaultMessage = true;
|
||||
res.SetCode("null");
|
||||
Assert.AreEqual("null", GetMessage(res, CultureInfo.CurrentCulture), "Code");
|
||||
res.Verify();
|
||||
Assert.AreEqual("null", GetMessage(res, CultureInfo.CurrentCulture), "Code");
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof (NoSuchMessageException))]
|
||||
public void GetMessageResolvableNoValidMessage()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetCode(null);
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.DefaultMessage).Return(null).Repeat.AtLeastOnce();
|
||||
Expect.Call(res.GetCodes()).Return(null);
|
||||
Expect.Call(res.GetArguments()).Return(null).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
GetMessage(res, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageResolvableValidMessageAndCode()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetCode("code1");
|
||||
res.SetArguments(new object[] {"my", "arguments"});
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.GetCodes()).Return(new string[] {"code1"});
|
||||
Expect.Call(res.GetArguments()).Return(new object[] { "my", "arguments" }).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
Assert.AreEqual("my arguments", GetMessage(res, CultureInfo.CurrentCulture), "Resolve");
|
||||
res.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageResolvableValidMessageAndCodeNullCulture()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetCode("code1");
|
||||
res.SetArguments(new object[] {"my", "arguments"});
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.GetCodes()).Return(new string[] { "code1" });
|
||||
Expect.Call(res.GetArguments()).Return(new object[] { "my", "arguments" }).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
Assert.AreEqual("my arguments", GetMessage(res, null), "Resolve");
|
||||
res.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -175,21 +183,25 @@ namespace Spring.Context.Support
|
||||
[Test]
|
||||
public void GetMessageWithResolvableArguments()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetCode("code1");
|
||||
res.SetArguments(new object[] {"my", "resolvable"});
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.GetCodes()).Return(new string[] { "code1" });
|
||||
Expect.Call(res.GetArguments()).Return(new object[] { "my", "resolvable" }).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
Assert.AreEqual("spring my resolvable", GetMessage("code2", CultureInfo.CurrentCulture, new object[] {"spring", res}), "Resolve");
|
||||
res.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageResolvableValidMessageAndCodNullMessageFormat()
|
||||
{
|
||||
MockMessageResolvable res = new MockMessageResolvable();
|
||||
res.SetDefaultMessage("myDefaultMessage");
|
||||
res.SetCode("nullCode");
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.DefaultMessage).Return("myDefaultMessage").Repeat.AtLeastOnce();
|
||||
Expect.Call(res.GetCodes()).Return(new string[] { "nullCode" });
|
||||
Expect.Call(res.GetArguments()).Return(null).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
|
||||
Assert.AreEqual("myDefaultMessage", GetMessage(res, null), "Resolve");
|
||||
res.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
private void resetMe()
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -34,6 +35,14 @@ namespace Spring.Context.Support
|
||||
[TestFixture]
|
||||
public sealed class DefaultMessageSourceResolvableTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
[SetUp]
|
||||
public void Init()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void InstantiationWithASingleCodeDefaultsToEmptyDefaultMessage()
|
||||
{
|
||||
@@ -78,16 +87,16 @@ namespace Spring.Context.Support
|
||||
[Test]
|
||||
public void DefaultResolvableFromExistingResolvable()
|
||||
{
|
||||
MockMessageResolvable mockResolvable = new MockMessageResolvable();
|
||||
mockResolvable.SetExpectedCodesCalls(1);
|
||||
mockResolvable.SetCode("code1FromMock");
|
||||
mockResolvable.SetDefaultMessage("defaultMessageFromMock");
|
||||
mockResolvable.SetArguments(new object[] {"ArgumentFromMock"});
|
||||
DefaultMessageSourceResolvable dmr = new DefaultMessageSourceResolvable(mockResolvable);
|
||||
IMessageSourceResolvable res = (IMessageSourceResolvable)mocks.CreateMock(typeof(IMessageSourceResolvable));
|
||||
Expect.Call(res.DefaultMessage).Return("defaultMessageFromMock").Repeat.AtLeastOnce();
|
||||
Expect.Call(res.GetCodes()).Return(new string[] { "code1FromMock" });
|
||||
Expect.Call(res.GetArguments()).Return(new object[] { "ArgumentFromMock" }).Repeat.AtLeastOnce();
|
||||
mocks.ReplayAll();
|
||||
DefaultMessageSourceResolvable dmr = new DefaultMessageSourceResolvable(res);
|
||||
Assert.AreEqual("defaultMessageFromMock", dmr.DefaultMessage, "default");
|
||||
Assert.AreEqual("code1FromMock", dmr.LastCode, "codes");
|
||||
Assert.AreEqual("ArgumentFromMock", (dmr.GetArguments())[0], "arguments");
|
||||
mockResolvable.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
private string getResolvableString()
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -35,19 +35,18 @@ namespace Spring.Context.Support
|
||||
/// <author>Rick Evans</author>
|
||||
[TestFixture]
|
||||
public sealed class DelegatingMessageSourceTests
|
||||
{
|
||||
private const string LookupKey = "rick";
|
||||
private DynamicMock _mock;
|
||||
private IMessageSource _messageSource;
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
private DynamicMock TheMock
|
||||
{
|
||||
get { return _mock; }
|
||||
}
|
||||
private const string LookupKey = "rick";
|
||||
private IMessageSource _messageSource;
|
||||
|
||||
private IMessageSource MockMessageSource
|
||||
{
|
||||
get { return _messageSource; }
|
||||
get
|
||||
{
|
||||
return _messageSource;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,8 +55,8 @@ namespace Spring.Context.Support
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mock = new DynamicMock(typeof(IMessageSource));
|
||||
_messageSource = (IMessageSource) _mock.Object;
|
||||
mocks = new MockRepository();
|
||||
_messageSource = (IMessageSource)mocks.CreateMock(typeof(IMessageSource));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -81,13 +80,14 @@ namespace Spring.Context.Support
|
||||
[Test]
|
||||
public void GetMessage()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("GetMessage", expectedName, LookupKey);
|
||||
const string expectedName = "Rick Evans";
|
||||
Expect.Call(MockMessageSource.GetMessage(LookupKey)).Return(expectedName);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
string name = source.GetMessage(LookupKey);
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -102,12 +102,13 @@ namespace Spring.Context.Support
|
||||
public void GetMessageWithCulture()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("GetMessage", expectedName, LookupKey, CultureInfo.InvariantCulture);
|
||||
Expect.Call(MockMessageSource.GetMessage(LookupKey, CultureInfo.InvariantCulture)).Return(expectedName);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
string name = source.GetMessage(LookupKey, CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -122,12 +123,13 @@ namespace Spring.Context.Support
|
||||
public void GetMessageWithParams()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("GetMessage", expectedName, LookupKey, new string[] { "Rick", "Evans" });
|
||||
Expect.Call(MockMessageSource.GetMessage(LookupKey, new string[] {"Rick", "Evans"})).Return(expectedName);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
string name = source.GetMessage(LookupKey, "Rick", "Evans");
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -142,12 +144,14 @@ namespace Spring.Context.Support
|
||||
public void GetMessageWithCultureAndParams()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("GetMessage", expectedName, LookupKey, CultureInfo.InvariantCulture, new string[] { "Rick", "Evans" });
|
||||
Expect.Call(MockMessageSource.GetMessage(LookupKey, CultureInfo.InvariantCulture, new string[] {"Rick", "Evans"}))
|
||||
.Return(expectedName);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
string name = source.GetMessage(LookupKey, CultureInfo.InvariantCulture, "Rick", "Evans");
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -164,25 +168,30 @@ namespace Spring.Context.Support
|
||||
const string expectedName = "Rick Evans";
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
TheMock.ExpectAndReturn("GetMessage", expectedName, null, CultureInfo.InvariantCulture);
|
||||
Expect.Call(MockMessageSource.GetMessage((IMessageSourceResolvable)null, CultureInfo.InvariantCulture)).Return(expectedName);
|
||||
mocks.ReplayAll();
|
||||
string name = source.GetMessage(
|
||||
(IMessageSourceResolvable) null, CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetMessageWithNoParentMessageSourceAndMessageSourceResolvableAndCulture()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
DynamicMock mock = new DynamicMock(typeof(IMessageSourceResolvable));
|
||||
IMessageSourceResolvable resolvable = (IMessageSourceResolvable) mock.Object;
|
||||
mock.ExpectAndReturn("DefaultMessage", "Rick Evans");
|
||||
mock.ExpectAndReturn("DefaultMessage", "Rick Evans");
|
||||
|
||||
IMessageSourceResolvable resolvable =
|
||||
(IMessageSourceResolvable) mocks.CreateMock(typeof (IMessageSourceResolvable));
|
||||
Expect.Call(resolvable.DefaultMessage).Return(expectedName);
|
||||
Expect.Call(resolvable.DefaultMessage).Return(expectedName);
|
||||
|
||||
DelegatingMessageSource source = new DelegatingMessageSource();
|
||||
mocks.ReplayAll();
|
||||
string name = source.GetMessage(resolvable, CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(expectedName, name);
|
||||
mock.Verify();
|
||||
//mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -209,12 +218,13 @@ namespace Spring.Context.Support
|
||||
public void GetResourceObject()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("GetResourceObject", expectedName, LookupKey);
|
||||
DelegatingMessageSource source
|
||||
Expect.Call(MockMessageSource.GetResourceObject(LookupKey)).Return(expectedName);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
string name = (string) source.GetResourceObject(LookupKey);
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -229,12 +239,13 @@ namespace Spring.Context.Support
|
||||
public void GetResourceObjectWithCulture()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("GetResourceObject", expectedName, LookupKey, CultureInfo.InvariantCulture);
|
||||
Expect.Call(MockMessageSource.GetResourceObject(LookupKey, CultureInfo.InvariantCulture)).Return(expectedName);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
string name = (string) source.GetResourceObject(LookupKey, CultureInfo.InvariantCulture);
|
||||
Assert.AreEqual(expectedName, name);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -249,11 +260,12 @@ namespace Spring.Context.Support
|
||||
public void ApplyResources()
|
||||
{
|
||||
const string expectedName = "Rick Evans";
|
||||
TheMock.ExpectAndReturn("ApplyResources", expectedName, 12, "rick", CultureInfo.InvariantCulture);
|
||||
MockMessageSource.ApplyResources((object) 12, "rick", CultureInfo.InvariantCulture);
|
||||
DelegatingMessageSource source
|
||||
= new DelegatingMessageSource(MockMessageSource);
|
||||
mocks.ReplayAll();
|
||||
source.ApplyResources(12, "rick", CultureInfo.InvariantCulture);
|
||||
TheMock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -35,27 +35,38 @@ namespace Spring.Objects.Factory.Config
|
||||
[TestFixture]
|
||||
public sealed class AbstractFactoryObjectTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisposeCallbackIsNotInvokedOnDisposeIfInPrototypeMode()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof(IDisposable));
|
||||
DummyFactoryObject factory = new DummyFactoryObject(mock.Object);
|
||||
IDisposable disposable = (IDisposable) mocks.CreateMock(typeof (IDisposable));
|
||||
DummyFactoryObject factory = new DummyFactoryObject(disposable);
|
||||
mocks.ReplayAll();
|
||||
factory.IsSingleton = false;
|
||||
factory.GetObject();
|
||||
factory.Dispose();
|
||||
// in prototype mode, so the Dispose() method of the object must not be called...
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DisposeCallbackIsInvokedOnDispose()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof(IDisposable));
|
||||
mock.Expect("Dispose");
|
||||
DummyFactoryObject factory = new DummyFactoryObject(mock.Object);
|
||||
IDisposable disposable = (IDisposable)mocks.CreateMock(typeof(IDisposable));
|
||||
disposable.Dispose();
|
||||
LastCall.On(disposable).Repeat.Once();
|
||||
DummyFactoryObject factory = new DummyFactoryObject(disposable);
|
||||
mocks.ReplayAll();
|
||||
factory.AfterPropertiesSet();
|
||||
factory.Dispose();
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
private sealed class DummyFactoryObject : AbstractFactoryObject
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -36,19 +36,28 @@ namespace Spring.Objects.Factory.Config
|
||||
[TestFixture]
|
||||
public sealed class ObjectFactoryCreatingFactoryObjectTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SunnyDay()
|
||||
{
|
||||
TestObject dude = new TestObject("Rick Evans", 30);
|
||||
DynamicMock mock = new DynamicMock(typeof (IObjectFactory));
|
||||
IObjectFactory objectFactory = (IObjectFactory) mocks.CreateMock(typeof (IObjectFactory));
|
||||
const string lookupObjectName = "rick";
|
||||
mock.ExpectAndReturn("GetObject", dude, lookupObjectName);
|
||||
mock.ExpectAndReturn("GetObject", dude, lookupObjectName);
|
||||
Expect.Call(objectFactory.GetObject(lookupObjectName)).Return(dude).Repeat.Twice();
|
||||
ObjectFactoryCreatingFactoryObject factory = new ObjectFactoryCreatingFactoryObject();
|
||||
factory.ObjectFactory = (IObjectFactory) mock.Object;
|
||||
factory.ObjectFactory = (IObjectFactory) objectFactory;
|
||||
factory.TargetObjectName = lookupObjectName;
|
||||
factory.AfterPropertiesSet();
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
IGenericObjectFactory gof = (IGenericObjectFactory) factory.GetObject();
|
||||
IGenericObjectFactory gofOther = (IGenericObjectFactory) factory.GetObject();
|
||||
Assert.IsTrue(Object.ReferenceEquals(gof, gofOther),
|
||||
@@ -59,23 +68,23 @@ namespace Spring.Objects.Factory.Config
|
||||
Assert.IsNotNull(two, "Must never return null (IFactoryObject contract).");
|
||||
Assert.IsTrue(Object.ReferenceEquals(one, two),
|
||||
"Not returning the same instance.");
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PrototypeModeWithSingletonTarget()
|
||||
{
|
||||
TestObject dude = new TestObject("Rick Evans", 30);
|
||||
DynamicMock mock = new DynamicMock(typeof (IObjectFactory));
|
||||
TestObject dude = new TestObject("Rick Evans", 30);
|
||||
IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
|
||||
const string lookupObjectName = "rick";
|
||||
mock.ExpectAndReturn("GetObject", dude, lookupObjectName);
|
||||
mock.ExpectAndReturn("GetObject", dude, lookupObjectName);
|
||||
Expect.Call(objectFactory.GetObject(lookupObjectName)).Return(dude).Repeat.Twice();
|
||||
ObjectFactoryCreatingFactoryObject factory = new ObjectFactoryCreatingFactoryObject();
|
||||
factory.ObjectFactory = (IObjectFactory) mock.Object;
|
||||
factory.ObjectFactory = (IObjectFactory) objectFactory;
|
||||
factory.TargetObjectName = lookupObjectName;
|
||||
factory.IsSingleton = false;
|
||||
factory.AfterPropertiesSet();
|
||||
|
||||
mocks.ReplayAll();
|
||||
IGenericObjectFactory gofOne = (IGenericObjectFactory) factory.GetObject();
|
||||
IGenericObjectFactory gofTwo = (IGenericObjectFactory) factory.GetObject();
|
||||
Assert.IsFalse(Object.ReferenceEquals(gofOne, gofTwo),
|
||||
@@ -86,7 +95,7 @@ namespace Spring.Objects.Factory.Config
|
||||
Assert.IsNotNull(two, "Must never return null (IFactoryObject contract).");
|
||||
Assert.IsTrue(Object.ReferenceEquals(one, two),
|
||||
"Not returning the same instance to singleton object.");
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
using System.Collections.Specialized;
|
||||
using Common.Logging;
|
||||
using Common.Logging.Simple;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
@@ -40,6 +40,15 @@ namespace Spring.Objects.Factory.Config
|
||||
[TestFixture]
|
||||
public sealed class PropertyOverrideConfigurerTests
|
||||
{
|
||||
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The setup logic executed before the execution of this test fixture.
|
||||
/// </summary>
|
||||
@@ -135,13 +144,15 @@ namespace Spring.Objects.Factory.Config
|
||||
[Test]
|
||||
public void MalformedOverrideKey()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof (IConfigurableListableObjectFactory));
|
||||
IConfigurableListableObjectFactory fac = (IConfigurableListableObjectFactory) mock.Object;
|
||||
IConfigurableListableObjectFactory objectFactory =
|
||||
(IConfigurableListableObjectFactory) mocks.CreateMock(typeof (IConfigurableListableObjectFactory));
|
||||
IConfigurableListableObjectFactory fac = (IConfigurableListableObjectFactory) objectFactory;
|
||||
|
||||
PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
|
||||
NameValueCollection defaultProperties = new NameValueCollection();
|
||||
defaultProperties.Add("malformedKey", "Rick Evans");
|
||||
cfg.Properties = defaultProperties;
|
||||
mocks.ReplayAll();
|
||||
try
|
||||
{
|
||||
cfg.PostProcessObjectFactory(fac);
|
||||
@@ -150,7 +161,7 @@ namespace Spring.Objects.Factory.Config
|
||||
catch (FatalObjectException)
|
||||
{
|
||||
}
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -158,20 +169,21 @@ namespace Spring.Objects.Factory.Config
|
||||
{
|
||||
const string valueTo_NOT_BeOveridden = "Jenny Lewis";
|
||||
TestObject foo = new TestObject(valueTo_NOT_BeOveridden, 30);
|
||||
|
||||
IDynamicMock mock = new DynamicMock(typeof (IConfigurableListableObjectFactory));
|
||||
mock.ExpectAndReturn("GetObjectDefinition", null, "rubbish");
|
||||
IConfigurableListableObjectFactory fac = (IConfigurableListableObjectFactory) mock.Object;
|
||||
IConfigurableListableObjectFactory objectFactory =
|
||||
(IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory));
|
||||
Expect.Call(objectFactory.GetObjectDefinition("rubbish")).Return(null);
|
||||
IConfigurableListableObjectFactory fac = (IConfigurableListableObjectFactory) objectFactory;
|
||||
|
||||
PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
|
||||
NameValueCollection defaultProperties = new NameValueCollection();
|
||||
defaultProperties.Add("rubbish.Name", "Rick Evans");
|
||||
cfg.Properties = defaultProperties;
|
||||
mocks.ReplayAll();
|
||||
cfg.PostProcessObjectFactory(fac);
|
||||
Assert.AreEqual(valueTo_NOT_BeOveridden, foo.Name,
|
||||
"Property value was overridden, but a rubbish objectName root was supplied.");
|
||||
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -25,9 +25,8 @@ using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Spring.Core.IO;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Core.TypeConversion;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
@@ -46,6 +45,13 @@ namespace Spring.Objects.Factory
|
||||
[TestFixture]
|
||||
public sealed class DefaultListableObjectFactoryTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
/// <summary>
|
||||
/// The setup logic executed before the execution of this test fixture.
|
||||
/// </summary>
|
||||
@@ -286,10 +292,8 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void GetObjectPostProcessorCount()
|
||||
{
|
||||
DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
|
||||
IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
|
||||
DynamicMock mock2 = new DynamicMock(typeof(IObjectPostProcessor));
|
||||
IObjectPostProcessor proc2 = (IObjectPostProcessor)mock2.Object;
|
||||
IObjectPostProcessor proc1 = (IObjectPostProcessor) mocks.CreateMock(typeof (IObjectPostProcessor));
|
||||
IObjectPostProcessor proc2 = (IObjectPostProcessor)mocks.CreateMock(typeof(IObjectPostProcessor));
|
||||
|
||||
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
|
||||
|
||||
@@ -299,6 +303,7 @@ namespace Spring.Objects.Factory
|
||||
Assert.AreEqual(1, lof.ObjectPostProcessorCount, errMsg);
|
||||
lof.AddObjectPostProcessor(proc2);
|
||||
Assert.AreEqual(2, lof.ObjectPostProcessorCount, errMsg);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -309,10 +314,9 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void GetObjectPostProcessorCountDoesntRespectHierarchy()
|
||||
{
|
||||
DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
|
||||
IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
|
||||
DynamicMock mock2 = new DynamicMock(typeof(IObjectPostProcessor));
|
||||
IObjectPostProcessor proc2 = (IObjectPostProcessor)mock2.Object;
|
||||
|
||||
IObjectPostProcessor proc1 = (IObjectPostProcessor)mocks.CreateMock(typeof(IObjectPostProcessor));
|
||||
IObjectPostProcessor proc2 = (IObjectPostProcessor)mocks.CreateMock(typeof(IObjectPostProcessor));
|
||||
|
||||
DefaultListableObjectFactory child = new DefaultListableObjectFactory();
|
||||
DefaultListableObjectFactory parent = new DefaultListableObjectFactory(child);
|
||||
@@ -1631,8 +1635,7 @@ namespace Spring.Objects.Factory
|
||||
[Test]
|
||||
public void IgnoreObjectPostProcessorDuplicates()
|
||||
{
|
||||
DynamicMock mock1 = new DynamicMock(typeof(IObjectPostProcessor));
|
||||
IObjectPostProcessor proc1 = (IObjectPostProcessor)mock1.Object;
|
||||
IObjectPostProcessor proc1 = (IObjectPostProcessor)mocks.CreateMock(typeof(IObjectPostProcessor));
|
||||
|
||||
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
|
||||
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Util;
|
||||
|
||||
@@ -37,17 +36,24 @@ namespace Spring.Objects.Factory
|
||||
[TestFixture]
|
||||
public sealed class ObjectDefinitionStoreExceptionTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
[Test]
|
||||
public void FromResource()
|
||||
{
|
||||
string expectedName = "bing";
|
||||
string expectedResourceDescription = "mock.resource";
|
||||
DynamicMock mock = new DynamicMock(typeof(IResource));
|
||||
mock.ExpectAndReturn("Description", expectedResourceDescription);
|
||||
IResource resource = (IResource) mock.Object;
|
||||
string expectedResourceDescription = "mock.resource";
|
||||
IResource resource = (IResource) mocks.CreateMock(typeof (IResource));
|
||||
Expect.Call(resource.Description).Return(expectedResourceDescription);
|
||||
mocks.ReplayAll();
|
||||
ObjectDefinitionStoreException inex
|
||||
= new ObjectDefinitionStoreException(resource, expectedName, "mmm...");
|
||||
mock.Verify();
|
||||
mocks.VerifyAll();
|
||||
CheckSerialization(inex, expectedName, expectedResourceDescription);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,8 @@
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -37,46 +36,56 @@ namespace Spring.Objects.Factory.Support
|
||||
[TestFixture]
|
||||
public sealed class LookupMethodReplacerTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof (ArgumentNullException))]
|
||||
public void InstantiationWithNullDefinition()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof (IObjectFactory));
|
||||
new LookupMethodReplacer(null, (IObjectFactory) mock.Object);
|
||||
IObjectFactory objectFactory = (IObjectFactory) mocks.CreateMock(typeof (IObjectFactory));
|
||||
new LookupMethodReplacer(null, objectFactory);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof (ArgumentNullException))]
|
||||
public void InstantiationWithNullFactory()
|
||||
{
|
||||
IDynamicMock mock = new DynamicMock(typeof(IConfigurableObjectDefinition));
|
||||
new LookupMethodReplacer((IConfigurableObjectDefinition)mock.Object, null);
|
||||
IConfigurableObjectDefinition configurableObjectDefinition =
|
||||
(IConfigurableObjectDefinition) mocks.CreateMock(typeof (IConfigurableObjectDefinition));
|
||||
new LookupMethodReplacer(configurableObjectDefinition, null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SunnyDayPath()
|
||||
{
|
||||
IDynamicMock mockFactory = new DynamicMock(typeof (IObjectFactory));
|
||||
IDynamicMock mockDefinition = new DynamicMock(typeof (IConfigurableObjectDefinition));
|
||||
|
||||
object expectedLookup = new object();
|
||||
IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
|
||||
IConfigurableObjectDefinition configurableObjectDefinition =
|
||||
(IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition));
|
||||
|
||||
object expectedLookup = new object();
|
||||
const string LookupObjectName = "foo";
|
||||
mockFactory.ExpectAndReturn("GetObject", expectedLookup, LookupObjectName);
|
||||
|
||||
Expect.Call(objectFactory.GetObject(LookupObjectName)).Return(expectedLookup);
|
||||
|
||||
LookupMethodOverride ovr = new LookupMethodOverride("SunnyDayPath", LookupObjectName);
|
||||
MethodOverrides overrides = new MethodOverrides();
|
||||
overrides.Add(ovr);
|
||||
mockDefinition.ExpectAndReturn("MethodOverrides", overrides);
|
||||
|
||||
LookupMethodReplacer replacer = new LookupMethodReplacer((IConfigurableObjectDefinition)mockDefinition.Object, (IObjectFactory)mockFactory.Object);
|
||||
Expect.Call(configurableObjectDefinition.MethodOverrides).Return(overrides);
|
||||
|
||||
LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory);
|
||||
mocks.ReplayAll();
|
||||
MethodInfo method = (MethodInfo) MethodBase.GetCurrentMethod();
|
||||
|
||||
object lookup = replacer.Implement(this, method, new object[] {});
|
||||
Assert.AreSame(expectedLookup, lookup);
|
||||
|
||||
mockFactory.Verify();
|
||||
mockDefinition.Verify();
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,10 +75,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DotNetMock, Version=0.7.5.0, Culture=neutral, PublicKeyToken=65e474d141e25e07">
|
||||
<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 in New Issue
Block a user