Correcting a few unit tests that needed to have the ApplicationContext set in the SetUp of the fixture.

This commit is contained in:
Morten Christensen
2012-12-14 13:49:20 -01:00
parent 4c256986da
commit 3d68106f47
6 changed files with 108 additions and 30 deletions

View File

@@ -26,40 +26,12 @@ namespace Umbraco.Core
private bool _configured;
private string _connectionString;
private string _providerName;
//private static readonly object Locker = new object();
//private static DatabaseContext _databaseContext;
//#region Singleton
///// <summary>
///// Gets the current Database Context.
///// </summary>
//public static DatabaseContext Current
//{
// get
// {
// if (_databaseContext == null)
// throw new InvalidOperationException("The DatabaseContext hasn't been initialized. Ensure that the CoreBootManager has been used to boot the application");
// return _databaseContext;
// }
// internal set
// {
// lock(Locker)
// {
// _databaseContext = value;
// }
// }
//}
//#endregion
internal DatabaseContext(IDatabaseFactory factory)
{
_factory = factory;
}
/// <summary>
/// Gets the <see cref="Database"/> object for doing CRUD operations
/// against custom tables that resides in the Umbraco database.

View File

@@ -1,7 +1,13 @@
using System;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
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
@@ -16,9 +22,24 @@ namespace Umbraco.Tests.Persistence
[SetUp]
public override void Initialize()
{
TestHelper.SetupLog4NetForTests();
TestHelper.InitializeContentDirectories();
string path = TestHelper.CurrentAssemblyDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);
UmbracoSettings.UseLegacyXmlSchema = false;
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 };
SyntaxConfig.SqlSyntaxProvider = MySqlSyntaxProvider.Instance;
_database = new Database("Server = 192.168.1.108; Database = testDb; Uid = umbraco; Pwd = umbraco",
@@ -29,6 +50,12 @@ namespace Umbraco.Tests.Persistence
public override void TearDown()
{
AppDomain.CurrentDomain.SetData("DataDirectory", null);
//reset the app context
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
RepositoryResolver.Reset();
}
public override Database Database

View File

@@ -1,10 +1,15 @@
using System;
using System.Configuration;
using System.Data.SqlServerCe;
using System.IO;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
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
@@ -19,6 +24,9 @@ namespace Umbraco.Tests.Persistence
[SetUp]
public override void Initialize()
{
TestHelper.SetupLog4NetForTests();
TestHelper.InitializeContentDirectories();
string path = TestHelper.CurrentAssemblyDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);
@@ -33,6 +41,18 @@ namespace Umbraco.Tests.Persistence
var engine = new SqlCeEngine("Datasource=|DataDirectory|test.sdf");
engine.CreateDatabase();
UmbracoSettings.UseLegacyXmlSchema = false;
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 };
SyntaxConfig.SqlSyntaxProvider = SqlCeSyntaxProvider.Instance;
_database = new Database("Datasource=|DataDirectory|test.sdf",
@@ -43,6 +63,12 @@ namespace Umbraco.Tests.Persistence
public override void TearDown()
{
AppDomain.CurrentDomain.SetData("DataDirectory", null);
//reset the app context
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
RepositoryResolver.Reset();
}
public override Database Database

View File

@@ -1,7 +1,13 @@
using System;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
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
@@ -16,9 +22,24 @@ namespace Umbraco.Tests.Persistence
[SetUp]
public override void Initialize()
{
TestHelper.SetupLog4NetForTests();
TestHelper.InitializeContentDirectories();
string path = TestHelper.CurrentAssemblyDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);
UmbracoSettings.UseLegacyXmlSchema = false;
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 };
SyntaxConfig.SqlSyntaxProvider = SqlServerSyntaxProvider.Instance;
_database = new Database(@"server=.\SQLEXPRESS;database=EmptyForTest;user id=umbraco;password=umbraco",
@@ -29,6 +50,12 @@ namespace Umbraco.Tests.Persistence
public override void TearDown()
{
AppDomain.CurrentDomain.SetData("DataDirectory", null);
//reset the app context
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
RepositoryResolver.Reset();
}
public override Database Database

View File

@@ -7,7 +7,6 @@ using System.Xml;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.ObjectResolution;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.UnitOfWork;

View File

@@ -2,8 +2,14 @@
using System.Data.SqlServerCe;
using System.IO;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration;
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;
namespace Umbraco.Tests.TestHelpers
{
@@ -21,6 +27,9 @@ namespace Umbraco.Tests.TestHelpers
[SetUp]
public virtual void Initialize()
{
TestHelper.SetupLog4NetForTests();
TestHelper.InitializeContentDirectories();
string path = TestHelper.CurrentAssemblyDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);
@@ -39,6 +48,18 @@ namespace Umbraco.Tests.TestHelpers
engine.CreateDatabase();
}
UmbracoSettings.UseLegacyXmlSchema = false;
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 };
SyntaxConfig.SqlSyntaxProvider = SyntaxProvider;
//Create the umbraco database
@@ -59,6 +80,12 @@ namespace Umbraco.Tests.TestHelpers
public virtual void TearDown()
{
AppDomain.CurrentDomain.SetData("DataDirectory", null);
//reset the app context
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
RepositoryResolver.Reset();
}
}
}