Beispiel #1
0
 public void CanExecuteNonQueryThroughTransaction()
 {
     using (DbConnection connection = db.CreateConnection())
     {
         connection.Open();
         using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
         {
             int rowsAffected = db.ExecuteNonQuery(insertionCommand, transaction.Transaction);
             int count        = Convert.ToInt32(db.ExecuteScalar(countCommand, transaction.Transaction));
             Assert.AreEqual(5, count);
             Assert.AreEqual(1, rowsAffected);
         }
     }
 }
        public void CanExecuteNonQueryThroughTransaction()
        {
            using (IDbConnection connection = this.db.GetConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    this.db.ExecuteNonQuery(this.insertionCommand, transaction.Transaction);

                    int count = Convert.ToInt32(this.db.ExecuteScalar(this.countCommand, transaction.Transaction));
                    Assert.AreEqual(5, count);
                    Assert.AreEqual(1, this.insertionCommand.RowsAffected);
                }
            }
        }
        public void CanExecuteQueryThroughDataReaderUsingTransaction()
        {
            using (DbConnection connection = this.db.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    IDataReader reader = this.db.ExecuteReader(this.insertCommand, transaction.Transaction);
                    Assert.AreEqual(1, reader.RecordsAffected);
                    reader.Close();
                }

                Assert.AreEqual(ConnectionState.Open, connection.State);
            }
        }
Beispiel #4
0
        public void TransactionActuallyRollsBack()
        {
            using (DbConnection connection = db.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    db.ExecuteNonQuery(insertionCommand, transaction.Transaction);
                }
            }
            DbCommand wrapper = db.GetSqlStringCommand(countQuery);
            int       count   = Convert.ToInt32(db.ExecuteScalar(wrapper));

            Assert.AreEqual(4, count);
        }
        public void CanExecuteNonQueryThroughTransaction()
        {
            using (DbConnection connection = db.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    int rowsAffected = this.db.ExecuteNonQuery(this.insertionCommand, transaction.Transaction);

                    int count = Convert.ToInt32(this.db.ExecuteScalar(this.countCommand, transaction.Transaction));
                    Assert.AreEqual(5, count);
                    Assert.AreEqual(1, rowsAffected);
                }
            }
        }
        public void CanExecuteQueryThroughDataReaderUsingTransaction()
        {
            using (IDbConnection connection = this.db.GetConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    IDataReader reader = this.db.ExecuteReader(this.insertCommand, transaction.Transaction);
                    Assert.AreEqual(1, reader.RecordsAffected);
                    reader.Close();
                }

                Assert.AreEqual(ConnectionState.Open, connection.State);
            }
        }
        public void CanExecuteXmlQueryThroughTransaction()
        {
            string knownGoodOutputAfterChange =
                "<Region RegionID=\"1\" RegionDescription=\"Eastern                                           \" />" +
                    "<Region RegionID=\"2\" RegionDescription=\"Western                                           \" />" +
                    "<Region RegionID=\"3\" RegionDescription=\"Northern                                          \" />" +
                    "<Region RegionID=\"4\" RegionDescription=\"Southern                                          \" />" +
                    "<Region RegionID=\"99\" RegionDescription=\"Midwest                                           \" />";

            string knownGoodOutputAfterRollback =
                "<Region RegionID=\"1\" RegionDescription=\"Eastern                                           \" />" +
                    "<Region RegionID=\"2\" RegionDescription=\"Western                                           \" />" +
                    "<Region RegionID=\"3\" RegionDescription=\"Northern                                          \" />" +
                    "<Region RegionID=\"4\" RegionDescription=\"Southern                                          \" />";

            string insertString = "insert into region values (99, 'Midwest')";
            DBCommandWrapper insertCommand = sqlDatabase.GetSqlStringCommandWrapper(insertString);

            string queryString = "Select * from Region for xml auto";
            SqlCommandWrapper sqlCommand = sqlDatabase.GetSqlStringCommandWrapper(queryString) as SqlCommandWrapper;

            string actualOutput = "";

            using (IDbConnection connection = sqlDatabase.GetConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    sqlDatabase.ExecuteNonQuery(insertCommand, transaction.Transaction);

                    XmlReader results = sqlDatabase.ExecuteXmlReader(sqlCommand, transaction.Transaction);
                    results.MoveToContent();
                    for (string value = results.ReadOuterXml(); value != null && value.Length != 0; value = results.ReadOuterXml())
                    {
                        actualOutput += value;
                    }
                    results.Close();
                }
            }

            Assert.AreEqual(actualOutput, knownGoodOutputAfterChange);

            string confirmationString = "Select * from Region for xml auto";
            SqlCommandWrapper confirmationCommand = sqlDatabase.GetSqlStringCommandWrapper(confirmationString) as SqlCommandWrapper;

            string rollbackResults = RetrieveXmlFromDatabase(confirmationCommand);
            Assert.AreEqual(knownGoodOutputAfterRollback, rollbackResults);
        }
        public void TransactionActuallyRollsBack()
        {
            using (IDbConnection connection = this.db.GetConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    this.db.ExecuteNonQuery(this.insertionCommand, transaction.Transaction);
                }
            }

            DBCommandWrapper wrapper = this.db.GetSqlStringCommandWrapper(this.countQuery);
            int count = Convert.ToInt32(this.db.ExecuteScalar(wrapper));

            Assert.AreEqual(4, count);
        }
        public void CanExecuteScalarDoAnInsertion()
        {
            string    insertCommand = "Insert into Region values (99, 'Midwest')";
            DbCommand command       = db.GetSqlStringCommand(insertCommand);

            using (DbConnection connection = db.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    db.ExecuteScalar(command, transaction.Transaction);
                    DbCommand rowCountCommand = db.GetSqlStringCommand("select count(*) from Region");
                    int       count           = Convert.ToInt32(db.ExecuteScalar(rowCountCommand, transaction.Transaction));
                    Assert.AreEqual(5, count);
                }
            }
        }
        public void CanExecuteScalarDoAnInsertion()
        {
            string insertCommand = "Insert into Region values (99, 'Midwest')";
            DbCommand command = this.db.GetSqlStringCommand(insertCommand);
			using (DbConnection connection = this.db.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    this.db.ExecuteScalar(command, transaction.Transaction);

                    DbCommand rowCountCommand = this.db.GetSqlStringCommand("select count(*) from Region");
                    int count = Convert.ToInt32(this.db.ExecuteScalar(rowCountCommand, transaction.Transaction));
                    Assert.AreEqual(5, count);
                }
            }
        }
        public void TransactionActuallyRollsBack()
        {
			using (DbConnection connection = this.db.CreateConnection())
            {
                connection.Open();
                using (RollbackTransactionWrapper transaction = new RollbackTransactionWrapper(connection.BeginTransaction()))
                {
                    this.db.ExecuteNonQuery(this.insertionCommand, transaction.Transaction);
                }
            }

            DbCommand wrapper = this.db.GetSqlStringCommand(this.countQuery);
            int count = Convert.ToInt32(this.db.ExecuteScalar(wrapper));
            Assert.AreEqual(4, count);
        }