public virtual void BeginTransaction() { using (HsqlConnection testSubject = new HsqlConnection()) { testSubject.Open(); using (HsqlTransaction transaction = testSubject.BeginTransaction()) { } } object[] expected = new object[] { IsolationLevel.Chaos, false, IsolationLevel.ReadCommitted, true, IsolationLevel.ReadUncommitted, true, IsolationLevel.RepeatableRead, true, IsolationLevel.Serializable, true, IsolationLevel.Snapshot, true, IsolationLevel.Unspecified, true }; IsolationLevel isolationLevel; bool isolationLevelIsSupported; for (int i = 0; i < expected.Length; i += 2) { isolationLevel = (IsolationLevel)expected[i]; isolationLevelIsSupported = (bool) expected[i+1]; TestBeginTransaction(isolationLevel, isolationLevelIsSupported); } }
void TestBeginTransaction(IsolationLevel isolationLevel, bool isolationLevelIsSupported) { try { using (HsqlConnection testSubject = new HsqlConnection()) { testSubject.Open(); using (HsqlTransaction transaction = testSubject.BeginTransaction(isolationLevel)) { } } Assert.That(isolationLevelIsSupported, "System.Data.IsolationLevel: " + Enum.GetName(typeof(IsolationLevel), isolationLevel)); } catch (Exception) { Assert.That(!isolationLevelIsSupported, "System.Data.IsolationLevel: " + Enum.GetName(typeof(IsolationLevel), isolationLevel)); } }
public virtual void EnlistTransaction() { HsqlConnection testSubject = new HsqlConnection(); using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required)) { testSubject.Open(); testSubject.EnlistTransaction(Transaction.Current); try { testSubject.BeginTransaction(); Assert.Fail("The test subject allowed a local transaction to be started " + "explicitly while participating in a system transaction"); } catch (Exception) { } transactionScope.Complete(); try { testSubject.BeginTransaction(); Assert.Fail("The test subject allowed a local transaction to be started " + "explicitly while participating in a system transaction"); } catch (Exception) { } } using (HsqlTransaction transaction = testSubject.BeginTransaction()) { transaction.Commit(); } }