Tests reorg, kill TestWithApplicationBase
This commit is contained in:
@@ -13,8 +13,8 @@ using Umbraco.Tests.Testing;
|
||||
namespace Umbraco.Tests.Models.Mapping
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(AutoMapper = true)]
|
||||
public class AutoMapperTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class AutoMapperTests : UmbracoTestBase
|
||||
{
|
||||
protected override void Compose()
|
||||
{
|
||||
|
||||
@@ -5,14 +5,13 @@ using AutoMapper;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Models.Mapping;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
@@ -20,7 +19,8 @@ using Umbraco.Web.PropertyEditors;
|
||||
namespace Umbraco.Tests.Models.Mapping
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentTypeModelMappingTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class ContentTypeModelMappingTests : UmbracoTestBase
|
||||
{
|
||||
// mocks of services that can be setup on a test by test basis to return whatever we want
|
||||
private readonly Mock<IContentTypeService> _contentTypeService = new Mock<IContentTypeService>();
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
[TestFixture]
|
||||
public class PartialViewRepositoryTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class PartialViewRepositoryTests : UmbracoTestBase
|
||||
{
|
||||
private IFileSystem _fileSystem;
|
||||
|
||||
|
||||
@@ -7,16 +7,16 @@ using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
[TestFixture]
|
||||
public class ScriptRepositoryTest : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class ScriptRepositoryTest : UmbracoTestBase
|
||||
{
|
||||
private IFileSystem _fileSystem;
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ using Microsoft.Owin;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -17,7 +16,8 @@ using Umbraco.Web.Security.Identity;
|
||||
namespace Umbraco.Tests.Security
|
||||
{
|
||||
[TestFixture]
|
||||
public class BackOfficeCookieManagerTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class BackOfficeCookieManagerTests : UmbracoTestBase
|
||||
{
|
||||
[Test]
|
||||
public void ShouldAuthenticateRequest_When_Not_Configured()
|
||||
|
||||
@@ -5,13 +5,14 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentTypeServiceExtensionsTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class ContentTypeServiceExtensionsTests : UmbracoTestBase
|
||||
{
|
||||
[Test]
|
||||
public void GetAvailableCompositeContentTypes_No_Overlap_By_Content_Type_And_Property_Type_Alias()
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Plugins;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.Services;
|
||||
using UmbracoExamine;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a base class for all Umbraco tests that require the Umbraco application.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Sets the Umbraco application DI container.</para>
|
||||
/// <para>Defines the Compose method for DI composition.</para>
|
||||
/// <para>Sets all sorts of things such as logging, plugin manager, base services, database factory & context...</para>
|
||||
/// <para>Does *not* create a database.</para>
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
[UmbracoTest(AutoMapper = true, ResetPluginManager = false)]
|
||||
public abstract class TestWithApplicationBase : UmbracoTestBase
|
||||
{
|
||||
protected ILogger Logger => Container.GetInstance<ILogger>();
|
||||
|
||||
protected IProfiler Profiler => Container.GetInstance<IProfiler>();
|
||||
|
||||
protected ProfilingLogger ProfilingLogger => Container.GetInstance<ProfilingLogger>();
|
||||
|
||||
protected CacheHelper CacheHelper => Container.GetInstance<CacheHelper>();
|
||||
|
||||
protected virtual ISqlSyntaxProvider SqlSyntax => new SqlCeSyntaxProvider();
|
||||
|
||||
protected IMapperCollection Mappers => Container.GetInstance<IMapperCollection>();
|
||||
|
||||
protected IQueryFactory QueryFactory => Container.GetInstance<DatabaseContext>().QueryFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the plugin manager should be resetted before and after each test.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// False by default, so the plugin manager does not need to re-scan all of the assemblies and tests run faster.
|
||||
/// Can be overriden if the plugin manager does need to reset, usually when SetupPluginManager has been overriden.
|
||||
/// </remarks>
|
||||
protected virtual bool PluginManagerResetRequired => false;
|
||||
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
|
||||
TestHelper.InitializeContentDirectories();
|
||||
|
||||
// initialize legacy mapings for core editors
|
||||
// create the legacy prop-eds mapping
|
||||
if (LegacyPropertyEditorIdToAliasConverter.Count() == 0)
|
||||
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
TestHelper.CleanContentDirectories();
|
||||
TestHelper.CleanUmbracoSettingsConfig();
|
||||
}
|
||||
|
||||
protected override void Compose()
|
||||
{
|
||||
base.Compose();
|
||||
|
||||
var settings = SettingsForTests.GetDefault();
|
||||
|
||||
// default Datalayer/Repositories/SQL/Database/etc...
|
||||
Container.RegisterFrom<RepositoryCompositionRoot>();
|
||||
|
||||
// register basic stuff that might need to be there for some container resolvers to work
|
||||
Container.RegisterSingleton(factory => SettingsForTests.GetDefault());
|
||||
Container.RegisterSingleton(factory => settings.Content);
|
||||
Container.RegisterSingleton(factory => settings.Templates);
|
||||
Container.Register<IServiceProvider, ActivatorServiceProvider>();
|
||||
Container.Register(factory => new MediaFileSystem(Mock.Of<IFileSystem>()));
|
||||
Container.RegisterSingleton<IExamineIndexCollectionAccessor, TestIndexCollectionAccessor>();
|
||||
|
||||
// replace some stuff
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "ScriptFileSystem");
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "PartialViewFileSystem");
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "PartialViewMacroFileSystem");
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "StylesheetFileSystem");
|
||||
|
||||
// need real file systems here as templates content is on-disk only
|
||||
//Container.RegisterSingleton<IFileSystem>(factory => Mock.Of<IFileSystem>(), "MasterpageFileSystem");
|
||||
//Container.RegisterSingleton<IFileSystem>(factory => Mock.Of<IFileSystem>(), "ViewFileSystem");
|
||||
Container.RegisterSingleton<IFileSystem>(factory => new PhysicalFileSystem("Views", "/views"), "ViewFileSystem");
|
||||
Container.RegisterSingleton<IFileSystem>(factory => new PhysicalFileSystem("MasterPages", "/masterpages"), "MasterpageFileSystem");
|
||||
|
||||
// no factory (noop)
|
||||
Container.RegisterSingleton<IPublishedContentModelFactory, NoopPublishedContentModelFactory>();
|
||||
|
||||
// register application stuff (database factory & context, services...)
|
||||
Container.RegisterCollectionBuilder<MapperCollectionBuilder>()
|
||||
.AddCore();
|
||||
|
||||
Container.RegisterSingleton<IEventMessagesFactory>(_ => new TransientEventMessagesFactory());
|
||||
Container.RegisterSingleton<IDatabaseScopeAccessor, TestDatabaseScopeAccessor>();
|
||||
var sqlSyntaxProviders = TestObjects.GetDefaultSqlSyntaxProviders(Logger);
|
||||
Container.RegisterSingleton<ISqlSyntaxProvider>(_ => sqlSyntaxProviders.OfType<SqlCeSyntaxProvider>().First());
|
||||
Container.RegisterSingleton<IDatabaseFactory>(f => new UmbracoDatabaseFactory(
|
||||
Core.Configuration.GlobalSettings.UmbracoConnectionName,
|
||||
sqlSyntaxProviders,
|
||||
Logger, f.GetInstance<IDatabaseScopeAccessor>(),
|
||||
Mock.Of<IMapperCollection>()));
|
||||
Container.RegisterSingleton(f => new DatabaseContext(f.GetInstance<IDatabaseFactory>()));
|
||||
|
||||
Container.RegisterCollectionBuilder<UrlSegmentProviderCollectionBuilder>(); // empty
|
||||
Container.Register(factory
|
||||
=> TestObjects.GetDatabaseUnitOfWorkProvider(factory.GetInstance<ILogger>(), factory.TryGetInstance<IDatabaseFactory>(), factory.TryGetInstance<RepositoryFactory>()));
|
||||
|
||||
Container.RegisterFrom<ServicesCompositionRoot>();
|
||||
// composition root is doing weird things, fix
|
||||
Container.RegisterSingleton<IApplicationTreeService, ApplicationTreeService>();
|
||||
Container.RegisterSingleton<ISectionService, SectionService>();
|
||||
|
||||
// somehow property editor ends up wanting this
|
||||
Container.RegisterSingleton(f => new ManifestBuilder(
|
||||
f.GetInstance<IRuntimeCacheProvider>(),
|
||||
new ManifestParser(f.GetInstance<ILogger>(), new DirectoryInfo(IOHelper.MapPath("~/App_Plugins")), f.GetInstance<IRuntimeCacheProvider>())
|
||||
));
|
||||
|
||||
// note - don't register collections, use builders
|
||||
Container.RegisterCollectionBuilder<PropertyEditorCollectionBuilder>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data.SqlServerCe;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using System.Xml;
|
||||
@@ -13,9 +12,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -29,10 +26,7 @@ using Umbraco.Core.Plugins;
|
||||
using Umbraco.Web.Routing;
|
||||
using File = System.IO.File;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
@@ -47,8 +41,9 @@ namespace Umbraco.Tests.TestHelpers
|
||||
/// <para>Provides an Umbraco context and Xml content.</para>
|
||||
/// <para>fixme what else?</para>
|
||||
/// </remarks>
|
||||
[TestFixture, RequiresSTA]
|
||||
public abstract class TestWithDatabaseBase : TestWithApplicationBase
|
||||
[RequiresSTA] // why?
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public abstract class TestWithDatabaseBase : UmbracoTestBase
|
||||
{
|
||||
private CacheHelper _disabledCacheHelper;
|
||||
private IFacadeService _facadeService;
|
||||
|
||||
@@ -8,20 +8,55 @@ namespace Umbraco.Tests.Testing
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, /*AllowMultiple = false,*/ Inherited = false)]
|
||||
public class UmbracoTestAttribute : Attribute
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether tests are "WithApplication".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Default is false.</para>
|
||||
/// <para>This is for tests that inherited from TestWithApplicationBase.</para>
|
||||
/// <para>Implies AutoMapper = true (, ResetPluginManager = false).</para>
|
||||
/// </remarks>
|
||||
public bool WithApplication { get { return _withApplication.ValueOrDefault(false); } set { _withApplication.Set(value); } }
|
||||
private readonly Settable<bool> _withApplication = new Settable<bool>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to compose and initialize AutoMapper.
|
||||
/// </summary>
|
||||
/// <remarks>Default is false unless WithApplication is true, in which case default is true.</remarks>
|
||||
public bool AutoMapper { get { return _autoMapper.ValueOrDefault(WithApplication); } set { _autoMapper.Set(value);} }
|
||||
private readonly Settable<bool> _autoMapper = new Settable<bool>();
|
||||
public bool AutoMapper { get { return _autoMapper.ValueOrDefault(false); } set { _autoMapper.Set(value);} }
|
||||
|
||||
private readonly Settable<bool> _resetPluginManager = new Settable<bool>();
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating ... FIXME to be completed
|
||||
/// </summary>
|
||||
public bool ResetPluginManager { get { return _resetPluginManager.ValueOrDefault(false); } set { _resetPluginManager.Set(value); } }
|
||||
private readonly Settable<bool> _resetPluginManager = new Settable<bool>();
|
||||
|
||||
private readonly Settable<bool> _facadeServiceRepositoryEvents = new Settable<bool>();
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating ... FIXME to be completed
|
||||
/// </summary>
|
||||
public bool FacadeServiceRepositoryEvents { get { return _facadeServiceRepositoryEvents.ValueOrDefault(false); } set { _facadeServiceRepositoryEvents.Set(value); } }
|
||||
private readonly Settable<bool> _facadeServiceRepositoryEvents = new Settable<bool>();
|
||||
|
||||
private readonly Settable<UmbracoTestOptions.Logger> _logger = new Settable<UmbracoTestOptions.Logger>();
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating the required logging support.
|
||||
/// </summary>
|
||||
/// <remarks>Default is to mock logging.</remarks>
|
||||
public UmbracoTestOptions.Logger Logger { get { return _logger.ValueOrDefault(UmbracoTestOptions.Logger.Mock); } set { _logger.Set(value); } }
|
||||
private readonly Settable<UmbracoTestOptions.Logger> _logger = new Settable<UmbracoTestOptions.Logger>();
|
||||
|
||||
private readonly Settable<UmbracoTestOptions.Database> _database = new Settable<UmbracoTestOptions.Database>();
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating the required database support.
|
||||
/// </summary>
|
||||
/// <remarks>Default is no database support.</remarks>
|
||||
public UmbracoTestOptions.Database Database { get { return _database.ValueOrDefault(UmbracoTestOptions.Database.None); } set { _database.Set(value); } }
|
||||
private readonly Settable<UmbracoTestOptions.Database> _database = new Settable<UmbracoTestOptions.Database>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Get
|
||||
|
||||
public static UmbracoTestAttribute Get(MethodInfo method)
|
||||
{
|
||||
@@ -56,5 +91,7 @@ namespace Umbraco.Tests.Testing
|
||||
_database.Set(other._database);
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AutoMapper;
|
||||
using LightInject;
|
||||
@@ -8,13 +10,26 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Components;
|
||||
using Umbraco.Core.DI;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Models.Mapping;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Plugins;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.DI;
|
||||
using Umbraco.Web.Services;
|
||||
using UmbracoExamine;
|
||||
using Current = Umbraco.Core.DI.Current;
|
||||
|
||||
namespace Umbraco.Tests.Testing
|
||||
@@ -39,6 +54,7 @@ namespace Umbraco.Tests.Testing
|
||||
// starting a test runs like this:
|
||||
// - SetUp() // when overriding, call base.SetUp() *first* then setup your own stuff
|
||||
// --- Compose() // when overriding, call base.Commpose() *first* then compose your own stuff
|
||||
// --- Initialize() // same
|
||||
// - test runs
|
||||
// - TearDown() // when overriding, clear you own stuff *then* call base.TearDown()
|
||||
//
|
||||
@@ -64,6 +80,26 @@ namespace Umbraco.Tests.Testing
|
||||
|
||||
private static PluginManager _pluginManager;
|
||||
|
||||
#region Accessors
|
||||
|
||||
protected ILogger Logger => Container.GetInstance<ILogger>();
|
||||
|
||||
protected IProfiler Profiler => Container.GetInstance<IProfiler>();
|
||||
|
||||
protected ProfilingLogger ProfilingLogger => Container.GetInstance<ProfilingLogger>();
|
||||
|
||||
protected CacheHelper CacheHelper => Container.GetInstance<CacheHelper>();
|
||||
|
||||
protected virtual ISqlSyntaxProvider SqlSyntax => Container.GetInstance<ISqlSyntaxProvider>();
|
||||
|
||||
protected IMapperCollection Mappers => Container.GetInstance<IMapperCollection>();
|
||||
|
||||
protected IQueryFactory QueryFactory => Container.GetInstance<DatabaseContext>().QueryFactory;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setup
|
||||
|
||||
[SetUp]
|
||||
public virtual void SetUp()
|
||||
{
|
||||
@@ -93,6 +129,7 @@ namespace Umbraco.Tests.Testing
|
||||
ComposeAutoMapper(Options.AutoMapper);
|
||||
ComposePluginManager(Options.ResetPluginManager);
|
||||
ComposeDatabase(Options.Database);
|
||||
ComposeApplication(Options.WithApplication);
|
||||
// etc
|
||||
ComposeWtf();
|
||||
|
||||
@@ -107,9 +144,12 @@ namespace Umbraco.Tests.Testing
|
||||
protected virtual void Initialize()
|
||||
{
|
||||
InitializeAutoMapper(Options.AutoMapper);
|
||||
InitializeApplication(Options.WithApplication);
|
||||
}
|
||||
|
||||
#region Composing
|
||||
#endregion
|
||||
|
||||
#region Compose
|
||||
|
||||
protected virtual void ComposeLogging(UmbracoTestOptions.Logger option)
|
||||
{
|
||||
@@ -177,6 +217,72 @@ namespace Umbraco.Tests.Testing
|
||||
|
||||
}
|
||||
|
||||
protected virtual void ComposeApplication(bool withApplication)
|
||||
{
|
||||
if (withApplication == false) return;
|
||||
|
||||
var settings = SettingsForTests.GetDefault();
|
||||
|
||||
// default Datalayer/Repositories/SQL/Database/etc...
|
||||
Container.RegisterFrom<RepositoryCompositionRoot>();
|
||||
|
||||
// register basic stuff that might need to be there for some container resolvers to work
|
||||
Container.RegisterSingleton(factory => SettingsForTests.GetDefault());
|
||||
Container.RegisterSingleton(factory => settings.Content);
|
||||
Container.RegisterSingleton(factory => settings.Templates);
|
||||
Container.Register<IServiceProvider, ActivatorServiceProvider>();
|
||||
Container.Register(factory => new MediaFileSystem(Mock.Of<IFileSystem>()));
|
||||
Container.RegisterSingleton<IExamineIndexCollectionAccessor, TestIndexCollectionAccessor>();
|
||||
|
||||
// replace some stuff
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "ScriptFileSystem");
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "PartialViewFileSystem");
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "PartialViewMacroFileSystem");
|
||||
Container.RegisterSingleton(factory => Mock.Of<IFileSystem>(), "StylesheetFileSystem");
|
||||
|
||||
// need real file systems here as templates content is on-disk only
|
||||
//Container.RegisterSingleton<IFileSystem>(factory => Mock.Of<IFileSystem>(), "MasterpageFileSystem");
|
||||
//Container.RegisterSingleton<IFileSystem>(factory => Mock.Of<IFileSystem>(), "ViewFileSystem");
|
||||
Container.RegisterSingleton<IFileSystem>(factory => new PhysicalFileSystem("Views", "/views"), "ViewFileSystem");
|
||||
Container.RegisterSingleton<IFileSystem>(factory => new PhysicalFileSystem("MasterPages", "/masterpages"), "MasterpageFileSystem");
|
||||
|
||||
// no factory (noop)
|
||||
Container.RegisterSingleton<IPublishedContentModelFactory, NoopPublishedContentModelFactory>();
|
||||
|
||||
// register application stuff (database factory & context, services...)
|
||||
Container.RegisterCollectionBuilder<MapperCollectionBuilder>()
|
||||
.AddCore();
|
||||
|
||||
Container.RegisterSingleton<IEventMessagesFactory>(_ => new TransientEventMessagesFactory());
|
||||
Container.RegisterSingleton<IDatabaseScopeAccessor, TestDatabaseScopeAccessor>();
|
||||
var sqlSyntaxProviders = TestObjects.GetDefaultSqlSyntaxProviders(Logger);
|
||||
Container.RegisterSingleton<ISqlSyntaxProvider>(_ => sqlSyntaxProviders.OfType<SqlCeSyntaxProvider>().First());
|
||||
Container.RegisterSingleton<IDatabaseFactory>(f => new UmbracoDatabaseFactory(
|
||||
Core.Configuration.GlobalSettings.UmbracoConnectionName,
|
||||
sqlSyntaxProviders,
|
||||
Logger, f.GetInstance<IDatabaseScopeAccessor>(),
|
||||
Mock.Of<IMapperCollection>()));
|
||||
Container.RegisterSingleton(f => new DatabaseContext(f.GetInstance<IDatabaseFactory>()));
|
||||
|
||||
Container.RegisterCollectionBuilder<UrlSegmentProviderCollectionBuilder>(); // empty
|
||||
Container.Register(factory
|
||||
=> TestObjects.GetDatabaseUnitOfWorkProvider(factory.GetInstance<ILogger>(), factory.TryGetInstance<IDatabaseFactory>(), factory.TryGetInstance<RepositoryFactory>()));
|
||||
|
||||
Container.RegisterFrom<ServicesCompositionRoot>();
|
||||
// composition root is doing weird things, fix
|
||||
Container.RegisterSingleton<IApplicationTreeService, ApplicationTreeService>();
|
||||
Container.RegisterSingleton<ISectionService, SectionService>();
|
||||
|
||||
// somehow property editor ends up wanting this
|
||||
Container.RegisterSingleton(f => new ManifestBuilder(
|
||||
f.GetInstance<IRuntimeCacheProvider>(),
|
||||
new ManifestParser(f.GetInstance<ILogger>(), new DirectoryInfo(IOHelper.MapPath("~/App_Plugins")), f.GetInstance<IRuntimeCacheProvider>())
|
||||
));
|
||||
|
||||
// note - don't register collections, use builders
|
||||
Container.RegisterCollectionBuilder<PropertyEditorCollectionBuilder>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialize
|
||||
@@ -193,6 +299,18 @@ namespace Umbraco.Tests.Testing
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void InitializeApplication(bool withApplication)
|
||||
{
|
||||
if (withApplication == false) return;
|
||||
|
||||
TestHelper.InitializeContentDirectories();
|
||||
|
||||
// initialize legacy mapings for core editors
|
||||
// create the legacy prop-eds mapping
|
||||
if (LegacyPropertyEditorIdToAliasConverter.Count() == 0)
|
||||
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TearDown and Reset
|
||||
@@ -204,6 +322,12 @@ namespace Umbraco.Tests.Testing
|
||||
FirstTestInSession = false;
|
||||
|
||||
Reset();
|
||||
|
||||
if (Options.WithApplication)
|
||||
{
|
||||
TestHelper.CleanContentDirectories();
|
||||
TestHelper.CleanUmbracoSettingsConfig();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Reset()
|
||||
|
||||
@@ -529,7 +529,6 @@
|
||||
<Compile Include="Cache\DistributedCache\DistributedCacheTests.cs" />
|
||||
<Compile Include="Templates\MasterPageHelperTests.cs" />
|
||||
<Compile Include="TestHelpers\TestWithDatabaseBase.cs" />
|
||||
<Compile Include="TestHelpers\TestWithApplicationBase.cs" />
|
||||
<Compile Include="TestHelpers\SettingsForTests.cs" />
|
||||
<Compile Include="Configurations\GlobalSettingsTests.cs" />
|
||||
<Compile Include="Routing\ContentFinderByAliasTests.cs" />
|
||||
|
||||
@@ -13,6 +13,7 @@ using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
@@ -22,7 +23,8 @@ using Umbraco.Web.Security;
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class SurfaceControllerTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class SurfaceControllerTests : UmbracoTestBase
|
||||
{
|
||||
public override void SetUp()
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -26,7 +27,8 @@ using Umbraco.Web.Security;
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
[TestFixture]
|
||||
public class UmbracoViewPageTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class UmbracoViewPageTests : UmbracoTestBase
|
||||
{
|
||||
private FacadeService _service;
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
@@ -18,7 +17,8 @@ using Current = Umbraco.Web.Current;
|
||||
namespace Umbraco.Tests.Web
|
||||
{
|
||||
[TestFixture]
|
||||
public class WebExtensionMethodTests : TestWithApplicationBase
|
||||
[UmbracoTest(WithApplication = true)]
|
||||
public class WebExtensionMethodTests : UmbracoTestBase
|
||||
{
|
||||
[Test]
|
||||
public void RouteDataExtensions_GetUmbracoContext()
|
||||
|
||||
Reference in New Issue
Block a user