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); } }
public virtual void ChangeDatabase() { using (HsqlConnection testSubject = new HsqlConnection("DataSource=mem:test2")) { string databaseName = "test1"; testSubject.ChangeDatabase(databaseName); testSubject.Open(); } using (HsqlConnection testSubject = new HsqlConnection("DataSource=mem:test2")) { testSubject.Open(); string databaseName = "test1"; try { testSubject.ChangeDatabase(databaseName); Assert.Fail("it is not expected that it is legal to change database while a connection is open."); } catch (Exception) { } } }
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 Open() { using (HsqlConnection testSubject = new HsqlConnection()) { testSubject.Open(); try { testSubject.Open(); Assert.Fail("A second Open() invocation should not succeed when a connection is already open."); } catch (Exception) { } } }
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(); } }
public virtual void Close() { using (HsqlConnection testSubject = new HsqlConnection()) { Assert.That(testSubject.State == ConnectionState.Closed); testSubject.Open(); Assert.That(testSubject.State == ConnectionState.Open); testSubject.Close(); Assert.That(testSubject.State == ConnectionState.Closed); testSubject.Close(); Assert.That(testSubject.State == ConnectionState.Closed); } }
/// <summary> /// Returns the collection of currently valid initial schema names, /// given the specified context. /// </summary> /// <param name="context"> /// An <see cref="ITypeDescriptorContext"></see> whose <c>Instance</c> /// property supplies the <c>HsqlConnectionStringBuilder</c> use to /// connect to a data source to retrieve the currently valid initial /// schema names. /// </param> /// <returns> /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds /// collection of currently valid initial schema names. /// </returns> public override TypeConverter.StandardValuesCollection GetStandardValues( ITypeDescriptorContext context) { if (!IsStandardValuesSupported(context)) { return null; } List<string> values = new List<string>(); try { HsqlConnectionStringBuilder builder = (HsqlConnectionStringBuilder)context.Instance; // TODO: this is sub-optimal, but is currently the best (only?) // solution to the problem of how to avoid creating and/or // leaving open embedded database instances. if (IsEmbeddedProtocol(builder)) { builder = new HsqlConnectionStringBuilder( builder.ConnectionString); builder.AutoShutdown = true; builder.IfExists = true; } using (HsqlConnection connection = new HsqlConnection()) { connection.ConnectionString = builder.ConnectionString; using (HsqlCommand command = new HsqlCommand( connection, SchemaQuery)) { connection.Open(); using (HsqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { values.Add(reader.GetString(0)); } } } } } catch (Exception exception) { #if DEBUG Debug.WriteLine(exception); #endif } return new TypeConverter.StandardValuesCollection(values); }