Updated SettingsForTest to return mockable umbraco settings so we can set whatever we want. Fixing up unit tests. Removes calls to CleanUmbracoSettingsConfig and EnsureUmbracoSettingsConfig since we should be dealing with the mockable settings.

This commit is contained in:
Shannon
2013-09-16 19:33:21 +10:00
parent b043ee577f
commit 48db556d1b
17 changed files with 183 additions and 166 deletions

View File

@@ -13,10 +13,15 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
return new OptionalCommaDelimitedConfigurationElement(
(CommaDelimitedConfigurationElement)this["imageFileTypes"],
//set the default
new[] { "jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif" });
GetDefaultImageFileTypes());
}
}
internal static string[] GetDefaultImageFileTypes()
{
return new[] {"jpeg", "jpg", "gif", "bmp", "png", "tiff", "tif"};
}
[ConfigurationProperty("allowedAttributes")]
internal CommaDelimitedConfigurationElement ImageTagAllowedAttributes
{
@@ -61,5 +66,16 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
}
}
internal static ImagingAutoFillPropertiesCollection GetDefaultImageAutoFillProperties()
{
return new ImagingAutoFillPropertiesCollection
{
new ImagingAutoFillUploadFieldElement
{
Alias = "umbracoFile"
}
};
}
}
}

View File

@@ -47,7 +47,21 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
var urls = this[prop] as ConfigurationElement;
if (urls != null && urls.ElementInformation.IsPresent == false)
{
var dictionary = new Dictionary<char, string>()
_defaultUrlReplacing = new UrlReplacingElement()
{
CharCollection = GetDefaultCharReplacements()
};
return _defaultUrlReplacing;
}
return (UrlReplacingElement)this["urlReplacing"];
}
}
internal static CharCollection GetDefaultCharReplacements()
{
var dictionary = new Dictionary<char, string>()
{
{' ',"-"},
{'\"',""},
@@ -77,28 +91,19 @@ namespace Umbraco.Core.Configuration.UmbracoSettings
{'>',""}
};
//const string chars = @" ,"",',%,.,;,/,\,:,#,+,*,&,?,æ,ø,å,ä,ö,ü,ß,Ä,Ö,|,<,>";
//const string chars = @" ,"",',%,.,;,/,\,:,#,+,*,&,?,æ,ø,å,ä,ö,ü,ß,Ä,Ö,|,<,>";
var collection = new CharCollection();
foreach (var c in dictionary)
{
collection.Add(new CharElement
{
Char = c.Key.ToString(CultureInfo.InvariantCulture),
Replacement = c.Value.ToString(CultureInfo.InvariantCulture)
});
}
_defaultUrlReplacing = new UrlReplacingElement()
{
CharCollection = collection
};
return _defaultUrlReplacing;
}
return (UrlReplacingElement)this["urlReplacing"];
var collection = new CharCollection();
foreach (var c in dictionary)
{
collection.Add(new CharElement
{
Char = c.Key.ToString(CultureInfo.InvariantCulture),
Replacement = c.Value.ToString(CultureInfo.InvariantCulture)
});
}
return collection;
}
bool IRequestHandlerSection.UseDomainPrefixes

View File

@@ -425,7 +425,7 @@ namespace Umbraco.Core.Models
if (UmbracoConfiguration.Current.UmbracoSettings.Content.ImageAutoFillProperties != null)
{
uploadFieldConfigNode = UmbracoConfiguration.Current.UmbracoSettings.Content.ImageAutoFillProperties
.Single(x => x.Alias == propertyTypeAlias);
.FirstOrDefault(x => x.Alias == propertyTypeAlias);
}

View File

@@ -470,7 +470,7 @@ function isValidAlias(alias) {{
var newUrl = url.ToLowerInvariant();
foreach (var n in UmbracoConfiguration.Current.UmbracoSettings.RequestHandler.CharCollection)
{
if (n.Char.IsNullOrWhiteSpace() == false)
if (n.Char != "")
newUrl = newUrl.Replace(n.Char, n.Replacement);
}

View File

@@ -1,9 +1,58 @@
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="FileSystemProviders" type="Umbraco.Core.Configuration.FileSystemProvidersSection, Umbraco.Core" requirePermission="false"/>
</configSections>
<sectionGroup name="umbracoConfiguration">
<section name="FileSystemProviders" type="Umbraco.Core.Configuration.FileSystemProvidersSection, Umbraco.Core" requirePermission="false"/>
</sectionGroup>
</configSections>
<umbracoConfiguration>
<FileSystemProviders>
<Provider alias="media" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\Media\"/>
<add key="rootUrl" value="/Media/"/>
</Parameters>
</Provider>
<!-- Macros -->
<Provider alias="macros" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\App_Data\Macros"/>
<add key="rootUrl" value="/Macros/"/>
</Parameters>
</Provider>
<!-- Scripts -->
<Provider alias="scripts" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\scripts\"/>
<add key="rootUrl" value="/scripts/"/>
</Parameters>
</Provider>
<!-- Stylesheets -->
<Provider alias="stylesheets" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\css\"/>
<add key="rootUrl" value="/css/"/>
</Parameters>
</Provider>
<!-- Templates -->
<Provider alias="masterpages" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\masterpages\"/>
<add key="rootUrl" value="/masterpages/"/>
</Parameters>
</Provider>
<Provider alias="views" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\views\"/>
<add key="rootUrl" value="/views/"/>
</Parameters>
</Provider>
</FileSystemProviders>
</umbracoConfiguration>
<appSettings>
<add key="umbracoConfigurationStatus" value="6.0.0"/>
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd"/>
@@ -20,49 +69,6 @@
<add name="umbracoDbDSN" connectionString="Datasource=|DataDirectory|UmbracoPetaPocoTests.sdf;Flush Interval=1;File Access Retry Timeout=10" providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
<FileSystemProviders>
<Provider alias="media" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\Media\"/>
<add key="rootUrl" value="/Media/"/>
</Parameters>
</Provider>
<!-- Macros -->
<Provider alias="macros" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\App_Data\Macros"/>
<add key="rootUrl" value="/Macros/"/>
</Parameters>
</Provider>
<!-- Scripts -->
<Provider alias="scripts" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\scripts\"/>
<add key="rootUrl" value="/scripts/"/>
</Parameters>
</Provider>
<!-- Stylesheets -->
<Provider alias="stylesheets" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\css\"/>
<add key="rootUrl" value="/css/"/>
</Parameters>
</Provider>
<!-- Templates -->
<Provider alias="masterpages" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\masterpages\"/>
<add key="rootUrl" value="/masterpages/"/>
</Parameters>
</Provider>
<Provider alias="views" type="Umbraco.Core.IO.PhysicalFileSystem, Umbraco.Core">
<Parameters>
<add key="rootPath" value="\views\"/>
<add key="rootUrl" value="/views/"/>
</Parameters>
</Provider>
</FileSystemProviders>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0"/>

View File

@@ -7,6 +7,7 @@ using Umbraco.Tests.CodeFirst.TestModels;
using Umbraco.Tests.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Rhino.Mocks;
namespace Umbraco.Tests.CodeFirst
{
@@ -57,10 +58,8 @@ namespace Umbraco.Tests.CodeFirst
#region Test setup
public override void Initialize()
{
TestHelper.EnsureUmbracoSettingsConfig();
base.Initialize();
{
base.Initialize();
}
public override void TearDown()

View File

@@ -11,7 +11,7 @@ namespace Umbraco.Tests.Configurations
[Test]
public void Can_Get_Media_Provider()
{
var config = (FileSystemProvidersSection)ConfigurationManager.GetSection("FileSystemProviders");
var config = (FileSystemProvidersSection)ConfigurationManager.GetSection("umbracoConfiguration/FileSystemProviders");
var providerConfig = config.Providers["media"];
Assert.That(providerConfig, Is.Not.Null);

View File

@@ -29,7 +29,6 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings
}
else
{
//Section = configuration.GetSection("umbracoConfiguration/settings") as UmbracoSettingsSection;
SettingsSection = UmbracoConfiguration.For<IUmbracoSettingsSection>(configuration);
}

View File

@@ -3,15 +3,26 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using Umbraco.Core;
using Umbraco.Core.Strings;
using Umbraco.Core.ObjectResolution;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.CoreStrings
{
[TestFixture]
public class CmsHelperCasingTests
{
[SetUp]
public void Setup()
{
//set default config
var config = SettingsForTests.GetDefault();
SettingsForTests.ConfigureSettings(config);
}
[TestCase("thisIsTheEnd", "This Is The End")]
[TestCase("th", "Th")]
[TestCase("t", "t")]

View File

@@ -18,14 +18,14 @@ namespace Umbraco.Tests.CoreStrings
[SetUp]
public void Setup()
{
TestHelper.EnsureUmbracoSettingsConfig();
var config = SettingsForTests.GetDefault();
SettingsForTests.ConfigureSettings(config);
_helper = new LegacyShortStringHelper();
}
[TearDown]
public void TearDown()
{
TestHelper.CleanUmbracoSettingsConfig();
}

View File

@@ -5,12 +5,21 @@ using System.Linq;
using System.Text;
using NUnit.Framework;
using Umbraco.Core.IO;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.IO
{
[TestFixture]
public class FileSystemProviderManagerTests
{
[SetUp]
public void Setup()
{
//init the config singleton
var config = SettingsForTests.GetDefault();
SettingsForTests.ConfigureSettings(config);
}
[Test]
public void Can_Get_Base_File_System()
{
@@ -33,7 +42,6 @@ namespace Umbraco.Tests.IO
Assert.Throws<InvalidOperationException>(() => FileSystemProviderManager.Current.GetFileSystemProvider<InvalidTypedFileSystem>());
}
#region
/// <summary>
/// Used in unit tests, for a typed file system we need to inherit from FileSystemWrapper and they MUST have a ctor
@@ -46,6 +54,5 @@ namespace Umbraco.Tests.IO
}
}
#endregion
}
}

View File

@@ -17,13 +17,14 @@ namespace Umbraco.Tests.Models
[SetUp]
public void Init()
{
TestHelper.EnsureUmbracoSettingsConfig();
var config = SettingsForTests.GetDefault();
SettingsForTests.ConfigureSettings(config);
}
[TearDown]
public void Dispose()
{
TestHelper.CleanUmbracoSettingsConfig();
}
[TestCase("-1,-20,12,34,56", false)]

View File

@@ -32,14 +32,14 @@ namespace Umbraco.Tests.TestHelpers
TestHelper.EnsureUmbracoSettingsConfig();
//mock the Umbraco settings that we need
//var settings = MockRepository.GenerateStub<IUmbracoSettings>();
var settings = SettingsForTests.GetDefault();
settings.Stub(x => x.Content.UseLegacyXmlSchema).Return(false);
settings.Stub(x => x.Content.ForceSafeAliases).Return(true);
settings.Stub(x => x.Content.UmbracoLibraryCacheDuration).Return(1800);
SettingsForTests.ConfigureSettings(settings);
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();
@@ -77,6 +77,8 @@ namespace Umbraco.Tests.TestHelpers
});
}
protected virtual IUmbracoSettingsSection UmbracoSettings { get; private set; }
/// <summary>
/// By default this returns false which means the plugin manager will not be reset so it doesn't need to re-scan
/// all of the assemblies. Inheritors can override this if plugin manager resetting is required, generally needs

View File

@@ -24,83 +24,59 @@ namespace Umbraco.Tests.TestHelpers
UmbracoConfiguration.Current.UmbracoSettings = settings;
}
///// <summary>
///// Returns generated settings which can be stubbed to return whatever values necessary
///// </summary>
///// <returns></returns>
//public static IUmbracoSettings GetMockSettings()
//{
// var settings = MockRepository.GenerateMock<IUmbracoSettings>();
/// <summary>
/// Returns generated settings which can be stubbed to return whatever values necessary
/// </summary>
/// <returns></returns>
public static IUmbracoSettingsSection GetMockSettings()
{
var settings = MockRepository.GenerateStub<IUmbracoSettingsSection>();
// var content = MockRepository.GenerateMock<IContent>();
// var security = MockRepository.GenerateMock<ISecurity>();
// var requestHandler = MockRepository.GenerateMock<IRequestHandler>();
// var templates = MockRepository.GenerateMock<ITemplates>();
// var dev = MockRepository.GenerateMock<IDeveloper>();
// var viewStateMover = MockRepository.GenerateMock<IViewstateMoverModule>();
// var logging = MockRepository.GenerateMock<ILogging>();
// var tasks = MockRepository.GenerateMock<IScheduledTasks>();
// var distCall = MockRepository.GenerateMock<IDistributedCall>();
// var repos = MockRepository.GenerateMock<IRepositories>();
// var providers = MockRepository.GenerateMock<IProviders>();
// var help = MockRepository.GenerateMock<IHelp>();
// var routing = MockRepository.GenerateMock<IWebRouting>();
// var scripting = MockRepository.GenerateMock<IScripting>();
var content = MockRepository.GenerateStub<IContentSection>();
var security = MockRepository.GenerateStub<ISecuritySection>();
var requestHandler = MockRepository.GenerateStub<IRequestHandlerSection>();
var templates = MockRepository.GenerateStub<ITemplatesSection>();
var dev = MockRepository.GenerateStub<IDeveloperSection>();
var viewStateMover = MockRepository.GenerateStub<IViewStateMoverModuleSection>();
var logging = MockRepository.GenerateStub<ILoggingSection>();
var tasks = MockRepository.GenerateStub<IScheduledTasksSection>();
var distCall = MockRepository.GenerateStub<IDistributedCallSection>();
var repos = MockRepository.GenerateStub<IRepositoriesSection>();
var providers = MockRepository.GenerateStub<IProvidersSection>();
var help = MockRepository.GenerateStub<IHelpSection>();
var routing = MockRepository.GenerateStub<IWebRoutingSection>();
var scripting = MockRepository.GenerateStub<IScriptingSection>();
// settings.Stub(x => x.Content).Return(content);
// settings.Stub(x => x.Security).Return(security);
// settings.Stub(x => x.RequestHandler).Return(requestHandler);
// settings.Stub(x => x.Templates).Return(templates);
// settings.Stub(x => x.Developer).Return(dev);
// settings.Stub(x => x.ViewstateMoverModule).Return(viewStateMover);
// settings.Stub(x => x.Logging).Return(logging);
// settings.Stub(x => x.ScheduledTasks).Return(tasks);
// settings.Stub(x => x.DistributedCall).Return(distCall);
// settings.Stub(x => x.PackageRepositories).Return(repos);
// settings.Stub(x => x.Providers).Return(providers);
// settings.Stub(x => x.Help).Return(help);
// settings.Stub(x => x.WebRouting).Return(routing);
// settings.Stub(x => x.Scripting).Return(scripting);
settings.Stub(x => x.Content).Return(content);
settings.Stub(x => x.Security).Return(security);
settings.Stub(x => x.RequestHandler).Return(requestHandler);
settings.Stub(x => x.Templates).Return(templates);
settings.Stub(x => x.Developer).Return(dev);
settings.Stub(x => x.ViewStateMoverModule).Return(viewStateMover);
settings.Stub(x => x.Logging).Return(logging);
settings.Stub(x => x.ScheduledTasks).Return(tasks);
settings.Stub(x => x.DistributedCall).Return(distCall);
settings.Stub(x => x.PackageRepositories).Return(repos);
settings.Stub(x => x.Providers).Return(providers);
settings.Stub(x => x.Help).Return(help);
settings.Stub(x => x.WebRouting).Return(routing);
settings.Stub(x => x.Scripting).Return(scripting);
// return settings;
//}
//Now configure some defaults - the defaults in the config section classes do NOT pertain to the mocked data!!
settings.Content.Stub(x => x.UseLegacyXmlSchema).Return(false);
settings.Content.Stub(x => x.ForceSafeAliases).Return(true);
settings.Content.Stub(x => x.ImageAutoFillProperties).Return(ContentImagingElement.GetDefaultImageAutoFillProperties());
settings.Content.Stub(x => x.ImageFileTypes).Return(ContentImagingElement.GetDefaultImageFileTypes());
settings.RequestHandler.Stub(x => x.AddTrailingSlash).Return(true);
settings.RequestHandler.Stub(x => x.UseDomainPrefixes).Return(false);
settings.RequestHandler.Stub(x => x.CharCollection).Return(RequestHandlerElement.GetDefaultCharReplacements());
settings.Content.Stub(x => x.UmbracoLibraryCacheDuration).Return(1800);
settings.WebRouting.Stub(x => x.UrlProviderMode).Return("Auto");
//public static int UmbracoLibraryCacheDuration
//{
// get { return LegacyUmbracoSettings.UmbracoLibraryCacheDuration; }
// set { LegacyUmbracoSettings.UmbracoLibraryCacheDuration = value; }
//}
//public static bool UseLegacyXmlSchema
//{
// get { return LegacyUmbracoSettings.UseLegacyXmlSchema; }
// set { LegacyUmbracoSettings.UseLegacyXmlSchema = value; }
//}
//public static bool AddTrailingSlash
//{
// get { return LegacyUmbracoSettings.AddTrailingSlash; }
// set { LegacyUmbracoSettings.AddTrailingSlash = value; }
//}
//public static bool UseDomainPrefixes
//{
// get { return LegacyUmbracoSettings.UseDomainPrefixes; }
// set { LegacyUmbracoSettings.UseDomainPrefixes = value; }
//}
//public static string SettingsFilePath
//{
// get { return LegacyUmbracoSettings.SettingsFilePath; }
// set { LegacyUmbracoSettings.SettingsFilePath = value; }
//}
//public static bool ForceSafeAliases
//{
// get { return LegacyUmbracoSettings.ForceSafeAliases; }
// set { LegacyUmbracoSettings.ForceSafeAliases = value; }
//}
return settings;
}
// from appSettings

View File

@@ -28,11 +28,6 @@ namespace Umbraco.Web.Routing
var provider = UrlProviderMode.Auto;
Mode = provider;
//if (Enum<UrlProviderMode>.TryParse(UmbracoConfiguration.For<IWebRouting>(), out provider))
//{
//}
if (Enum<UrlProviderMode>.TryParse(UmbracoConfiguration.Current.UmbracoSettings.WebRouting.UrlProviderMode, out provider))
{
Mode = provider;

View File

@@ -53,6 +53,7 @@ namespace Umbraco.Web.Trees
[DataMember(Name = "name")]
public string Title { get; set; }
//TODO: This doesn't seem to be used by anything!
/// <summary>
/// Gets or sets the node path.
/// </summary>

View File

@@ -619,12 +619,11 @@ namespace umbraco
private static string _path;
/// <summary>
/// Gets/sets the settings file path, the setter can be used in unit tests
/// Gets the settings file path
/// </summary>
internal static string SettingsFilePath
{
get { return _path ?? (_path = GlobalSettings.FullpathToRoot + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar); }
set { _path = value; }
}
internal const string Filename = "umbracoSettings.config";