Removed PluginManagerExtensions for finding IMigrations since we are manually initializing the resolver instead of type finding. Updated

unit tests to use resolvers and are passing.
This commit is contained in:
Shannon Deminick
2013-01-10 04:49:12 +03:00
parent 4532c1b5b9
commit b8f455e50b
6 changed files with 38 additions and 78 deletions

View File

@@ -1,13 +0,0 @@
using System.Collections.Generic;
namespace Umbraco.Core.Persistence.Migrations
{
internal static class PluginManagerExtension
{
public static IEnumerable<IMigration> FindMigrations(this PluginManager resolver)
{
var types = resolver.ResolveTypesWithAttribute<IMigration, MigrationAttribute>();
return resolver.CreateInstances<IMigration>(types);
}
}
}

View File

@@ -267,7 +267,6 @@
<Compile Include="Persistence\Migrations\MigrationExpressionBase.cs" />
<Compile Include="Persistence\Migrations\MigrationResolver.cs" />
<Compile Include="Persistence\Migrations\MigrationRunner.cs" />
<Compile Include="Persistence\Migrations\PluginManagerExtension.cs" />
<Compile Include="Persistence\Migrations\Syntax\Alter\AlterSyntaxBuilder.cs" />
<Compile Include="Persistence\Migrations\Syntax\Alter\Column\AlterColumnBuilder.cs" />
<Compile Include="Persistence\Migrations\Syntax\Alter\Column\IAlterColumnOptionForeignKeyCascadeSyntax.cs" />

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.ObjectResolution;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -19,31 +20,25 @@ namespace Umbraco.Tests.Migrations
{
TestHelper.SetupLog4NetForTests();
//this ensures its reset
PluginManager.Current = new PluginManager(false);
MigrationResolver.Current = new MigrationResolver(new List<Type>
{
typeof (AlterUserTableMigrationStub),
typeof(Dummy),
typeof (FourNineMigration),
typeof (FourTenMigration),
typeof (FourElevenMigration),
typeof (FourElevenMigration)
});
//for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
PluginManager.Current.AssembliesToScan = new[]
{
typeof (FourNineMigration).Assembly
};
Resolution.Freeze();
SyntaxConfig.SqlSyntaxProvider = SqlCeSyntax.Provider;
}
[Test]
public void Can_Find_Migrations_In_Current_Assembly()
{
var foundTypes = PluginManager.Current.ResolveMigrationTypes();
Assert.That(foundTypes.Any(), Is.True);
Assert.That(foundTypes.Count(), Is.EqualTo(4));
}
}
[Test]
public void Can_Find_Migrations_With_Targtet_Version_Six()
{
var foundMigrations = PluginManager.Current.FindMigrations();
var foundMigrations = MigrationResolver.Current.Migrations;
var targetVersion = new Version("6.0.0");
var list = new List<IMigration>();
@@ -78,8 +73,9 @@ namespace Umbraco.Tests.Migrations
[TearDown]
public void TearDown()
{
PluginManager.Current = null;
{
MigrationResolver.Reset();
Resolution.IsFrozen = false;
}
}
}

View File

@@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Persistence.Migrations;
namespace Umbraco.Tests.Migrations
{
/// <summary>
/// Used for TypeInheritanceTest and CodeFirstTests
/// </summary>
internal static class PluginManagerExtensions
{
public static IEnumerable<Type> ResolveMigrationTypes(this PluginManager resolver)
{
return resolver.ResolveTypesWithAttribute<IMigration, MigrationAttribute>();
}
public static IEnumerable<IMigration> FindMigrations(this PluginManager resolver)
{
var types = resolver.ResolveTypesWithAttribute<IMigration, MigrationAttribute>();
return resolver.CreateInstances<IMigration>(types);
}
}
}

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.ObjectResolution;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
@@ -18,33 +20,33 @@ namespace Umbraco.Tests.Migrations
{
TestHelper.SetupLog4NetForTests();
//this ensures its reset
PluginManager.Current = new PluginManager(false);
MigrationResolver.Current = new MigrationResolver(new List<Type>
{
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero.RemoveUmbracoAppConstraints),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.DeleteAppTables),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.EnsureAppsTreesUpdated),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.MoveMasterContentTypeData),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.NewCmsContentType2ContentTypeTable),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.RemoveMasterContentTypeColumn),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.RenameCmsTabTable),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.RenameTabIdColumn),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.UpdateCmsContentTypeAllowedContentTypeTable),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.UpdateCmsContentTypeTable),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.UpdateCmsContentVersionTable),
typeof (Core.Persistence.Migrations.Upgrades.TargetVersionSixth.UpdateCmsPropertyTypeGroupTable)
});
//for testing, we'll specify which assemblies are scanned for the PluginTypeResolver
PluginManager.Current.AssembliesToScan = new[]
{
typeof (MigrationRunner).Assembly
};
Resolution.Freeze();
SyntaxConfig.SqlSyntaxProvider = SqlCeSyntax.Provider;
}
[Test]
public void Can_Find_Migrations_In_Current_Assembly()
{
var foundTypes = PluginManager.Current.ResolveMigrationTypes();
Assert.That(foundTypes.Any(), Is.True);
Assert.That(foundTypes.Count(), Is.GreaterThanOrEqualTo(11));
}
[Test]
public void Can_Find_Targetted_Migrations()
{
var configuredVersion = new Version("4.11.0");
var targetVersion = new Version("6.0.0");
var foundMigrations = PluginManager.Current.FindMigrations();
var foundMigrations = MigrationResolver.Current.Migrations;
var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
var migrations = migrationRunner.OrderedUpgradeMigrations(foundMigrations);
@@ -66,7 +68,8 @@ namespace Umbraco.Tests.Migrations
[TearDown]
public void TearDown()
{
PluginManager.Current = null;
MigrationResolver.Reset();
Resolution.IsFrozen = false;
}
}
}

View File

@@ -168,7 +168,6 @@
<DependentUpon>SqlResources.resx</DependentUpon>
</Compile>
<Compile Include="Migrations\Stubs\AlterUserTableMigrationStub.cs" />
<Compile Include="Migrations\PluginManagerExtensions.cs" />
<Compile Include="Migrations\Stubs\Dummy.cs" />
<Compile Include="Migrations\Stubs\FourNineMigration.cs" />
<Compile Include="Migrations\TargetVersionSixthMigrationsTest.cs" />