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.

This commit is contained in:
Shannon
2014-06-30 14:02:43 +10:00
parent 45e6127d00
commit 496beca8f2

View File

@@ -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
{
/// <summary>Regular expression that finds multiline block comments.</summary>
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<Type>
{
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;
}
}
}