Exemplo n.º 1
0
        /// <summary>
        /// Run a test and clean up the databases when complete.
        /// </summary>
        /// <param name="connectionString">The connection string for the database.</param>
        /// <param name="action">The test to run.</param>
        internal static void TestWithRollback(string connectionString, Action <RecordingDbConnection> action)
        {
            // make sure the database exists
            if (!SchemaInstaller.DatabaseExists(connectionString))
            {
                SchemaInstaller.CreateDatabase(connectionString);
            }

            // do all of the work in a transaction so we can clean up our changes
            using (TransactionScope transaction = new TransactionScope())
                using (SqlConnection connection = new SqlConnection(connectionString))
                    using (RecordingDbConnection recordingConnection = new RecordingDbConnection(connection))
                    {
                        recordingConnection.Open();
                        try
                        {
                            action(recordingConnection);
                        }
                        finally
                        {
                            Console.WriteLine("== BEGIN SCRIPT ============================");
                            Console.WriteLine(recordingConnection.ScriptLog.ToString());
                            Console.WriteLine("== END SCRIPT ============================");
                        }
                    }
        }
		/// <summary>
		/// Run a test and clean up the databases when complete.
		/// </summary>
		/// <param name="connectionString">The connection string for the database.</param>
		/// <param name="action">The test to run.</param>
		internal static void TestWithRollback(string connectionString, Action<RecordingDbConnection> action)
		{
			// make sure the database exists
			if (!SchemaInstaller.DatabaseExists(connectionString))
				SchemaInstaller.CreateDatabase(connectionString);

			// do all of the work in a transaction so we can clean up our changes
			using (TransactionScope transaction = new TransactionScope())
			using (SqlConnection connection = new SqlConnection(connectionString))
			using (RecordingDbConnection recordingConnection = new RecordingDbConnection(connection))
			{
				recordingConnection.Open();
				try
				{
					action(recordingConnection);
				}
				finally
				{
					Console.WriteLine("== BEGIN SCRIPT ============================");
					Console.WriteLine(recordingConnection.ScriptLog.ToString());
					Console.WriteLine("== END SCRIPT ============================");
				}
			}
		}