Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Data/Core
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv29774/Data/Core
Modified Files:
TxScopeTransactionManager.cs
Log Message:
SPRNET-761 - Add unit tests for TxScopePlatformTransactionManager
Introduce ITransactionScopeAdapter to make it testable with Mocks
added TypeMock based unit test that is not used but nice to have for future reference
Index: TxScopeTransactionManager.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Data/Data/Core/TxScopeTransactionManager.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TxScopeTransactionManager.cs 30 Nov 2007 07:55:29 -0000 1.3
--- TxScopeTransactionManager.cs 30 Nov 2007 18:38:46 -0000 1.4
***************
*** 4,8 ****
/*
! * Copyright 2004 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
--- 4,8 ----
/*
! * Copyright 2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
***************
*** 23,26 ****
--- 23,27 ----
using System;
using System.Transactions;
+ using Spring.Data.Support;
using Spring.Objects.Factory;
using Spring.Transaction;
***************
*** 36,42 ****
--- 37,65 ----
public class TxScopeTransactionManager : AbstractPlatformTransactionManager, IInitializingObject
{
+ private ITransactionScopeAdapter txAdapter;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TxScopeTransactionManager"/> class.
+ /// </summary>
+ public TxScopeTransactionManager()
+ {
+
+ }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TxScopeTransactionManager"/> class.
+ /// </summary>
+ /// <remarks>This is indented only for unit testing purposes and should not be
+ /// called by application code.</remarks>
+ /// <param name="txAdapter">The tx adapter.</param>
+ public TxScopeTransactionManager(ITransactionScopeAdapter txAdapter)
+ {
+ this.txAdapter = txAdapter;
+ }
#region IInitializingObject Members
+ /// <summary>
+ /// No-op initialization
+ /// </summary>
public void AfterPropertiesSet()
{
***************
*** 55,59 ****
PromotableTxScopeTransactionObject txObject =
(PromotableTxScopeTransactionObject)transaction;
! return txObject.IsExistingTransaction();
}
--- 78,82 ----
PromotableTxScopeTransactionObject txObject =
(PromotableTxScopeTransactionObject)transaction;
! return txObject.TxScopeAdapter.IsExistingTransaction;
}
***************
*** 74,81 ****
protected override object DoSuspend(object transaction)
{
! // Passing the current TransactionScope as the 'suspended resource, even though DoResume has no need to operate
// on this object as it is handled internally inside TransactionScope.
PromotableTxScopeTransactionObject txMgrStateObject = (PromotableTxScopeTransactionObject) transaction;
! return txMgrStateObject.TransactionScope;
}
--- 97,104 ----
protected override object DoSuspend(object transaction)
{
! // Passing the current TxScopeAdapter as the 'suspended resource, even though DoResume has no need to operate
// on this object as it is handled internally inside TransactionScope.
PromotableTxScopeTransactionObject txMgrStateObject = (PromotableTxScopeTransactionObject) transaction;
! return txMgrStateObject.TxScopeAdapter;
}
***************
*** 90,95 ****
try
{
! txObject.TransactionScope.Complete();
! txObject.TransactionScope.Dispose();
}
catch (TransactionAbortedException ex)
--- 113,118 ----
try
{
! txObject.TxScopeAdapter.Complete();
! txObject.TxScopeAdapter.Dispose();
}
catch (TransactionAbortedException ex)
***************
*** 114,118 ****
try
{
! txObject.TransactionScope.Dispose();
}
catch (Exception e)
--- 137,142 ----
try
{
!
! txObject.TxScopeAdapter.Dispose();
}
catch (Exception e)
***************
*** 138,142 ****
}
!
private void DoTxScopeBegin(PromotableTxScopeTransactionObject transaction,
--- 162,169 ----
}
! protected override bool ShouldCommitOnGlobalRollbackOnly
! {
! get { return true; }
! }
private void DoTxScopeBegin(PromotableTxScopeTransactionObject transaction,
***************
*** 146,151 ****
TransactionScopeOption txScopeOption = CreateTransactionScopeOptions(definition);
TransactionOptions txOptions = CreateTransactionOptions(definition);
! TransactionScope txScope = new TransactionScope(txScopeOption, txOptions, definition.EnterpriseServicesInteropOption);
! transaction.TransactionScope = txScope;
}
--- 173,189 ----
TransactionScopeOption txScopeOption = CreateTransactionScopeOptions(definition);
TransactionOptions txOptions = CreateTransactionOptions(definition);
!
! if (txAdapter != null)
! {
! txAdapter.CreateTransactionScope(txScopeOption, txOptions, definition.EnterpriseServicesInteropOption);
! transaction.TxScopeAdapter = txAdapter;
! }
! else
! {
! //TransactionScope txScope = new TransactionScope(txScopeOption, txOptions, definition.EnterpriseServicesInteropOption);
! //transaction.TxScopeAdapter.TransactionScope = txScope;
! transaction.TxScopeAdapter.CreateTransactionScope(txScopeOption, txOptions, definition.EnterpriseServicesInteropOption);
! }
!
}
***************
*** 205,250 ****
}
public class PromotableTxScopeTransactionObject : ISmartTransactionObject
{
! private TransactionScope txScope;
! public TransactionScope TransactionScope
{
! get {return txScope;}
! set {txScope = value;}
}
! public bool RollbackOnly
{
! get {
! if (System.Transactions.Transaction.Current != null &&
! System.Transactions.Transaction.Current.TransactionInformation != null &&
! System.Transactions.Transaction.Current.TransactionInformation.Status == TransactionStatus.Aborted)
! {
! return true;
! }
! else
! {
! return false;
! }
! }
}
/// <summary>
! /// Determines whether a current transaction exists.
/// </summary>
! /// <returns>
! /// <c>true</c> if a current transaction exists; otherwise, <c>false</c>.
! /// </returns>
! public bool IsExistingTransaction()
{
! if (System.Transactions.Transaction.Current != null)
! {
! return true;
! }
! else
! {
! return false;
! }
}
}
--- 243,285 ----
}
+ /// <summary>
+ /// The transaction resource object that encapsulates the state and functionality
+ /// contained in TransactionScope and Transaction.Current via the ITransactionScopeAdapter
+ /// property.
+ /// </summary>
public class PromotableTxScopeTransactionObject : ISmartTransactionObject
{
! private ITransactionScopeAdapter txScopeAdapter;
! /// <summary>
! /// Initializes a new instance of the <see cref="PromotableTxScopeTransactionObject"/> class.
! /// Will create an instance of <see cref="DefaultTransactionScopeAdapter"/>.
! /// </summary>
! public PromotableTxScopeTransactionObject()
{
! txScopeAdapter = new DefaultTransactionScopeAdapter();
}
! /// <summary>
! /// Gets or sets the transaction scope adapter.
! /// </summary>
! /// <value>The transaction scope adapter.</value>
! public ITransactionScopeAdapter TxScopeAdapter
{
! get { return txScopeAdapter; }
! set { txScopeAdapter = value; }
}
+
/// <summary>
! /// Return whether the transaction is internally marked as rollback-only.
/// </summary>
! /// <value></value>
! /// <returns>True of the transaction is marked as rollback-only.</returns>
! public bool RollbackOnly
{
! get {
! return txScopeAdapter.RollbackOnly;
! }
}
}
|