Remove DotNetMock

This commit is contained in:
Marko Lahma
2012-02-18 14:24:00 +02:00
parent 6365b8654f
commit 41a0f3ce0a
25 changed files with 382 additions and 957 deletions

View File

@@ -76,10 +76,6 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<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.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>

View File

@@ -93,10 +93,6 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<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.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>

View File

@@ -76,10 +76,6 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<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.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>

View File

@@ -93,10 +93,6 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<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.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>

Binary file not shown.

Binary file not shown.

View File

@@ -24,13 +24,11 @@ using System;
using System.Runtime.Serialization;
using AopAlliance.Aop;
using AopAlliance.Intercept;
using DotNetMock.Dynamic;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Aop.Interceptor;
using Spring.Aop.Support;
using Spring.Objects;
using Spring.Proxy;
using Spring.Util;
#endregion
@@ -545,12 +543,7 @@ namespace Spring.Aop.Framework
[Test]
public void AdvisedSupportListenerMethodsAreCalledAppropriately()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;
mock.Expect("Activated");
mock.Expect("AdviceChanged");
mock.Expect("InterfacesChanged");
IAdvisedSupportListener listener = MockRepository.GenerateMock<IAdvisedSupportListener>();
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
@@ -562,14 +555,15 @@ namespace Spring.Aop.Framework
// must fire the InterfacesChanged callback...
factory.AddInterface(typeof(ISerializable));
mock.Verify();
listener.AssertWasCalled(x => x.Activated(Arg<AdvisedSupport>.Is.NotNull));
listener.AssertWasCalled(x => x.AdviceChanged(Arg<AdvisedSupport>.Is.NotNull));
listener.AssertWasCalled(x => x.InterfacesChanged(Arg<AdvisedSupport>.Is.NotNull));
}
[Test]
public void AdvisedSupportListenerMethodsAre_NOT_CalledIfProxyHasNotBeenCreated()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;
IAdvisedSupportListener listener = MockRepository.GenerateMock<IAdvisedSupportListener>();
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
@@ -579,7 +573,8 @@ namespace Spring.Aop.Framework
// must not fire the InterfacesChanged callback...
factory.AddInterface(typeof(ISerializable));
mock.Verify();
listener.AssertWasNotCalled(x => x.AdviceChanged(Arg<AdvisedSupport>.Is.Anything));
listener.AssertWasNotCalled(x => x.InterfacesChanged(Arg<AdvisedSupport>.Is.Anything));
}
[Test]
@@ -599,8 +594,7 @@ namespace Spring.Aop.Framework
[Test]
public void RemoveAdvisedSupportListener()
{
IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener));
IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;
IAdvisedSupportListener listener = MockRepository.GenerateMock<IAdvisedSupportListener>();
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
@@ -609,7 +603,9 @@ namespace Spring.Aop.Framework
factory.GetProxy();
// check that no lifecycle callback methods were invoked on the listener...
mock.Verify();
listener.AssertWasNotCalled(x => x.Activated(Arg<AdvisedSupport>.Is.Anything));
listener.AssertWasNotCalled(x => x.AdviceChanged(Arg<AdvisedSupport>.Is.Anything));
listener.AssertWasNotCalled(x => x.InterfacesChanged(Arg<AdvisedSupport>.Is.Anything));
}
[Test]

View File

@@ -15,14 +15,12 @@
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections;
using NUnit.Framework;
using DotNetMock.Dynamic;
using AopAlliance.Aop;
using Rhino.Mocks;
using Spring.Aop.Framework;
using Spring.Objects;
#endregion
@@ -56,23 +54,20 @@ namespace Spring.Aop.Support
}
[Test]
public void testIntroductionInterceptorWithDelegation()
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);
ITimeStampedIntroduction ts = MockRepository.GenerateMock<ITimeStampedIntroduction>();
ts.Stub(x => x.TimeStamp).Return(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
@@ -81,15 +76,14 @@ namespace Spring.Aop.Support
{
}
public void testIntroductionInterceptorWithInterfaceHierarchy()
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);
ISubTimeStampedIntroduction ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>();
ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
// we must add introduction, not an advisor
@@ -98,19 +92,16 @@ namespace Spring.Aop.Support
object proxy = factory.GetProxy();
ISubTimeStamped tsp = (ISubTimeStamped) proxy;
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
tsControl.Verify();
}
public void testIntroductionInterceptorWithSuperInterface()
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);
ISubTimeStamped ts = MockRepository.GenerateMock<ISubTimeStampedIntroduction>();
ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);
factory.AddIntroduction(0, new DefaultIntroductionAdvisor(
(ISubTimeStampedIntroduction)ts,
@@ -120,8 +111,6 @@ namespace Spring.Aop.Support
ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
Assert.IsTrue(!(tsp is ISubTimeStamped));
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
tsControl.Verify();
}
/// <summary>
@@ -137,7 +126,7 @@ namespace Spring.Aop.Support
{
_timestamp = timestamp;
}
public void foo()
public void Foo()
{
}
public DateTime TimeStamp
@@ -149,7 +138,7 @@ namespace Spring.Aop.Support
}
}
public void testAutomaticInterfaceRecognitionInDelegate()
public void TestAutomaticInterfaceRecognitionInDelegate()
{
IIntroductionAdvisor ia = new DefaultIntroductionAdvisor(new Test(EXPECTED_TIMESTAMP));
@@ -160,7 +149,7 @@ namespace Spring.Aop.Support
ITimeStamped ts = (ITimeStamped) pf.GetProxy();
Assert.IsTrue(ts.TimeStamp == EXPECTED_TIMESTAMP);
((ITest) ts).foo();
((ITest) ts).Foo();
int age = ((ITestObject) ts).Age;
}
@@ -178,7 +167,7 @@ namespace Spring.Aop.Support
// interfaces that it intends to expose.
public interface ITest
{
void foo();
void Foo();
}
public interface ISubTimeStamped : ITimeStamped

View File

@@ -75,10 +75,6 @@
<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>

View File

@@ -81,10 +81,6 @@
<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>

View File

@@ -81,10 +81,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>

View File

@@ -74,10 +74,6 @@
<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>

View File

@@ -80,10 +80,6 @@
<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>

View File

@@ -36,10 +36,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="DotNetMock, Version=0.8.1.0, Culture=neutral, PublicKeyToken=65e474d141e25e07">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\DotNetMock.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>

View File

@@ -44,10 +44,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
</Reference>
<Reference Include="DotNetMock, Version=0.8.1.0, Culture=neutral, PublicKeyToken=65e474d141e25e07">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\DotNetMock.dll</HintPath>
</Reference>
<Reference Include="Iesi.Collections, Version=1.0.0.3, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>

View File

@@ -73,10 +73,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, processorArchitecture=MSIL">
<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>

View File

@@ -79,10 +79,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, processorArchitecture=MSIL">
<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>

View File

@@ -1,230 +1,44 @@
using System;
using System.Data;
using DotNetMock;
using Spring.Transaction.Support;
namespace Spring.Transaction
{
public class MyMockTxnObject : MockObject, ISmartTransactionObject
{
private ExpectationCounter _isRollbackOnlyCalls = new ExpectationCounter( "IsRollbackOnlyCalls" );
private bool _isRollbackOnly = false;
public MyMockTxnObject() : this( "MyMockTxnObject" ) {}
public MyMockTxnObject( string name ) : base( name ) {}
public void SetExpectedRollbackOnlyCalls( int calls )
{
_isRollbackOnlyCalls.Expected = calls;
}
public void SetExpectedIsRollBackOnlyValue( bool isRollbackOnly )
{
_isRollbackOnly = isRollbackOnly;
}
#region ISmartTransactionObject Members
public bool RollbackOnly
{
get
{
_isRollbackOnlyCalls.Inc();
return _isRollbackOnly;
}
}
#endregion
}
public class MyMockTxnObjectSavepointMgr : MockObject, ISavepointManager, ISmartTransactionObject
{
private string _savepoint;
private ExpectationString _expectedSavepoint = new ExpectationString("Savepoint");
public void SetSavepointToReturn( string savepoint )
{
_savepoint = savepoint;
}
public void SetExpectedSavepoint( string savepoint )
{
_expectedSavepoint.Expected = savepoint;
}
#region ISmartTransactionObject Members
public bool RollbackOnly
{
get
{ // TODO: Add MyMockTxnObjectSavepointMgr.IsRollbackOnly implementation
return false;
}
}
#endregion
#region ISavepointManager Members
public void ReleaseSavepoint(string savepoint)
{
_expectedSavepoint.Actual = savepoint;
}
public void CreateSavepoint( string savepoint )
{
_expectedSavepoint.Actual = savepoint;
}
public void RollbackToSavepoint(string savepoint)
{
_expectedSavepoint.Actual = savepoint;
}
#endregion
}
public class MockTxnPlatformMgr : MockObject, IPlatformTransactionManager
{
private ExpectationCounter _commitCalls = new ExpectationCounter("CommitCalls");
private ExpectationCounter _getTransactionCalls = new ExpectationCounter("GetTxnCalls");
private ExpectationCounter _rollbackCalls = new ExpectationCounter("RollbackCalls");
private bool _throwRollbackException = false;
#region IPlatformTransactionManager Members
public void SetExpectedCommitCallCount( int count )
{
_commitCalls.Expected = count;
}
public void SetExpectedRollbackCallCount( int count )
{
_rollbackCalls.Expected = count;
}
public void SetExpectedGetTxnCallCount( int count )
{
_getTransactionCalls.Expected = count;
}
public bool ThrowRollbackException
{
set { _throwRollbackException = value; }
}
public void Rollback(ITransactionStatus transactionStatus)
{
_rollbackCalls.Inc();
if ( _throwRollbackException )
{
throw new Exception("Rollback");
}
}
public void Commit(ITransactionStatus transactionStatus)
{
_commitCalls.Inc();
}
public ITransactionStatus GetTransaction(ITransactionDefinition definition)
{
_getTransactionCalls.Inc();
return null;
}
#endregion
}
public class MockTxnSync : MockObject, ITransactionSynchronization
{
#region ITransactionSynchronization Members
public void AfterCompletion(Spring.Transaction.Support.TransactionSynchronizationStatus status)
{
// TODO: Add MockTxnSync.AfterCompletion implementation
}
public void BeforeCommit(bool readOnly)
{
// TODO: Add MockTxnSync.BeforeCommit implementation
}
public void AfterCommit()
{
}
public void Resume()
{
// TODO: Add MockTxnSync.Resume implementation
}
public void BeforeCompletion()
{
// TODO: Add MockTxnSync.BeforeCompletion implementation
}
public void Suspend()
{
// TODO: Add MockTxnSync.Suspend implementation
}
#endregion
}
public class MockTxnDefinition : MockObject, ITransactionDefinition
{
private int _transactionTimeout = DefaultTransactionDefinition.TIMEOUT_DEFAULT;
private TransactionPropagation _transactionPropagation = TransactionPropagation.NotSupported;
private bool _readOnly = false;
public class MockTxnDefinition : ITransactionDefinition
{
private int _transactionTimeout = DefaultTransactionDefinition.TIMEOUT_DEFAULT;
private TransactionPropagation _transactionPropagation = TransactionPropagation.NotSupported;
private bool _readOnly = false;
private string _name = null;
private System.Transactions.EnterpriseServicesInteropOption _esInteropOption;
#region ITransactionDefinition Members
public bool ReadOnly
{
get
{
return _readOnly;
}
set
{
_readOnly = value;
}
}
public bool ReadOnly
{
get { return _readOnly; }
set { _readOnly = value; }
}
public int TransactionTimeout
{
get
{
return _transactionTimeout;
}
set
{
_transactionTimeout = value;
}
}
public int TransactionTimeout
{
get { return _transactionTimeout; }
set { _transactionTimeout = value; }
}
public IsolationLevel TransactionIsolationLevel
{
get
{
return IsolationLevel.Unspecified;
}
}
public IsolationLevel TransactionIsolationLevel
{
get { return IsolationLevel.Unspecified; }
}
public TransactionPropagation PropagationBehavior
{
get
{
return _transactionPropagation;
}
set
{
_transactionPropagation = value;
}
}
public TransactionPropagation PropagationBehavior
{
get { return _transactionPropagation; }
set { _transactionPropagation = value; }
}
public string Name
{
get
{
return _name;
}
get { return _name; }
}
public System.Transactions.EnterpriseServicesInteropOption EnterpriseServicesInteropOption
@@ -233,133 +47,104 @@ namespace Spring.Transaction
set { _esInteropOption = value; }
}
#endregion
#endregion
}
}
public class MockTxnPlatformMgrAbstract : AbstractPlatformTransactionManager, IMockObject
{
private object _transaction;
private bool _isVerified;
private string _mockName;
private bool _isExistingTransaction;
public class MockTxnPlatformMgrAbstract : AbstractPlatformTransactionManager
{
private object _transaction;
private bool _isExistingTransaction;
private ExpectationCounter _doBeginCalls = new ExpectationCounter("DoBegin Calls");
private ExpectationCounter _doGetTxnCalls = new ExpectationCounter("DoGetTransaction Calls");
private ExpectationCounter _isExistingTxnCalls = new ExpectationCounter("IsExistingTransaction Calls");
private int _doBeginCalls;
private int _doGetTxnCalls;
private int _isExistingTxnCalls;
private bool _useSavepointForNestedTransaction;
public void SetExpectedCalls( string method, int calls )
{
switch ( method )
{
case "DoBegin":
_doBeginCalls.Expected = calls;
break;
case "IsExistingTransaction":
_isExistingTxnCalls.Expected = calls;
break;
case "DoGetTransaction":
_doGetTxnCalls.Expected = calls;
break;
default:
break;
}
}
public void SetTransaction( object transaction )
{
_transaction = transaction;
_isExistingTransaction = true;
}
public object Transaction
{
get { return _transaction; }
}
public bool Savepoints
{
set { _useSavepointForNestedTransaction = value; }
}
#region IMockObject Members
private bool _useSavepointForNestedTransaction;
public void NotImplemented(string methodName)
{
// TODO: Add MockTxnPlatformMgrAbstract.NotImplemented implementation
}
public void SetTransaction(object transaction)
{
_transaction = transaction;
_isExistingTransaction = true;
}
public string MockName
{
get { return _mockName; }
set { _mockName = value;}
}
public object Transaction
{
get { return _transaction; }
}
#endregion
public bool Savepoints
{
set { _useSavepointForNestedTransaction = value; }
}
#region IVerifiable Members
public int DoBeginCallCount
{
get { return _doBeginCalls; }
}
public void Verify()
{
Verifier.Verify( this );
_isVerified = true;
}
public int DoGetTransactionCallCount
{
get { return _doGetTxnCalls; }
}
public bool IsVerified
{
get { return _isVerified; }
}
public int IsExistingTransactionCallCount
{
get { return _isExistingTxnCalls; }
}
#endregion
#region AbstractPlatformTransactionManager Impls
#region AbstractPlatformTransactionManager Impls
protected override void DoResume(object transaction, object suspendedResources)
{
protected override void DoResume(object transaction, object suspendedResources)
{
}
}
protected override void DoCommit(DefaultTransactionStatus status)
{
protected override void DoCommit(DefaultTransactionStatus status)
{
}
}
protected override object DoGetTransaction()
{
_doGetTxnCalls.Inc();
if ( null == _transaction )
{
return new object();
}
else
{
return _transaction;
}
}
protected override object DoSuspend(object transaction)
{
return null;
}
protected override void DoBegin(object transaction, ITransactionDefinition definition)
{
_doBeginCalls.Inc();
}
protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
{
protected override object DoGetTransaction()
{
_doGetTxnCalls++;
if (null == _transaction)
{
return new object();
}
else
{
return _transaction;
}
}
}
protected override void DoRollback(DefaultTransactionStatus status)
{
}
protected override bool IsExistingTransaction(object transaction)
{
_isExistingTxnCalls.Inc();
return _isExistingTransaction;
}
protected override object DoSuspend(object transaction)
{
return null;
}
protected override bool UseSavepointForNestedTransaction()
{
return _useSavepointForNestedTransaction;
}
protected override void DoBegin(object transaction, ITransactionDefinition definition)
{
_doBeginCalls++;
}
#endregion
protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
{
}
}
protected override void DoRollback(DefaultTransactionStatus status)
{
}
}
protected override bool IsExistingTransaction(object transaction)
{
_isExistingTxnCalls++;
return _isExistingTransaction;
}
protected override bool UseSavepointForNestedTransaction()
{
return _useSavepointForNestedTransaction;
}
#endregion
}
}

View File

@@ -1,5 +1,5 @@
using System;
using NUnit.Framework;
using Rhino.Mocks;
namespace Spring.Transaction.Support
{
@@ -18,16 +18,17 @@ namespace Spring.Transaction.Support
TransactionSynchronizationManager.ClearSynchronization();
}
}
[TearDown]
public void Destroy()
{
_mockTxnMgr.Verify();
_mockTxnMgr = null;
if (TransactionSynchronizationManager.SynchronizationActive)
{
TransactionSynchronizationManager.Clear();
}
}
[Test]
public void VanillaProperties()
{
@@ -43,16 +44,18 @@ namespace Spring.Transaction.Support
Assert.IsTrue(_mockTxnMgr.NestedTransactionsAllowed);
Assert.IsTrue(_mockTxnMgr.RollbackOnCommitFailure);
}
[Test]
[ExpectedException(typeof(InvalidTimeoutException), ExpectedMessage = "Invalid transaction timeout")]
[ExpectedException(typeof (InvalidTimeoutException), ExpectedMessage = "Invalid transaction timeout")]
public void DefinitionInvalidTimeoutException()
{
MockTxnDefinition def = new MockTxnDefinition();
def.TransactionTimeout = -1000;
_mockTxnMgr.GetTransaction(def);
}
[Test]
[ExpectedException(typeof(IllegalTransactionStateException), ExpectedMessage = "Transaction propagation 'mandatory' but no existing transaction found")]
[ExpectedException(typeof (IllegalTransactionStateException), ExpectedMessage = "Transaction propagation 'mandatory' but no existing transaction found")]
public void DefinitionInvalidPropagationState()
{
MockTxnDefinition def = new MockTxnDefinition();
@@ -61,38 +64,46 @@ namespace Spring.Transaction.Support
}
[Test]
[ExpectedException(typeof(IllegalTransactionStateException), ExpectedMessage = "Transaction propagation 'never' but existing transaction found.")]
[ExpectedException(typeof (IllegalTransactionStateException), ExpectedMessage = "Transaction propagation 'never' but existing transaction found.")]
public void NeverPropagateState()
{
MockTxnDefinition def = new MockTxnDefinition();
def.PropagationBehavior = TransactionPropagation.Never;
setGeneralGetTransactionExpectations();
SetGeneralGetTransactionExpectations();
_mockTxnMgr.GetTransaction(def);
AssertVanillaGetTransactionExpectations();
}
[Test]
[ExpectedException(typeof(NestedTransactionNotSupportedException), ExpectedMessage = "Transaction manager does not allow nested transactions by default - specify 'NestedTransactionsAllowed' property with value 'true'")]
[ExpectedException(typeof (NestedTransactionNotSupportedException), ExpectedMessage = "Transaction manager does not allow nested transactions by default - specify 'NestedTransactionsAllowed' property with value 'true'")]
public void NoNestedTransactionsAllowed()
{
MockTxnDefinition def = new MockTxnDefinition();
def.PropagationBehavior = TransactionPropagation.Nested;
setGeneralGetTransactionExpectations();
SetGeneralGetTransactionExpectations();
_mockTxnMgr.GetTransaction(def);
AssertVanillaGetTransactionExpectations();
}
[Test]
public void TransactionSuspendedSuccessfully()
{
MockTxnDefinition def = new MockTxnDefinition();
def.PropagationBehavior = TransactionPropagation.NotSupported;
def.ReadOnly = false;
setGeneralGetTransactionExpectations();
SetGeneralGetTransactionExpectations();
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(def);
Assert.IsNull(status.Transaction);
Assert.IsTrue(!status.IsNewTransaction);
Assert.IsTrue(status.NewSynchronization);
Assert.IsTrue(!status.ReadOnly);
Assert.IsNotNull(status.SuspendedResources);
AssertVanillaGetTransactionExpectations();
}
[Test]
public void TransactionCreatedSuccessfully()
{
@@ -100,15 +111,17 @@ namespace Spring.Transaction.Support
def.PropagationBehavior = TransactionPropagation.RequiresNew;
def.ReadOnly = false;
setGeneralGetTransactionExpectations();
SetGeneralGetTransactionExpectations();
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(def);
Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
Assert.IsTrue(status.IsNewTransaction);
Assert.IsTrue(status.NewSynchronization);
Assert.IsTrue(!status.ReadOnly);
Assert.IsNotNull(status.SuspendedResources);
AssertVanillaGetTransactionExpectations();
}
[Test]
public void NestedTransactionSuccessfully()
{
@@ -116,17 +129,19 @@ namespace Spring.Transaction.Support
def.PropagationBehavior = TransactionPropagation.Nested;
def.ReadOnly = false;
setGeneralGetTransactionExpectations();
_mockTxnMgr.SetExpectedCalls("DoBegin", 1);
SetGeneralGetTransactionExpectations();
_mockTxnMgr.Savepoints = false;
_mockTxnMgr.NestedTransactionsAllowed = true;
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(def);
Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
Assert.IsTrue(status.IsNewTransaction);
Assert.AreEqual(true, status.NewSynchronization);
Assert.IsTrue(!status.ReadOnly);
Assert.IsNull(status.SuspendedResources);
AssertVanillaGetTransactionExpectations();
Assert.AreEqual(1, _mockTxnMgr.DoBeginCallCount);
}
[Test]
@@ -135,87 +150,94 @@ namespace Spring.Transaction.Support
MockTxnDefinition def = new MockTxnDefinition();
def.PropagationBehavior = TransactionPropagation.Nested;
def.ReadOnly = false;
setVanillaGetTransactionExpectations();
_mockTxnMgr.SetTransaction(new MyMockTxnObjectSavepointMgr());
_mockTxnMgr.SetExpectedCalls("DoBegin", 0);
ISavepointManager saveMgr = MockRepository.GenerateMock<ISavepointManager>();
_mockTxnMgr.SetTransaction(saveMgr);
_mockTxnMgr.Savepoints = true;
_mockTxnMgr.NestedTransactionsAllowed = true;
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(def);
Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
Assert.IsFalse(status.IsNewTransaction);
Assert.IsFalse(status.NewSynchronization);
Assert.IsTrue(!status.ReadOnly);
Assert.IsNull(status.SuspendedResources);
AssertVanillaGetTransactionExpectations();
Assert.AreEqual(0, _mockTxnMgr.DoBeginCallCount);
}
[Test]
public void DefaultPropagationBehavior()
{
MockTxnDefinition def = new MockTxnDefinition();
def.PropagationBehavior = TransactionPropagation.Required;
def.ReadOnly = true;
setGeneralGetTransactionExpectations();
SetGeneralGetTransactionExpectations();
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(def);
Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
Assert.IsTrue(!status.IsNewTransaction);
Assert.IsTrue(status.NewSynchronization);
Assert.IsTrue(status.ReadOnly);
Assert.IsNull(status.SuspendedResources);
AssertVanillaGetTransactionExpectations();
}
[Test]
public void DefaultPropagationBehaviorWithNullDefinition()
{
setGeneralGetTransactionExpectations();
SetGeneralGetTransactionExpectations();
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(null);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(null);
Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
Assert.IsFalse(status.IsNewTransaction);
Assert.IsTrue(status.NewSynchronization);
Assert.IsFalse(status.ReadOnly);
Assert.IsNull(status.SuspendedResources);
AssertVanillaGetTransactionExpectations();
}
[Test]
public void DefaultNoExistingTransaction()
{
setVanillaGetTransactionExpectations();
_mockTxnMgr.SetExpectedCalls("DoBegin", 1);
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(null);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(null);
Assert.IsNotNull(status.Transaction);
Assert.IsTrue(status.IsNewTransaction);
Assert.IsTrue(status.NewSynchronization);
Assert.IsTrue(!status.ReadOnly);
Assert.IsNull(status.SuspendedResources);
Assert.AreEqual(1, _mockTxnMgr.DoBeginCallCount);
AssertVanillaGetTransactionExpectations();
}
[Test]
public void DefaultBehaviorDefaultPropagationNoExistingTransaction()
{
setVanillaGetTransactionExpectations();
_mockTxnMgr.SetExpectedCalls("DoBegin", 0);
MockTxnDefinition def = new MockTxnDefinition();
def.PropagationBehavior = TransactionPropagation.Never;
def.ReadOnly = true;
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
DefaultTransactionStatus status = (DefaultTransactionStatus) _mockTxnMgr.GetTransaction(def);
Assert.IsNull(status.Transaction);
Assert.IsTrue(!status.IsNewTransaction);
Assert.IsTrue(status.NewSynchronization);
Assert.IsTrue(status.ReadOnly);
Assert.IsNull(status.SuspendedResources);
Assert.AreEqual(0, _mockTxnMgr.DoBeginCallCount);
AssertVanillaGetTransactionExpectations();
}
private void setGeneralGetTransactionExpectations()
private void SetGeneralGetTransactionExpectations()
{
_mockTxnMgr.SetTransaction(new object());
setVanillaGetTransactionExpectations();
}
private void setVanillaGetTransactionExpectations()
private void AssertVanillaGetTransactionExpectations()
{
_mockTxnMgr.SetExpectedCalls("DoGetTransaction", 1);
_mockTxnMgr.SetExpectedCalls("IsExistingTransaction", 1);
Assert.AreEqual(1, _mockTxnMgr.DoGetTransactionCallCount);
Assert.AreEqual(1, _mockTxnMgr.IsExistingTransactionCallCount);
}
}
}
}

View File

@@ -1,104 +1,111 @@
using System;
using NUnit.Framework;
using Spring.Transaction;
using Rhino.Mocks;
namespace Spring.Transaction.Support
{
[TestFixture]
public class DefaultTransactionStatusTests
{
[Test]
public void DefaultConstructorTests()
{
MyMockTxnObject txn = new MyMockTxnObject();
txn.SetExpectedIsRollBackOnlyValue( false );
txn.SetExpectedRollbackOnlyCalls( 1 );
[TestFixture]
public class DefaultTransactionStatusTests
{
[Test]
public void DefaultConstructorTests()
{
ISmartTransactionObject txn = MockRepository.GenerateMock<ISmartTransactionObject>();
DefaultTransactionStatus stat = new DefaultTransactionStatus( txn, true, false, false, true, new object() );
Assert.IsNotNull( stat.Transaction );
Assert.IsTrue( !stat.ReadOnly );
Assert.IsTrue( !stat.NewSynchronization );
Assert.IsNotNull( stat.SuspendedResources );
Assert.IsTrue( stat.IsNewTransaction );
Assert.IsTrue( ! stat.RollbackOnly );
stat.SetRollbackOnly();
Assert.IsTrue( stat.RollbackOnly );
txn.Verify();
}
[Test]
[ExpectedException(typeof(NestedTransactionNotSupportedException))]
public void CreateSavepointException()
{
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
stat.CreateSavepoint( "mySavePoint" );
}
[Test]
[ExpectedException(typeof(NestedTransactionNotSupportedException))]
public void RollbackSavepointException()
{
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
stat.RollbackToSavepoint(null);
}
[Test]
[ExpectedException(typeof(NestedTransactionNotSupportedException))]
public void ReleaseSavepointException()
{
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
stat.ReleaseSavepoint(null);
}
[Test]
public void CreateSaveAndHoldValidSavepoint()
{
MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
saveMgr.SetSavepointToReturn( "savepoint" );
DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
status.CreateAndHoldSavepoint( "savepoint" );
Assert.IsTrue( status.HasSavepoint );
Assert.AreEqual( "savepoint", status.Savepoint );
}
[Test]
[ExpectedException(typeof(TransactionUsageException))]
public void RollbackHeldSavepointException()
{
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
stat.RollbackToHeldSavepoint();
}
[Test]
public void RollbackHeldSavepointSuccess()
{
MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
string savepoint = "savepoint";
saveMgr.SetExpectedSavepoint( savepoint );
saveMgr.SetSavepointToReturn( savepoint );
DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
status.CreateAndHoldSavepoint( savepoint );
Assert.IsTrue( status.HasSavepoint );
Assert.AreEqual( savepoint, status.Savepoint );
DefaultTransactionStatus stat = new DefaultTransactionStatus(txn, true, false, false, true, new object());
Assert.IsNotNull(stat.Transaction);
Assert.IsTrue(!stat.ReadOnly);
Assert.IsTrue(!stat.NewSynchronization);
Assert.IsNotNull(stat.SuspendedResources);
Assert.IsTrue(stat.IsNewTransaction);
Assert.IsTrue(! stat.RollbackOnly);
stat.SetRollbackOnly();
Assert.IsTrue(stat.RollbackOnly);
status.RollbackToHeldSavepoint();
saveMgr.Verify();
}
[Test]
[ExpectedException(typeof(TransactionUsageException))]
public void ReleaseHeldSavepointException()
{
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
stat.ReleaseHeldSavepoint();
}
[Test]
public void ReleaseHeldSavepointSuccess()
{
MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
string savepoint = "savepoint";
saveMgr.SetExpectedSavepoint( savepoint );
saveMgr.SetSavepointToReturn( savepoint );
DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
status.CreateAndHoldSavepoint( savepoint );
Assert.IsTrue( status.HasSavepoint );
Assert.AreEqual( savepoint, status.Savepoint );
txn.AssertWasCalled(x => x.RollbackOnly, constraints => constraints.Repeat.Once());
}
status.ReleaseHeldSavepoint();
saveMgr.Verify();
}
}
}
[Test]
[ExpectedException(typeof (NestedTransactionNotSupportedException))]
public void CreateSavepointException()
{
ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
stat.CreateSavepoint("mySavePoint");
}
[Test]
[ExpectedException(typeof (NestedTransactionNotSupportedException))]
public void RollbackSavepointException()
{
ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
stat.RollbackToSavepoint(null);
}
[Test]
[ExpectedException(typeof (NestedTransactionNotSupportedException))]
public void ReleaseSavepointException()
{
ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
stat.ReleaseSavepoint(null);
}
[Test]
public void CreateSaveAndHoldValidSavepoint()
{
ISavepointManager saveMgr = MockRepository.GenerateMock<ISavepointManager>();
DefaultTransactionStatus status = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());
status.CreateAndHoldSavepoint("savepoint");
Assert.IsTrue(status.HasSavepoint);
Assert.AreEqual("savepoint", status.Savepoint);
}
[Test]
[ExpectedException(typeof (TransactionUsageException))]
public void RollbackHeldSavepointException()
{
ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
stat.RollbackToHeldSavepoint();
}
[Test]
public void RollbackHeldSavepointSuccess()
{
ISavepointManager saveMgr = MockRepository.GenerateMock<ISavepointManager>();
string savepoint = "savepoint";
DefaultTransactionStatus status = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());
status.CreateAndHoldSavepoint(savepoint);
Assert.IsTrue(status.HasSavepoint);
Assert.AreEqual(savepoint, status.Savepoint);
status.RollbackToHeldSavepoint();
saveMgr.AssertWasCalled(x => x.RollbackToSavepoint(savepoint));
}
[Test]
[ExpectedException(typeof (TransactionUsageException))]
public void ReleaseHeldSavepointException()
{
ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
stat.ReleaseHeldSavepoint();
}
[Test]
public void ReleaseHeldSavepointSuccess()
{
ISavepointManager saveMgr = MockRepository.GenerateMock<ISavepointManager>();
string savepoint = "savepoint";
DefaultTransactionStatus status = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());
status.CreateAndHoldSavepoint(savepoint);
Assert.IsTrue(status.HasSavepoint);
Assert.AreEqual(savepoint, status.Savepoint);
status.ReleaseHeldSavepoint();
saveMgr.AssertWasCalled(x => x.CreateSavepoint(savepoint));
saveMgr.AssertWasCalled(x => x.ReleaseSavepoint(savepoint));
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Core;
using Spring.Util;
@@ -51,7 +52,7 @@ namespace Spring.Transaction.Support
[ExpectedException(typeof(InvalidOperationException))]
public void RegisterSyncsInvalid()
{
TransactionSynchronizationManager.RegisterSynchronization(new MockTxnSync());
TransactionSynchronizationManager.RegisterSynchronization(MockRepository.GenerateMock<ITransactionSynchronization>());
}
[Test]
@@ -60,7 +61,7 @@ namespace Spring.Transaction.Support
TransactionSynchronizationManager.InitSynchronization();
IList syncs = TransactionSynchronizationManager.Synchronizations;
Assert.AreEqual( 0, syncs.Count );
TransactionSynchronizationManager.RegisterSynchronization( new MockTxnSync() );
TransactionSynchronizationManager.RegisterSynchronization(MockRepository.GenerateMock<ITransactionSynchronization>());
syncs = TransactionSynchronizationManager.Synchronizations;
Assert.AreEqual( 1, syncs.Count );
TransactionSynchronizationManager.ClearSynchronization();

View File

@@ -1,80 +1,87 @@
using System;
using NUnit.Framework;
using Rhino.Mocks;
namespace Spring.Transaction.Support
{
[TestFixture]
public class TransactionTemplateTests
{
[Test]
[ExpectedException(typeof(ArgumentException))]
public void NoTxnMgr()
{
TransactionTemplate temp = new TransactionTemplate();
temp.AfterPropertiesSet();
}
[Test]
public void TxnMgr()
{
TransactionTemplate temp = new TransactionTemplate();
temp.PlatformTransactionManager = new MockTxnPlatformMgr();
temp.AfterPropertiesSet();
}
[Test]
public void ExecuteException()
{
MockTxnPlatformMgr mock = new MockTxnPlatformMgr();
mock.SetExpectedGetTxnCallCount(1);
mock.SetExpectedRollbackCallCount(1);
TransactionTemplate temp = new TransactionTemplate(mock);
try
{
temp.Execute(new TransactionDelegate(DummyExceptionMethod));
Assert.Fail("Should throw exception");
} catch
{
}
mock.Verify();
}
[Test]
public void ExecuteExceptionRollbackException()
{
MockTxnPlatformMgr mock = new MockTxnPlatformMgr();
mock.SetExpectedGetTxnCallCount(1);
mock.SetExpectedRollbackCallCount(1);
mock.ThrowRollbackException = true;
TransactionTemplate temp = new TransactionTemplate(mock);
try
{
temp.Execute(new TransactionDelegate(DummyExceptionMethod));
Assert.Fail("Should throw exception");
}
catch
{
}
mock.Verify();
}
[Test]
public void NullResult()
{
MockTxnPlatformMgr mock = new MockTxnPlatformMgr();
mock.SetExpectedGetTxnCallCount(1);
mock.SetExpectedCommitCallCount(1);
TransactionTemplate temp = new TransactionTemplate(mock);
temp.AfterPropertiesSet();
Assert.AreEqual( mock, temp.PlatformTransactionManager);
Assert.IsNull( temp.Execute(new TransactionDelegate(DummyTransactionMethod) ) );
mock.Verify();
}
public object DummyTransactionMethod( ITransactionStatus status )
{
return status;
}
public object DummyExceptionMethod( ITransactionStatus status )
{
throw new Exception("Bad Error");
}
}
}
[TestFixture]
public class TransactionTemplateTests
{
[Test]
[ExpectedException(typeof (ArgumentException))]
public void NoTxnMgr()
{
TransactionTemplate temp = new TransactionTemplate();
temp.AfterPropertiesSet();
}
[Test]
public void TxnMgr()
{
TransactionTemplate temp = new TransactionTemplate();
temp.PlatformTransactionManager = MockRepository.GenerateMock<IPlatformTransactionManager>();
temp.AfterPropertiesSet();
}
[Test]
public void ExecuteException()
{
IPlatformTransactionManager mock = MockRepository.GenerateMock<IPlatformTransactionManager>();
TransactionTemplate temp = new TransactionTemplate(mock);
try
{
temp.Execute(new TransactionDelegate(DummyExceptionMethod));
}
catch
{
}
mock.AssertWasCalled(x => x.GetTransaction(Arg<ITransactionDefinition>.Is.Anything), constraints => constraints.Repeat.Once());
mock.AssertWasCalled(x => x.Rollback(Arg<ITransactionStatus>.Is.Anything), constraints => constraints.Repeat.Once());
}
[Test]
public void ExecuteExceptionRollbackException()
{
IPlatformTransactionManager mock = MockRepository.GenerateMock<IPlatformTransactionManager>();
mock.Stub(x => x.Rollback(Arg<ITransactionStatus>.Is.Anything)).Throw(new Exception("Rollback"));
TransactionTemplate temp = new TransactionTemplate(mock);
try
{
temp.Execute(new TransactionDelegate(DummyExceptionMethod));
}
catch
{
}
mock.AssertWasCalled(x => x.GetTransaction(Arg<ITransactionDefinition>.Is.Anything), constraints => constraints.Repeat.Once());
mock.AssertWasCalled(x => x.Rollback(Arg<ITransactionStatus>.Is.Anything), constraints => constraints.Repeat.Once());
}
[Test]
public void NullResult()
{
IPlatformTransactionManager mock = MockRepository.GenerateMock<IPlatformTransactionManager>();
TransactionTemplate temp = new TransactionTemplate(mock);
temp.AfterPropertiesSet();
Assert.AreEqual(mock, temp.PlatformTransactionManager);
Assert.IsNull(temp.Execute(new TransactionDelegate(DummyTransactionMethod)));
mock.AssertWasCalled(x => x.GetTransaction(Arg<ITransactionDefinition>.Is.Anything), constraints => constraints.Repeat.Once());
mock.AssertWasCalled(x => x.Commit(Arg<ITransactionStatus>.Is.Anything), constraints => constraints.Repeat.Once());
}
public object DummyTransactionMethod(ITransactionStatus status)
{
return status;
}
public object DummyExceptionMethod(ITransactionStatus status)
{
throw new Exception("Bad Error");
}
}
}

View File

@@ -76,10 +76,6 @@
<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">
<Name>nunit.framework</Name>
<HintPath>..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>

View File

@@ -82,10 +82,6 @@
<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">
<Name>nunit.framework</Name>
<HintPath>..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>

View File

@@ -1,322 +0,0 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{F39DE556-EAFB-41A0-AB2F-F02F2E038E62}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Spring.Services.WindowsService.Tests"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = ""
PostBuildEvent = 'xcopy /I /E /Y "$(ProjectDir)Data" "$(TargetDir)Data"&#xd;&#xa;copy "$(ProjectDir)..\..\..\src\Spring\Spring.Services\WindowsService\Process\*.xml" "$(TargetDir)Data\Xml"'
RootNamespace = "Spring.Services"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "..\..\..\build\VS.Net\Spring.Services.Tests\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "..\..\..\build\VS.Net\Spring.Services.WindowsService.Tests\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath = "..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference
Name = "Spring.Services.WindowsService.Common"
Project = "{B8381347-51A1-4850-828C-3170FA93846C}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Spring.Core"
Project = "{710961A3-0DF4-49E4-A26E-F5B9C044AC84}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "DotNetMock"
AssemblyName = "DotNetMock"
HintPath = "..\..\..\lib\Net\1.1\DotNetMock.dll"
/>
<Reference
Name = "DotNetMock.Framework"
AssemblyName = "DotNetMock.Framework"
HintPath = "..\..\..\lib\Net\1.1\DotNetMock.Framework.dll"
/>
<Reference
Name = "log4net"
AssemblyName = "log4net"
HintPath = "..\..\..\lib\Net\1.1\log4net.dll"
/>
<Reference
Name = "nunit.framework"
AssemblyName = "nunit.framework"
HintPath = "..\..\..\lib\Net\1.1\nunit.framework.dll"
/>
<Reference
Name = "System.Windows.Forms"
AssemblyName = "System.Windows.Forms"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll"
/>
<Reference
Name = "NUnitForms"
AssemblyName = "NUnitForms"
HintPath = "..\..\..\lib\Net\1.1\NUnitForms.dll"
/>
<Reference
Name = "System.Drawing"
AssemblyName = "System.Drawing"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
/>
<Reference
Name = "AgileDocs.Core"
AssemblyName = "AgileDocs.Core"
HintPath = "..\..\..\doc\reference\src\templated\AgileDocs.Core.dll"
/>
<Reference
Name = "Spring.Threading"
Project = "{4640D873-95DC-4130-98E2-2B931D390C20}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "System.Web"
AssemblyName = "System.Web"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
/>
<Reference
Name = "System.Web.Services"
AssemblyName = "System.Web.Services"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.Services.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "tests.config"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "Data\Spring\WindowsService\Cassini\localizer.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\WindowsService\Cassini\service.config"
BuildAction = "None"
/>
<File
RelPath = "Data\Spring\WindowsService\Cassini\service.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\WindowsService\Cassini\watcher.xml"
BuildAction = "Content"
/>
<Folder RelPath = "Data\Spring\WindowsService\Cassini\wwwroot\" />
<File
RelPath = "Data\Spring\WindowsService\Echo\service.config"
BuildAction = "None"
/>
<File
RelPath = "Data\Spring\WindowsService\Echo\service.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\WindowsService\Echo\watcher.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\WindowsService\Simple\service.config"
BuildAction = "None"
/>
<File
RelPath = "Data\Spring\WindowsService\Simple\service.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Spring\WindowsService\Simple\watcher.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Xml\watcher-0.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Xml\watcher-1.xml"
BuildAction = "Content"
/>
<File
RelPath = "Data\Xml\watcher-simple.xml"
BuildAction = "Content"
/>
<File
RelPath = "WindowsService\IntegrationTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\TestUtils.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\ApplicationHostTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\ApplicationTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\LocalizerTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\ServiceSupportTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\UtilsTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\AggregatedDeployEventDispatcherTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\ApplicationWatcherManagerTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\DeployEventAggregatorTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\DeployManagerTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\NullSync.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\SpringAssembliesDeployerTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\TestingHandler.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\FileSystem\DefaultApplicationWatcherFactoryTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\FileSystem\FileSystemApplicationWatcherTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\FileSystem\FileSystemDeployLocationTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\FileSystem\FileSystemMonitorTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Deploy\FileSystem\RegularExpressionFilterConfigurerTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Common\Gui\ApplicationMonitorTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Samples\Echo\Echo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "WindowsService\Samples\Simple\Simple.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>