Supercharges integration tests - now running at a great speed.

This commit is contained in:
Shannon
2014-03-17 22:22:44 +11:00
parent 4748366766
commit 217267bf94
4 changed files with 42 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using Umbraco.Core.Logging;
namespace Umbraco.Core
{
@@ -14,7 +15,7 @@ namespace Umbraco.Core
public static IEnumerable<IEnumerable<T>> InGroupsOf<T>(this IEnumerable<T> source, int groupSize)
{
if (source == null)
throw new NullReferenceException("source");
throw new NullReferenceException("source");
// enumerate the source only once!
return new InGroupsEnumerator<T>(source, groupSize).Groups();
@@ -125,23 +126,13 @@ namespace Umbraco.Core
}
/// <summary>The flatten list.</summary>
/// <param name="items">The items.</param>
/// <param name="selectChild">The select child.</param>
/// <typeparam name="TItem">Item type</typeparam>
/// <param name="e">The items.</param>
/// <param name="f">The select child.</param>
/// <typeparam name="T">Item type</typeparam>
/// <returns>list of TItem</returns>
[SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "By design")]
public static IEnumerable<TItem> FlattenList<TItem>(this IEnumerable<TItem> items, Func<TItem, IEnumerable<TItem>> selectChild)
public static IEnumerable<T> FlattenList<T>(this IEnumerable<T> e, Func<T, IEnumerable<T>> f)
{
IEnumerable<TItem> children = items != null && items.Any()
? items.SelectMany(selectChild).FlattenList(selectChild)
: Enumerable.Empty<TItem>();
if (items != null)
{
return items.Concat(children);
}
return null;
return e.SelectMany(c => f(c).FlattenList(f)).Concat(e);
}
/// <summary>

View File

@@ -290,7 +290,15 @@ namespace Umbraco.Core
"HtmlAgilityPack.",
"TidyNet.",
"ICSharpCode.",
"CookComputing."
"CookComputing.",
"AutoMapper,",
"HtmlAgilityPack,",
"itextsharp,",
"MiniProfiler,",
"Moq,",
"nunit.framework,",
"TidyNet,",
"WebDriver,"
};
/// <summary>

View File

@@ -394,7 +394,7 @@ namespace Umbraco.Tests.Services
return contentType;
}
private IEnumerable<IContentType> CreateContentTypeHierarchy()
private IContentType[] CreateContentTypeHierarchy()
{
//create the master type
var masterContentType = MockedContentTypes.CreateSimpleContentType("masterContentType", "MasterContentType");
@@ -413,7 +413,7 @@ namespace Umbraco.Tests.Services
list.Add(contentType);
}
return list;
return list.ToArray();
}
}
}

View File

@@ -49,6 +49,10 @@ namespace Umbraco.Tests.TestHelpers
private ApplicationContext _appContext;
private string _dbPath;
//used to store (globally) the pre-built db with schema and initial data
private static Byte[] _dbBytes;
[SetUp]
public override void Initialize()
{
@@ -135,7 +139,7 @@ namespace Umbraco.Tests.TestHelpers
Core.Configuration.GlobalSettings.UmbracoConnectionName,
GetDbConnectionString());
string dbFilePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf");
_dbPath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf");
//create a new database file if
// - is the first test in the session
@@ -144,7 +148,7 @@ namespace Umbraco.Tests.TestHelpers
// - _isFirstTestInFixture + DbInitBehavior.NewDbFileAndSchemaPerFixture
//if this is the first test in the session, always ensure a new db file is created
if (_isFirstRunInTestSession || !File.Exists(dbFilePath)
if (_isFirstRunInTestSession || File.Exists(_dbPath) == false
|| DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerTest
|| (_isFirstTestInFixture && DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerFixture))
{
@@ -163,8 +167,15 @@ namespace Umbraco.Tests.TestHelpers
//Create the Sql CE database
using (DisposableTimer.TraceDuration<BaseDatabaseFactoryTest>("Create database file"))
{
var engine = new SqlCeEngine(settings.ConnectionString);
engine.CreateDatabase();
if (_dbBytes != null)
{
File.WriteAllBytes(_dbPath, _dbBytes);
}
else
{
var engine = new SqlCeEngine(settings.ConnectionString);
engine.CreateDatabase();
}
}
}
@@ -210,12 +221,19 @@ namespace Umbraco.Tests.TestHelpers
// - NewDbFileAndSchemaPerTest
// - _isFirstTestInFixture + DbInitBehavior.NewDbFileAndSchemaPerFixture
if (_isFirstRunInTestSession
if (_dbBytes == null &&
(_isFirstRunInTestSession
|| DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerTest
|| (_isFirstTestInFixture && DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerFixture))
|| (_isFirstTestInFixture && DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerFixture)))
{
//Create the umbraco database and its base data
DatabaseContext.Database.CreateDatabaseSchema(false);
//close the connections, we're gonna read this baby in as a byte array so we don't have to re-initialize the
// damn db for each test
CloseDbConnections();
_dbBytes = File.ReadAllBytes(_dbPath);
}
}