diff --git a/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2008.csproj b/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2008.csproj index ae7c5001..bd154402 100644 --- a/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2008.csproj +++ b/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2008.csproj @@ -76,10 +76,6 @@ prompt - - False - ..\..\..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2010.csproj b/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2010.csproj index a9a81aae..e29a6f8d 100644 --- a/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2010.csproj +++ b/examples/Spring/SpringAir/test/SpringAir.Core.Tests/SpringAir.Core.Tests.2010.csproj @@ -93,10 +93,6 @@ prompt - - False - ..\..\..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2008.csproj b/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2008.csproj index 3122dff8..8f4842c2 100644 --- a/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2008.csproj +++ b/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2008.csproj @@ -76,10 +76,6 @@ prompt - - False - ..\..\..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2010.csproj b/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2010.csproj index bf2993d0..3dd51c0f 100644 --- a/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2010.csproj +++ b/examples/Spring/SpringAir/test/SpringAir.Data.Ado.Tests/SpringAir.Data.Ado.Tests.2010.csproj @@ -93,10 +93,6 @@ prompt - - False - ..\..\..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/lib/Net/2.0/DotNetMock.Framework.dll b/lib/Net/2.0/DotNetMock.Framework.dll deleted file mode 100644 index 7831d4eb..00000000 Binary files a/lib/Net/2.0/DotNetMock.Framework.dll and /dev/null differ diff --git a/lib/Net/2.0/DotNetMock.dll b/lib/Net/2.0/DotNetMock.dll deleted file mode 100644 index 4ebee5cc..00000000 Binary files a/lib/Net/2.0/DotNetMock.dll and /dev/null differ diff --git a/test/Spring/Spring.Aop.Tests/Aop/Framework/ProxyFactoryTests.cs b/test/Spring/Spring.Aop.Tests/Aop/Framework/ProxyFactoryTests.cs index 60fdf2f5..e4333a08 100644 --- a/test/Spring/Spring.Aop.Tests/Aop/Framework/ProxyFactoryTests.cs +++ b/test/Spring/Spring.Aop.Tests/Aop/Framework/ProxyFactoryTests.cs @@ -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(); 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.Is.NotNull)); + listener.AssertWasCalled(x => x.AdviceChanged(Arg.Is.NotNull)); + listener.AssertWasCalled(x => x.InterfacesChanged(Arg.Is.NotNull)); } [Test] public void AdvisedSupportListenerMethodsAre_NOT_CalledIfProxyHasNotBeenCreated() { - IDynamicMock mock = new DynamicMock(typeof(IAdvisedSupportListener)); - IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object; + IAdvisedSupportListener listener = MockRepository.GenerateMock(); 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.Is.Anything)); + listener.AssertWasNotCalled(x => x.InterfacesChanged(Arg.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(); 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.Is.Anything)); + listener.AssertWasNotCalled(x => x.AdviceChanged(Arg.Is.Anything)); + listener.AssertWasNotCalled(x => x.InterfacesChanged(Arg.Is.Anything)); } [Test] diff --git a/test/Spring/Spring.Aop.Tests/Aop/Support/DelegatingIntroductionInterceptorTests.cs b/test/Spring/Spring.Aop.Tests/Aop/Support/DelegatingIntroductionInterceptorTests.cs index 902e2f19..6ab64f30 100644 --- a/test/Spring/Spring.Aop.Tests/Aop/Support/DelegatingIntroductionInterceptorTests.cs +++ b/test/Spring/Spring.Aop.Tests/Aop/Support/DelegatingIntroductionInterceptorTests.cs @@ -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(); + 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(); + 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(); + 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(); } /// @@ -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 diff --git a/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2008.csproj b/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2008.csproj index ed3834e9..afe208b0 100644 --- a/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2008.csproj +++ b/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2008.csproj @@ -75,10 +75,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2010.csproj b/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2010.csproj index 1b08c1c1..7d895ddd 100644 --- a/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2010.csproj +++ b/test/Spring/Spring.Aop.Tests/Spring.Aop.Tests.2010.csproj @@ -81,10 +81,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2010.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2010.csproj index d9da4153..bb7ff0a9 100644 --- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2010.csproj +++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2010.csproj @@ -81,10 +81,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2008.csproj b/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2008.csproj index e7fb4673..ae2ca028 100644 --- a/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2008.csproj +++ b/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2008.csproj @@ -74,10 +74,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2010.csproj b/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2010.csproj index 812a76bc..a209d791 100644 --- a/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2010.csproj +++ b/test/Spring/Spring.Data.Integration.Tests/Spring.Data.Integration.Tests.2010.csproj @@ -80,10 +80,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj index ac9c1a33..a9ca8521 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj @@ -36,10 +36,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2010.csproj b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2010.csproj index e509472d..a1faf85f 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2010.csproj +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2010.csproj @@ -44,10 +44,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll diff --git a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj index 7f2d3d81..7a7f896f 100644 --- a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj +++ b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj @@ -73,10 +73,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2010.csproj b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2010.csproj index 9996705e..a8124a9b 100644 --- a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2010.csproj +++ b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2010.csproj @@ -79,10 +79,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Data.Tests/Transaction/CommonTypes.cs b/test/Spring/Spring.Data.Tests/Transaction/CommonTypes.cs index 3de383cd..bc91fd63 100644 --- a/test/Spring/Spring.Data.Tests/Transaction/CommonTypes.cs +++ b/test/Spring/Spring.Data.Tests/Transaction/CommonTypes.cs @@ -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 + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Data.Tests/Transaction/Support/AbstractPlatformTransactionManagerTests.cs b/test/Spring/Spring.Data.Tests/Transaction/Support/AbstractPlatformTransactionManagerTests.cs index d04e30fb..22ca726f 100644 --- a/test/Spring/Spring.Data.Tests/Transaction/Support/AbstractPlatformTransactionManagerTests.cs +++ b/test/Spring/Spring.Data.Tests/Transaction/Support/AbstractPlatformTransactionManagerTests.cs @@ -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(); + _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); } - } -} +} \ No newline at end of file diff --git a/test/Spring/Spring.Data.Tests/Transaction/Support/DefaultTransactionStatusTests.cs b/test/Spring/Spring.Data.Tests/Transaction/Support/DefaultTransactionStatusTests.cs index de37d6ec..a43761d5 100644 --- a/test/Spring/Spring.Data.Tests/Transaction/Support/DefaultTransactionStatusTests.cs +++ b/test/Spring/Spring.Data.Tests/Transaction/Support/DefaultTransactionStatusTests.cs @@ -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(); - 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(); + 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(); + 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(); + DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object()); + stat.ReleaseSavepoint(null); + } + + [Test] + public void CreateSaveAndHoldValidSavepoint() + { + ISavepointManager saveMgr = MockRepository.GenerateMock(); + 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(); + DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object()); + stat.RollbackToHeldSavepoint(); + } + + [Test] + public void RollbackHeldSavepointSuccess() + { + ISavepointManager saveMgr = MockRepository.GenerateMock(); + 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(); + DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object()); + stat.ReleaseHeldSavepoint(); + } + + [Test] + public void ReleaseHeldSavepointSuccess() + { + ISavepointManager saveMgr = MockRepository.GenerateMock(); + 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)); + } + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionSynchronizationManagerTests.cs b/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionSynchronizationManagerTests.cs index cb2bc502..c4a5fe02 100644 --- a/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionSynchronizationManagerTests.cs +++ b/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionSynchronizationManagerTests.cs @@ -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()); } [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()); syncs = TransactionSynchronizationManager.Synchronizations; Assert.AreEqual( 1, syncs.Count ); TransactionSynchronizationManager.ClearSynchronization(); diff --git a/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionTemplateTests.cs b/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionTemplateTests.cs index c9f2e536..4502f2bf 100644 --- a/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionTemplateTests.cs +++ b/test/Spring/Spring.Data.Tests/Transaction/Support/TransactionTemplateTests.cs @@ -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(); + temp.AfterPropertiesSet(); + } + + [Test] + public void ExecuteException() + { + IPlatformTransactionManager mock = MockRepository.GenerateMock(); + + TransactionTemplate temp = new TransactionTemplate(mock); + try + { + temp.Execute(new TransactionDelegate(DummyExceptionMethod)); + } + catch + { + } + + mock.AssertWasCalled(x => x.GetTransaction(Arg.Is.Anything), constraints => constraints.Repeat.Once()); + mock.AssertWasCalled(x => x.Rollback(Arg.Is.Anything), constraints => constraints.Repeat.Once()); + } + + [Test] + public void ExecuteExceptionRollbackException() + { + IPlatformTransactionManager mock = MockRepository.GenerateMock(); + mock.Stub(x => x.Rollback(Arg.Is.Anything)).Throw(new Exception("Rollback")); + + TransactionTemplate temp = new TransactionTemplate(mock); + try + { + temp.Execute(new TransactionDelegate(DummyExceptionMethod)); + } + catch + { + } + + mock.AssertWasCalled(x => x.GetTransaction(Arg.Is.Anything), constraints => constraints.Repeat.Once()); + mock.AssertWasCalled(x => x.Rollback(Arg.Is.Anything), constraints => constraints.Repeat.Once()); + } + + [Test] + public void NullResult() + { + IPlatformTransactionManager mock = MockRepository.GenerateMock(); + + 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.Is.Anything), constraints => constraints.Repeat.Once()); + mock.AssertWasCalled(x => x.Commit(Arg.Is.Anything), constraints => constraints.Repeat.Once()); + } + + public object DummyTransactionMethod(ITransactionStatus status) + { + return status; + } + + public object DummyExceptionMethod(ITransactionStatus status) + { + throw new Exception("Bad Error"); + } + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj index 91125c39..bf07699d 100644 --- a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj +++ b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2008.csproj @@ -76,10 +76,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - nunit.framework ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2010.csproj b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2010.csproj index 8cb5e79b..6a64f236 100644 --- a/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2010.csproj +++ b/test/Spring/Spring.Services.Tests/Spring.Services.Tests.2010.csproj @@ -82,10 +82,6 @@ False ..\..\..\lib\Net\2.0\Common.Logging.dll - - False - ..\..\..\lib\Net\2.0\DotNetMock.dll - nunit.framework ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Services.Tests/Spring.Services.WindowsService.Tests.csproj b/test/Spring/Spring.Services.Tests/Spring.Services.WindowsService.Tests.csproj deleted file mode 100644 index 844d3e58..00000000 --- a/test/Spring/Spring.Services.Tests/Spring.Services.WindowsService.Tests.csproj +++ /dev/null @@ -1,322 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -