Ensuring closed connections in unit tests using either the legacy or PetaPoco datalayer.

This commit is contained in:
Morten Christensen
2013-01-02 10:44:28 -01:00
parent 56bcb2f804
commit 0312caa166
2 changed files with 10 additions and 6 deletions

View File

@@ -24,7 +24,7 @@ namespace Umbraco.Tests.TestHelpers
/// <summary>
/// Use this abstract class for tests that requires a Sql Ce database populated with the umbraco db schema.
/// The PetaPoco Database class should be used through the <see cref="DatabaseFactory"/> singleton.
/// The PetaPoco Database class should be used through the <see cref="DefaultDatabaseFactory"/>.
/// </summary>
[TestFixture, RequiresSTA]
public abstract class BaseDatabaseFactoryTest
@@ -43,7 +43,9 @@ namespace Umbraco.Tests.TestHelpers
RepositoryResolver.Current = new RepositoryResolver(
new RepositoryFactory());
DatabaseContext.Database.Dispose();
//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
@@ -84,7 +86,7 @@ namespace Umbraco.Tests.TestHelpers
SyntaxConfig.SqlSyntaxProvider = null;
//legacy API database connection close
//legacy API database connection close - because a unit test using PetaPoco db-layer can trigger the usage of SqlHelper we need to ensure that a possible connection is closed.
SqlCeContextGuardian.CloseBackgroundConnection();
ApplicationContext.Current = null;

View File

@@ -3,14 +3,12 @@ using System.IO;
using System.Web.Routing;
using System.Xml;
using NUnit.Framework;
using SQLCE4Umbraco;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.ObjectResolution;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
using Umbraco.Tests.Stubs;
using Umbraco.Web;
using Umbraco.Web.Routing;
@@ -53,12 +51,16 @@ namespace Umbraco.Tests.TestHelpers
TestHelper.CleanContentDirectories();
//reset the app context
DatabaseContext.Database.Dispose();
ApplicationContext.ApplicationCache.ClearAllCache();
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
if (RequiresDbSetup)
{
TestHelper.ClearDatabase();
SqlCeContextGuardian.CloseBackgroundConnection();
}
AppDomain.CurrentDomain.SetData("DataDirectory", null);