From 496beca8f286c918e59030aa252c00a8ee80607d Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 30 Jun 2014 14:02:43 +1000 Subject: [PATCH] This Can_Find_Targetted_Migrations test needed a valid database to pass. This update ensures that the database is created with the old version 4.8 db schema. --- .../TargetVersionSixthMigrationsTest.cs | 70 +++++++++++++++++-- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs b/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs index 8aad190fea..9a9b2922d4 100644 --- a/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs +++ b/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs @@ -1,7 +1,11 @@ using System; using System.Collections.Generic; +using System.Data.SqlServerCe; using System.Linq; +using System.Text.RegularExpressions; using NUnit.Framework; +using SQLCE4Umbraco; +using Umbraco.Core; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Migrations; @@ -13,13 +17,20 @@ using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; namespace Umbraco.Tests.Migrations { [TestFixture] - public class TargetVersionSixthMigrationsTest + public class TargetVersionSixthMigrationsTest : BaseDatabaseFactoryTest { + /// Regular expression that finds multiline block comments. + private static readonly Regex FindComments = new Regex(@"\/\*.*?\*\/", RegexOptions.Singleline | RegexOptions.Compiled); + [SetUp] - public void Initialize() + public override void Initialize() { TestHelper.SetupLog4NetForTests(); + TestHelper.InitializeContentDirectories(); + Path = TestHelper.CurrentAssemblyDirectory; + AppDomain.CurrentDomain.SetData("DataDirectory", Path); + MigrationResolver.Current = new MigrationResolver(() => new List { typeof (Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero.RemoveUmbracoAppConstraints), @@ -36,22 +47,39 @@ namespace Umbraco.Tests.Migrations typeof (UpdateCmsPropertyTypeGroupTable) }.OrderByDescending(x => x.Name)); - Resolution.Freeze(); + Resolution.Freeze(); SqlSyntaxContext.SqlSyntaxProvider = SqlCeSyntax.Provider; + + var engine = new SqlCeEngine("Datasource=|DataDirectory|UmbracoPetaPocoTests.sdf;Flush Interval=1;"); + engine.CreateDatabase(); } - + [Test] public void Can_Find_Targetted_Migrations() { + var db = GetConfiguredDatabase(); + + //Create db schema and data from old Total.sql file for Sql Ce + string statements = GetDatabaseSpecificSqlScript(); + // replace block comments by whitespace + statements = FindComments.Replace(statements, " "); + // execute all non-empty statements + foreach (string statement in statements.Split(";".ToCharArray())) + { + string rawStatement = statement.Replace("GO", "").Trim(); + if (rawStatement.Length > 0) + db.Execute(new Sql(rawStatement)); + } + var configuredVersion = new Version("4.8.0"); var targetVersion = new Version("6.0.0"); - var foundMigrations = MigrationResolver.Current.Migrations; + var foundMigrations = MigrationResolver.Current.Migrations; var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); var migrations = migrationRunner.OrderedUpgradeMigrations(foundMigrations).ToList(); - var context = new MigrationContext(DatabaseProviders.SqlServerCE, null); + var context = new MigrationContext(DatabaseProviders.SqlServerCE, db); foreach (MigrationBase migration in migrations) { migration.GetUpExpressions(context); @@ -66,9 +94,37 @@ namespace Umbraco.Tests.Migrations } [TearDown] - public void TearDown() + public override void TearDown() { + base.TearDown(); + + PluginManager.Current = null; + SqlSyntaxContext.SqlSyntaxProvider = null; MigrationResolver.Reset(); + + TestHelper.CleanContentDirectories(); + + Path = TestHelper.CurrentAssemblyDirectory; + AppDomain.CurrentDomain.SetData("DataDirectory", null); + + SqlCeContextGuardian.CloseBackgroundConnection(); } + + public string Path { get; set; } + + public UmbracoDatabase GetConfiguredDatabase() + { + return new UmbracoDatabase("Datasource=|DataDirectory|UmbracoPetaPocoTests.sdf;Flush Interval=1;", "System.Data.SqlServerCe.4.0"); + } + + public DatabaseProviders GetDatabaseProvider() + { + return DatabaseProviders.SqlServerCE; + } + + public string GetDatabaseSpecificSqlScript() + { + return SqlScripts.SqlResources.SqlCeTotal_480; + } } } \ No newline at end of file