should knock off a few minutes for running tests.

This commit is contained in:
Shannon
2013-11-15 16:00:48 +11:00
parent 4a6103ba94
commit 9774744991
6 changed files with 112 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ using System.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Services
@@ -25,6 +26,11 @@ namespace Umbraco.Tests.Services
base.TearDown();
}
protected override DatabaseBehavior DatabaseTestBehavior
{
get { return DatabaseBehavior.NewSchemaPerFixture; }
}
[Test]
public void EntityService_Can_Find_All_Content_By_UmbracoObjectTypes()
{
@@ -136,24 +142,32 @@ namespace Umbraco.Tests.Services
y => y.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias)), Is.True);
}
private static bool _isSetup = false;
public override void CreateTestData()
{
base.CreateTestData();
if (_isSetup == false)
{
_isSetup = true;
//Create and Save folder-Media -> 1050
var folderMediaType = ServiceContext.ContentTypeService.GetMediaType(1031);
var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
ServiceContext.MediaService.Save(folder, 0);
base.CreateTestData();
//Create and Save image-Media -> 1051
var imageMediaType = ServiceContext.ContentTypeService.GetMediaType(1032);
var image = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);
ServiceContext.MediaService.Save(image, 0);
//Create and Save folder-Media -> 1050
var folderMediaType = ServiceContext.ContentTypeService.GetMediaType(1031);
var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1);
ServiceContext.MediaService.Save(folder, 0);
//Create and Save file-Media -> 1052
var fileMediaType = ServiceContext.ContentTypeService.GetMediaType(1033);
var file = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);
ServiceContext.MediaService.Save(file, 0);
//Create and Save image-Media -> 1051
var imageMediaType = ServiceContext.ContentTypeService.GetMediaType(1032);
var image = MockedMedia.CreateMediaImage(imageMediaType, folder.Id);
ServiceContext.MediaService.Save(image, 0);
//Create and Save file-Media -> 1052
var fileMediaType = ServiceContext.ContentTypeService.GetMediaType(1033);
var file = MockedMedia.CreateMediaFile(fileMediaType, folder.Id);
ServiceContext.MediaService.Save(file, 0);
}
}
}
}

View File

@@ -55,10 +55,10 @@ namespace Umbraco.Tests.TestHelpers
public override void Initialize()
{
InitializeFirstRunFlags();
var path = TestHelper.CurrentAssemblyDirectory;
AppDomain.CurrentDomain.SetData("DataDirectory", path);
//disable cache
var cacheHelper = CacheHelper.CreateDisabledCacheHelper();
@@ -67,25 +67,35 @@ namespace Umbraco.Tests.TestHelpers
GetDbProviderName());
_appContext = new ApplicationContext(
//assign the db context
new DatabaseContext(dbFactory),
//assign the service context
new ServiceContext(new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper),
cacheHelper)
{
IsReady = true
};
//assign the db context
new DatabaseContext(dbFactory),
//assign the service context
new ServiceContext(new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper),
cacheHelper)
{
IsReady = true
};
base.Initialize();
DatabaseContext.Initialize(dbFactory.ProviderName, dbFactory.ConnectionString);
using (DisposableTimer.TraceDuration<BaseDatabaseFactoryTest>("init"))
{
using (DisposableTimer.TraceDuration<BaseDatabaseFactoryTest>("DatabaseContext.Initialize"))
{
DatabaseContext.Initialize(dbFactory.ProviderName, dbFactory.ConnectionString);
}
using (DisposableTimer.TraceDuration<BaseDatabaseFactoryTest>("CreateSqlCeDatabase"))
{
CreateSqlCeDatabase();
}
using (DisposableTimer.TraceDuration<BaseDatabaseFactoryTest>("InitializeDatabase"))
{
InitializeDatabase();
}
CreateSqlCeDatabase();
InitializeDatabase();
//ensure the configuration matches the current version for tests
SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3);
//ensure the configuration matches the current version for tests
SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3);
}
}
protected override void SetupApplicationContext()

View File

@@ -28,17 +28,23 @@ namespace Umbraco.Tests.TestHelpers
{
base.Initialize();
TestHelper.InitializeContentDirectories();
TestHelper.EnsureUmbracoSettingsConfig();
using (DisposableTimer.TraceDuration<BaseUmbracoApplicationTest>("init"))
{
TestHelper.InitializeContentDirectories();
//TestHelper.EnsureUmbracoSettingsConfig();
//Create the legacy prop-eds mapping
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
SetupPluginManager();
SetupApplicationContext();
InitializeMappers();
FreezeResolution();
}
//Create the legacy prop-eds mapping
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
SetupPluginManager();
SetupApplicationContext();
InitializeMappers();
FreezeResolution();
}
[TearDown]

View File

@@ -1,4 +1,5 @@
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
namespace Umbraco.Tests.TestHelpers
@@ -9,17 +10,25 @@ namespace Umbraco.Tests.TestHelpers
[TestFixture]
public abstract class BaseUmbracoConfigurationTest
{
[TestFixtureSetUp]
public void InitializeFixture()
{
TestHelper.SetupLog4NetForTests();
}
[SetUp]
public virtual void Initialize()
{
TestHelper.SetupLog4NetForTests();
using (DisposableTimer.TraceDuration < BaseUmbracoConfigurationTest>("init"))
{
//mock the Umbraco settings that we need
var settings = SettingsForTests.GetMockSettings();
//sets the global singleton to use the mocked format
SettingsForTests.ConfigureSettings(settings);
//set our local variable for tests to use (preferably)
UmbracoSettings = settings;
}
//mock the Umbraco settings that we need
var settings = SettingsForTests.GetMockSettings();
//sets the global singleton to use the mocked format
SettingsForTests.ConfigureSettings(settings);
//set our local variable for tests to use (preferably)
UmbracoSettings = settings;
}
[TearDown]

View File

@@ -113,27 +113,27 @@ namespace Umbraco.Tests.TestHelpers
}
}
//TODO: With the new config updates, I'm pretty sure this isn't needed?
public static void EnsureUmbracoSettingsConfig()
{
var currDir = new DirectoryInfo(CurrentAssemblyDirectory);
////TODO: With the new config updates, I'm pretty sure this isn't needed?
//public static void EnsureUmbracoSettingsConfig()
//{
// var currDir = new DirectoryInfo(CurrentAssemblyDirectory);
var configPath = Path.Combine(currDir.Parent.Parent.FullName, "config");
if (Directory.Exists(configPath) == false)
Directory.CreateDirectory(configPath);
// var configPath = Path.Combine(currDir.Parent.Parent.FullName, "config");
// if (Directory.Exists(configPath) == false)
// Directory.CreateDirectory(configPath);
var umbracoSettingsFile = Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config");
if (File.Exists(umbracoSettingsFile) == false)
File.Copy(
currDir.Parent.Parent.Parent.GetDirectories("Umbraco.Web.UI")
.First()
.GetDirectories("config").First()
.GetFiles("umbracoSettings.Release.config").First().FullName,
Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config"),
true);
// var umbracoSettingsFile = Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config");
// if (File.Exists(umbracoSettingsFile) == false)
// File.Copy(
// currDir.Parent.Parent.Parent.GetDirectories("Umbraco.Web.UI")
// .First()
// .GetDirectories("config").First()
// .GetFiles("umbracoSettings.Release.config").First().FullName,
// Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config"),
// true);
//Core.Configuration.LegacyUmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false);
}
// //Core.Configuration.LegacyUmbracoSettings.SettingsFilePath = IOHelper.MapPath(SystemDirectories.Config + Path.DirectorySeparatorChar, false);
//}
public static void CleanUmbracoSettingsConfig()
{

View File

@@ -14,7 +14,14 @@
</logger>
<logger name="Umbraco.Core.Persistence.Database">
<level value="WARN" />
<level value="OFF" />
</logger>
<logger name="Umbraco.Core.Persistence.UmbracoDatabase">
<level value="OFF" />
</logger>
<logger name="DatabaseSchemaCreation">
<level value="OFF" />
</logger>
<logger name="Umbraco.Core.Persistence.Migrations.Initial.DatabaseSchemaCreation">