Permalink
Browse files

Transaction IsolationLevel is now passed to underlying adapter

fixes #213
  • Loading branch information...
1 parent 5815811 commit b227feec9e4d2c0f74a154b052323c15abc247a5 Maciej Aniserowicz committed Jul 16, 2012
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using NUnit.Framework;
+
+namespace Simple.Data.UnitTest
+{
+ [TestFixture]
+ class BeginTransactionWithIsolataionLevelTest
+ {
+ [Test]
+ public void TransactionsGetUnspecifiedIsolationLevelByDefault()
+ {
+ var adapter = new StubAdapterWithTransaction();
+ Database db = new Database(adapter);
+ db.BeginTransaction();
+
+ Assert.AreEqual(IsolationLevel.Unspecified, adapter.IsolationLevel);
+ }
+
+ [Test]
+ public void TransactionsGetExplicitlySetIsolationLevel()
+ {
+ var adapter = new StubAdapterWithTransaction();
+ Database db = new Database(adapter);
+ db.BeginTransaction(IsolationLevel.Serializable);
+
+ Assert.AreEqual(IsolationLevel.Serializable, adapter.IsolationLevel);
+ }
+
+ [Test]
+ public void NamedTransactionsGetUnspecifiedIsolationLevel()
+ {
+ var adapter = new StubAdapterWithTransaction();
+ Database db = new Database(adapter);
+ db.BeginTransaction("tran name");
+
+ Assert.AreEqual(IsolationLevel.Unspecified, adapter.IsolationLevel);
+ }
+ }
+
+ class StubAdapterWithTransaction : StubAdapter, IAdapterWithTransactions
+ {
+ public string TransactionName;
+ public IsolationLevel IsolationLevel;
+
+ public IAdapterTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
+ {
+ this.IsolationLevel = isolationLevel;
+ return null;
+ }
+
+ public IAdapterTransaction BeginTransaction(string name, IsolationLevel isolationLevel = IsolationLevel.Unspecified)
+ {
+ this.IsolationLevel = isolationLevel;
+ this.TransactionName = name;
+ return null;
+ }
+
+ #region IAdapterWithTransactions - not implementead
+
+ public IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria, IAdapterTransaction transaction)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IDictionary<string, object> Insert(string tableName, IDictionary<string, object> data, IAdapterTransaction transaction, bool resultRequired)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable<IDictionary<string, object>> InsertMany(string tableName, IEnumerable<IDictionary<string, object>> data, IAdapterTransaction transaction, Func<IDictionary<string, object>, Exception, bool> onError, bool resultRequired)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int Update(string tableName, IDictionary<string, object> data, SimpleExpression criteria, IAdapterTransaction transaction)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int Delete(string tableName, SimpleExpression criteria, IAdapterTransaction transaction)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int UpdateMany(string tableName, IEnumerable<IDictionary<string, object>> dataList, IAdapterTransaction adapterTransaction)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int UpdateMany(string tableName, IEnumerable<IDictionary<string, object>> dataList, IAdapterTransaction adapterTransaction, IList<string> keyFields)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int UpdateMany(string tableName, IList<IDictionary<string, object>> dataList, IEnumerable<string> criteriaFieldNames, IAdapterTransaction adapterTransaction)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IDictionary<string, object> Get(string tableName, IAdapterTransaction transaction, params object[] parameterValues)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IEnumerable<IDictionary<string, object>> RunQuery(SimpleQuery query, IAdapterTransaction transaction, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
+ {
+ throw new NotImplementedException();
+ }
+
+ #endregion
+ }
+
+}
@@ -70,6 +70,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AdapterFactoryTest.cs" />
+ <Compile Include="BeginTransactionWithIsolataionLevelTest.cs" />
<Compile Include="BinderHelperTest.cs" />
<Compile Include="ComposerTest.cs" />
<Compile Include="ConcreteCollectionTypeCreatorTest.cs" />
@@ -39,13 +39,13 @@ private SimpleTransaction(SimpleTransaction copy) : base(copy)
private void Begin()
{
- _adapterTransaction = _adapter.BeginTransaction();
+ _adapterTransaction = _adapter.BeginTransaction(_isolationLevel);
_transactionRunner = new TransactionRunner(_adapter, _adapterTransaction);
}
private void Begin(string name)
{
- _adapterTransaction = _adapter.BeginTransaction(name);
+ _adapterTransaction = _adapter.BeginTransaction(name, _isolationLevel);
_transactionRunner = new TransactionRunner(_adapter, _adapterTransaction);
}

0 comments on commit b227fee

Please sign in to comment.