From fd91340e75bbaa89b5b5356c00356668b01a0656 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 13 Nov 2013 12:41:02 +1100 Subject: [PATCH] Updates DefaultShortStringHelperTests to ensure that umb config is mocked. --- .../DefaultShortStringHelperTests.cs | 10 ++++-- .../TestHelpers/BaseUmbracoApplicationTest.cs | 21 +++++------- .../BaseUmbracoConfigurationTest.cs | 34 +++++++++++++++++++ src/Umbraco.Tests/Umbraco.Tests.csproj | 1 + 4 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs diff --git a/src/Umbraco.Tests/CoreStrings/DefaultShortStringHelperTests.cs b/src/Umbraco.Tests/CoreStrings/DefaultShortStringHelperTests.cs index b9188730d7..17e583b635 100644 --- a/src/Umbraco.Tests/CoreStrings/DefaultShortStringHelperTests.cs +++ b/src/Umbraco.Tests/CoreStrings/DefaultShortStringHelperTests.cs @@ -6,17 +6,20 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Strings; using Umbraco.Core.ObjectResolution; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.CoreStrings { [TestFixture] - public class DefaultShortStringHelperTests + public class DefaultShortStringHelperTests : BaseUmbracoConfigurationTest { private DefaultShortStringHelper _helper; [SetUp] - public void Setup() + public override void Initialize() { + base.Initialize(); + // NOTE: it is not possible to configure the helper once it has been assigned // to the resolver and resolution has frozen. but, obviously, it is possible // to configure filters and then to alter these filters after resolution has @@ -37,8 +40,9 @@ namespace Umbraco.Tests.CoreStrings } [TearDown] - public void TearDown() + public override void TearDown() { + base.TearDown(); ShortStringHelperResolver.Reset(); } diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 760cf4514e..403a285209 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -1,7 +1,6 @@ using AutoMapper; using NUnit.Framework; using Umbraco.Core; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models.Mapping; using Umbraco.Core.ObjectResolution; using Umbraco.Core.Persistence; @@ -19,22 +18,16 @@ namespace Umbraco.Tests.TestHelpers /// ensures everything is torn down properly. /// [TestFixture] - public abstract class BaseUmbracoApplicationTest + public abstract class BaseUmbracoApplicationTest : BaseUmbracoConfigurationTest { [SetUp] - public virtual void Initialize() + public override void Initialize() { - TestHelper.SetupLog4NetForTests(); + base.Initialize(); + TestHelper.InitializeContentDirectories(); TestHelper.EnsureUmbracoSettingsConfig(); - //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; - //Create the legacy prop-eds mapping LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors(); @@ -46,8 +39,10 @@ namespace Umbraco.Tests.TestHelpers } [TearDown] - public virtual void TearDown() + public override void TearDown() { + base.TearDown(); + //reset settings SettingsForTests.Reset(); UmbracoContext.Current = null; @@ -72,7 +67,7 @@ namespace Umbraco.Tests.TestHelpers }); } - protected virtual IUmbracoSettingsSection UmbracoSettings { get; private set; } + /// /// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs new file mode 100644 index 0000000000..b5524cad0f --- /dev/null +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoConfigurationTest.cs @@ -0,0 +1,34 @@ +using NUnit.Framework; +using Umbraco.Core.Configuration.UmbracoSettings; + +namespace Umbraco.Tests.TestHelpers +{ + /// + /// A base test class that ensures that the umbraco configuration is mocked + /// + [TestFixture] + public abstract class BaseUmbracoConfigurationTest + { + [SetUp] + public virtual void Initialize() + { + TestHelper.SetupLog4NetForTests(); + + //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] + public virtual void TearDown() + { + //reset settings + SettingsForTests.Reset(); + } + + protected virtual IUmbracoSettingsSection UmbracoSettings { get; private set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 129eab4cfc..fef66e7ffa 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -379,6 +379,7 @@ +