Exemple #1
0
        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);
            }
        }
Exemple #2
0
        public virtual void Transaction()
        {
            using (HsqlConnection connection = NewConnection())
                using (HsqlCommand testSubject = connection.CreateCommand())
                {
                    testSubject.CommandText = "update foo set bar = baz";
                    testSubject.Connection.BeginTransaction(IsolationLevel.ReadUncommitted);
                    HsqlTransaction transaction = testSubject.Transaction;

                    IsolationLevel expected = IsolationLevel.ReadUncommitted;
                    IsolationLevel actual   = transaction.IsolationLevel;

                    Assert.AreEqual(expected, actual);

                    //
                    Assert.Fail("TODO");
                }
        }
Exemple #3
0
        public void Clone()
        {
            using (HsqlConnection connection = NewConnection())
                using (HsqlTransaction transaction = connection.BeginTransaction())
                    using (HsqlCommand originalCommand = connection.CreateCommand())
                    {
                        originalCommand.CommandType = global::System.Data.CommandType.StoredProcedure;
                        originalCommand.CommandText = "call 1 + cast(? as integer)";
                        originalCommand.DeriveParameters();

                        HsqlCommand clonedCommand = originalCommand.Clone();

                        Assert.AreEqual(originalCommand.CommandText, clonedCommand.CommandText);
                        Assert.AreEqual(originalCommand.CommandTimeout, clonedCommand.CommandTimeout);
                        Assert.AreEqual(originalCommand.CommandType, clonedCommand.CommandType);
                        Assert.AreSame(connection, clonedCommand.Connection);
                        Assert.AreEqual(originalCommand.DesignTimeVisible, clonedCommand.DesignTimeVisible);
                        Assert.AreEqual(originalCommand.Parameters.Count, clonedCommand.Parameters.Count);

                        for (int i = 0; i < originalCommand.Parameters.Count; i++)
                        {
                            HsqlParameter orignalCommandParameter = originalCommand.Parameters[i];
                            HsqlParameter clonedCommandParameter  = clonedCommand.Parameters[i];

                            Assert.AreEqual(orignalCommandParameter.DbType, clonedCommandParameter.DbType);
                            Assert.AreEqual(orignalCommandParameter.Direction, clonedCommandParameter.Direction);
                            Assert.AreEqual(orignalCommandParameter.IsNullable, clonedCommandParameter.IsNullable);
                            Assert.AreEqual(orignalCommandParameter.Offset, clonedCommandParameter.Offset);
                            Assert.AreEqual(orignalCommandParameter.ParameterName, clonedCommandParameter.ParameterName);
                            Assert.AreEqual(orignalCommandParameter.Precision, clonedCommandParameter.Precision);
                            Assert.AreEqual(orignalCommandParameter.ProviderType, clonedCommandParameter.ProviderType);
                            Assert.AreEqual(orignalCommandParameter.Scale, clonedCommandParameter.Scale);
                            Assert.AreEqual(orignalCommandParameter.Size, clonedCommandParameter.Size);
                            Assert.AreEqual(orignalCommandParameter.SourceColumn, clonedCommandParameter.SourceColumn);
                            Assert.AreEqual(orignalCommandParameter.SourceColumnNullMapping, clonedCommandParameter.SourceColumnNullMapping);
                            Assert.AreEqual(orignalCommandParameter.SourceVersion, clonedCommandParameter.SourceVersion);
                            Assert.AreEqual(orignalCommandParameter.ToSqlLiteral(), clonedCommandParameter.ToSqlLiteral());
                            Assert.AreEqual(orignalCommandParameter.Value, clonedCommandParameter.Value);
                        }

                        Assert.AreSame(originalCommand.Transaction, clonedCommand.Transaction);
                        Assert.AreEqual(originalCommand.UpdatedRowSource, clonedCommand.UpdatedRowSource);
                    }
        }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
        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));
            }
        }
Exemple #6
0
 /// <summary>
 /// Notifies the transaction participant that the enlistment has completed successfully.
 /// </summary>
 /// <exception cref="TransactionException">
 /// When an attempt to enlist or serialize the transaction fails.
 /// </exception>
 void IPromotableSinglePhaseNotification.Initialize()
 {
     m_dbTransaction = m_dbConnection.BeginTransaction(
         HsqlConvert.ToIsolationLevel(m_systemTransaction.IsolationLevel));
 }
 /// <summary>
 /// Notifies the transaction participant that the enlistment has completed successfully.
 /// </summary>
 /// <exception cref="TransactionException">
 /// When an attempt to enlist or serialize the transaction fails.
 /// </exception>
 void IPromotableSinglePhaseNotification.Initialize()
 {
     m_dbTransaction = m_dbConnection.BeginTransaction(
         HsqlConvert.ToIsolationLevel(m_systemTransaction.IsolationLevel));
 }