<commit_before>using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Security.Principal;
using MbUnit.Framework;
using Microsoft.SqlServer.Management.Smo;
using Subtext.Framework;
using Subtext.Framework.Configuration;
using Subtext.Installation;
using Subtext.Scripting;
using UnitTests.Subtext;

[assembly: AssemblyCleanup(typeof(AssemblySetUpAndCleanUp))]
namespace UnitTests.Subtext
{
	public static class AssemblySetUpAndCleanUp
	{
		[SetUp]
		public static void SetUp()
		{
			Console.WriteLine("Assembly Setup beginning...");
			if (ConfigurationManager.AppSettings["connectionStringName"] == "subtextExpress")
			{
				//For use with SQL Express. If you use "subtextData", we assume you already have the database created.
				CreateAndInstallDatabase();
			}
			else
			{
				using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
				{
					connection.Open();
					using (SqlTransaction transaction = connection.BeginTransaction())
					{
						ScriptHelper.ExecuteScript("StoredProcedures.sql", transaction);
						transaction.Commit();
					}
				}
			}
		}

		[TearDown]
		public static void TearDown()
		{
			if (ConfigurationManager.AppSettings["connectionStringName"] == "subtextExpress")
			{
				try
				{
					DeleteDatabase(Config.ConnectionString.Server, "Subtext_Tests");
				}
				catch(Exception e)
				{
					Console.WriteLine("Exception occurred while deleting the database. We'll get it the next time around.");
					Console.WriteLine(e);

				}
			}
		}

		private static void CreateAndInstallDatabase()
		{
			ConnectionString connectionString = Config.ConnectionString;

			DeleteDatabase(connectionString.Server, "Subtext_Tests");
			CreateDatabase(connectionString.Server, "Subtext_Tests");

			//Test connection.
			using (SqlConnection connection = new SqlConnection(connectionString))
			{
				connection.Open();
				connection.Close();
			}

			SqlInstaller installer = new SqlInstaller(connectionString);
			installer.Install(VersionInfo.FrameworkVersion);
		}

		private static void DeleteDatabase(string serverName, string databaseName)
		{
			Console.WriteLine(@"Attempting to delete database '{0}\{1}", serverName, databaseName);
			DetachDatabase(serverName, databaseName);
			
			DeleteFile(Path.Combine(Path.GetFullPath(@"App_Data"), databaseName + ".mdf"));
			DeleteFile(Path.Combine(Path.GetFullPath(@"App_Data"), databaseName + ".ldf"));
		}

		private static void DeleteFile(string path)
		{<commit_msg>Adding a bit more console output.<commit_after>using System;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;
using System.Security.Principal;
using MbUnit.Framework;
using Microsoft.SqlServer.Management.Smo;
using Subtext.Framework;
using Subtext.Framework.Configuration;
using Subtext.Installation;
using Subtext.Scripting;
using UnitTests.Subtext;

[assembly: AssemblyCleanup(typeof(AssemblySetUpAndCleanUp))]
namespace UnitTests.Subtext
{
	public static class AssemblySetUpAndCleanUp
	{
		[SetUp]
		public static void SetUp()
		{
			Console.WriteLine("Assembly Setup beginning...");
			if (ConfigurationManager.AppSettings["connectionStringName"] == "subtextExpress")
			{
				//For use with SQL Express. If you use "subtextData", we assume you already have the database created.
				CreateAndInstallDatabase();
			}
			else
			{
				using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
				{
					connection.Open();
					using (SqlTransaction transaction = connection.BeginTransaction())
					{
						ScriptHelper.ExecuteScript("StoredProcedures.sql", transaction);
						transaction.Commit();
					}
				}
			}
		}

		[TearDown]
		public static void TearDown()
		{
			if (ConfigurationManager.AppSettings["connectionStringName"] == "subtextExpress")
			{
				try
				{
					DeleteDatabase(Config.ConnectionString.Server, "Subtext_Tests");
				}
				catch(Exception e)
				{
					Console.WriteLine("Exception occurred while deleting the database. We'll get it the next time around.");
					Console.WriteLine(e);

				}
			}
		}

		private static void CreateAndInstallDatabase()
		{
			ConnectionString connectionString = Config.ConnectionString;

			DeleteDatabase(connectionString.Server, "Subtext_Tests");
			Console.Write("Creating Database 'Subtext_Tests'");
			CreateDatabase(connectionString.Server, "Subtext_Tests");

			Console.Write("Installing Subtext onto Subtext_Tests");

			SqlInstaller installer = new SqlInstaller(connectionString);
			installer.Install(VersionInfo.FrameworkVersion);
		}

		private static void DeleteDatabase(string serverName, string databaseName)
		{
			Console.WriteLine(@"Attempting to delete database '{0}\{1}", serverName, databaseName);
			DetachDatabase(serverName, databaseName);
			
			DeleteFile(Path.Combine(Path.GetFullPath(@"App_Data"), databaseName + ".mdf"));
			DeleteFile(Path.Combine(Path.GetFullPath(@"App_Data"), databaseName + ".ldf"));
		}

		private static void DeleteFile(string path)
		{
{'fraction_non_alphanumeric': 0.10611188532749354, 'fraction_numerical': 0.0007963368504877563, 'mean_word_length': 4.5391400220507165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6539124', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1363, 'n_words': 311}