diff --git a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs index 621c47d568..37659fd5d0 100644 --- a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs @@ -1,6 +1,15 @@ -using NUnit.Framework; +using System; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Models.Rdbms; +using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.SqlSyntax; +using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Core.Publishing; +using Umbraco.Core.Services; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Persistence { @@ -8,10 +17,37 @@ namespace Umbraco.Tests.Persistence public abstract class BaseTableByTableTest { [SetUp] - public abstract void Initialize(); + public virtual void Initialize() + { + TestHelper.SetupLog4NetForTests(); + TestHelper.InitializeContentDirectories(); + + string path = TestHelper.CurrentAssemblyDirectory; + AppDomain.CurrentDomain.SetData("DataDirectory", path); + + RepositoryResolver.Current = new RepositoryResolver( + new RepositoryFactory()); + + ApplicationContext.Current = new ApplicationContext( + //assign the db context + new DatabaseContext(new DefaultDatabaseFactory()), + //assign the service context + new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true }; + + Resolution.Freeze(); + } [TearDown] - public abstract void TearDown(); + public virtual void TearDown() + { + SqlSyntaxContext.SqlSyntaxProvider = null; + AppDomain.CurrentDomain.SetData("DataDirectory", null); + + //reset the app context + ApplicationContext.Current = null; + + RepositoryResolver.Reset(); + } public abstract Database Database { get; } diff --git a/src/Umbraco.Tests/Persistence/MySqlTableByTableTest.cs b/src/Umbraco.Tests/Persistence/MySqlTableByTableTest.cs index bb91263d57..48103cf7b6 100644 --- a/src/Umbraco.Tests/Persistence/MySqlTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/MySqlTableByTableTest.cs @@ -22,21 +22,7 @@ namespace Umbraco.Tests.Persistence [SetUp] public override void Initialize() { - TestHelper.SetupLog4NetForTests(); - TestHelper.InitializeContentDirectories(); - - string path = TestHelper.CurrentAssemblyDirectory; - AppDomain.CurrentDomain.SetData("DataDirectory", path); - - RepositoryResolver.Current = new RepositoryResolver( - new RepositoryFactory()); - - Resolution.Freeze(); - ApplicationContext.Current = new ApplicationContext( - //assign the db context - new DatabaseContext(new DefaultDatabaseFactory()), - //assign the service context - new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true }; + base.Initialize(); SqlSyntaxContext.SqlSyntaxProvider = MySqlSyntax.Provider; @@ -47,12 +33,7 @@ namespace Umbraco.Tests.Persistence [TearDown] public override void TearDown() { - AppDomain.CurrentDomain.SetData("DataDirectory", null); - - //reset the app context - ApplicationContext.Current = null; - - RepositoryResolver.Reset(); + base.TearDown(); } public override Database Database diff --git a/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs b/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs index 74f09897d1..c33fe6d2dd 100644 --- a/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/SqlCeTableByTableTest.cs @@ -24,12 +24,9 @@ namespace Umbraco.Tests.Persistence [SetUp] public override void Initialize() { - TestHelper.SetupLog4NetForTests(); - TestHelper.InitializeContentDirectories(); + base.Initialize(); string path = TestHelper.CurrentAssemblyDirectory; - AppDomain.CurrentDomain.SetData("DataDirectory", path); - //Delete database file before continueing string filePath = string.Concat(path, "\\test.sdf"); if (File.Exists(filePath)) @@ -40,17 +37,7 @@ namespace Umbraco.Tests.Persistence //Create the Sql CE database var engine = new SqlCeEngine("Datasource=|DataDirectory|test.sdf"); engine.CreateDatabase(); - - RepositoryResolver.Current = new RepositoryResolver( - new RepositoryFactory()); - - Resolution.Freeze(); - ApplicationContext.Current = new ApplicationContext( - //assign the db context - new DatabaseContext(new DefaultDatabaseFactory()), - //assign the service context - new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true }; - + SqlSyntaxContext.SqlSyntaxProvider = SqlCeSyntax.Provider; _database = new Database("Datasource=|DataDirectory|test.sdf", @@ -60,14 +47,7 @@ namespace Umbraco.Tests.Persistence [TearDown] public override void TearDown() { - AppDomain.CurrentDomain.SetData("DataDirectory", null); - - SqlSyntaxContext.SqlSyntaxProvider = null; - - //reset the app context - ApplicationContext.Current = null; - - RepositoryResolver.Reset(); + base.TearDown(); } public override Database Database diff --git a/src/Umbraco.Tests/Persistence/SqlTableByTableTest.cs b/src/Umbraco.Tests/Persistence/SqlTableByTableTest.cs index dad49ea54d..bdc9c45b00 100644 --- a/src/Umbraco.Tests/Persistence/SqlTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/SqlTableByTableTest.cs @@ -22,21 +22,7 @@ namespace Umbraco.Tests.Persistence [SetUp] public override void Initialize() { - TestHelper.SetupLog4NetForTests(); - TestHelper.InitializeContentDirectories(); - - string path = TestHelper.CurrentAssemblyDirectory; - AppDomain.CurrentDomain.SetData("DataDirectory", path); - - RepositoryResolver.Current = new RepositoryResolver( - new RepositoryFactory()); - - Resolution.Freeze(); - ApplicationContext.Current = new ApplicationContext( - //assign the db context - new DatabaseContext(new DefaultDatabaseFactory()), - //assign the service context - new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true }; + base.Initialize(); SqlSyntaxContext.SqlSyntaxProvider = SqlServerSyntax.Provider; @@ -47,14 +33,7 @@ namespace Umbraco.Tests.Persistence [TearDown] public override void TearDown() { - AppDomain.CurrentDomain.SetData("DataDirectory", null); - - SqlSyntaxContext.SqlSyntaxProvider = null; - - //reset the app context - ApplicationContext.Current = null; - - RepositoryResolver.Reset(); + base.TearDown(); } public override Database Database