diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 4265575e9a..f227411371 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -8,6 +8,7 @@ using NUnit.Framework; using SQLCE4Umbraco; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Logging; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.SqlSyntax; @@ -33,28 +34,37 @@ namespace Umbraco.Tests.TestHelpers public virtual void Initialize() { TestHelper.SetupLog4NetForTests(); - Resolution.Reset(); TestHelper.InitializeContentDirectories(); string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); - UmbracoSettings.UseLegacyXmlSchema = false; - - RepositoryResolver.Current = new RepositoryResolver( - new RepositoryFactory()); - //Ensure that any database connections from a previous test is disposed. This is really just double safety as its also done in the TearDown. if(ApplicationContext != null && DatabaseContext != null) DatabaseContext.Database.Dispose(); SqlCeContextGuardian.CloseBackgroundConnection(); - - //Delete database file before continueing - string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf"); - if (File.Exists(filePath)) + + try { - File.Delete(filePath); + //Delete database file before continueing + string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf"); + if (File.Exists(filePath)) + { + File.Delete(filePath); + } } + catch (Exception) + { + //if this doesn't work we have to make sure everything is reset! otherwise + // well run into issues because we've already set some things up + TearDown(); + throw; + } + + UmbracoSettings.UseLegacyXmlSchema = false; + + RepositoryResolver.Current = new RepositoryResolver( + new RepositoryFactory()); //Get the connectionstring settings from config var settings = ConfigurationManager.ConnectionStrings[Core.Configuration.GlobalSettings.UmbracoConnectionName]; @@ -110,13 +120,23 @@ namespace Umbraco.Tests.TestHelpers string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", null); - string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf"); - if (File.Exists(filePath)) - { - File.Delete(filePath); - } PluginManager.Current = null; UmbracoSettings.ResetSetters(); + + try + { + string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf"); + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + } + catch (Exception ex) + { + LogHelper.Error("Could not remove the old database file", ex); + + //We will swallow this exception! That's because a sub class might require further teardown logic. + } } protected ApplicationContext ApplicationContext diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs index 4bcc592405..e9437b1d98 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs @@ -30,20 +30,30 @@ namespace Umbraco.Tests.TestHelpers TestHelper.SetupLog4NetForTests(); TestHelper.InitializeContentDirectories(); - UmbracoSettings.UseLegacyXmlSchema = false; - string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", path); //If the Database Provider is Sql Ce we need to ensure the database if (ProviderName.Contains("SqlServerCe")) { - //Delete database file before continueing - string filePath = string.Concat(path, "\\test.sdf"); - if (File.Exists(filePath)) + try { - File.Delete(filePath); + //Delete database file before continueing + string filePath = string.Concat(path, "\\test.sdf"); + if (File.Exists(filePath)) + { + File.Delete(filePath); + } } + catch (Exception) + { + //if this doesn't work we have to make sure everything is reset! otherwise + // well run into issues because we've already set some things up + TearDown(); + throw; + } + + UmbracoSettings.UseLegacyXmlSchema = false; //Create the Sql CE database var engine = new SqlCeEngine(ConnectionString);