Tests - cleanup settings handling for more reliable tests
This commit is contained in:
@@ -25,11 +25,8 @@ namespace Umbraco.Core.Configuration
|
||||
/// </summary>
|
||||
internal class UmbracoSettings
|
||||
{
|
||||
private static bool GetKeyWithOverride(string key, bool defaultValue, bool? overrideValue)
|
||||
private static bool GetKeyValue(string key, bool defaultValue)
|
||||
{
|
||||
if (overrideValue.HasValue)
|
||||
return overrideValue.Value;
|
||||
|
||||
bool value;
|
||||
string stringValue = GetKey(key);
|
||||
|
||||
@@ -40,11 +37,8 @@ namespace Umbraco.Core.Configuration
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static int GetKeyWithOverride(string key, int defaultValue, int? overrideValue)
|
||||
private static int GetKeyValue(string key, int defaultValue)
|
||||
{
|
||||
if (overrideValue.HasValue)
|
||||
return overrideValue.Value;
|
||||
|
||||
int value;
|
||||
string stringValue = GetKey(key);
|
||||
|
||||
@@ -405,7 +399,7 @@ namespace Umbraco.Core.Configuration
|
||||
get
|
||||
{
|
||||
// default: false
|
||||
return GetKeyWithOverride("/settings/requestHandler/useDomainPrefixes", false, _useDomainPrefixes);
|
||||
return _useDomainPrefixes ?? GetKeyValue("/settings/requestHandler/useDomainPrefixes", false);
|
||||
}
|
||||
internal set
|
||||
{
|
||||
@@ -426,7 +420,7 @@ namespace Umbraco.Core.Configuration
|
||||
{
|
||||
// default: false
|
||||
return GlobalSettings.UseDirectoryUrls
|
||||
&& GetKeyWithOverride("/settings/requestHandler/addTrailingSlash", false, _addTrailingSlash);
|
||||
&& (_addTrailingSlash ?? GetKeyValue("/settings/requestHandler/addTrailingSlash", false));
|
||||
}
|
||||
internal set
|
||||
{
|
||||
@@ -649,7 +643,7 @@ namespace Umbraco.Core.Configuration
|
||||
get
|
||||
{
|
||||
// default: true
|
||||
return GetKeyWithOverride("/settings/content/ForceSafeAliases", true, _forceSafeAliases);
|
||||
return _forceSafeAliases ?? GetKeyValue("/settings/content/ForceSafeAliases", true);
|
||||
}
|
||||
internal set
|
||||
{
|
||||
@@ -668,7 +662,7 @@ namespace Umbraco.Core.Configuration
|
||||
get
|
||||
{
|
||||
// default: false
|
||||
return GetKeyWithOverride("/settings/web.routing/@trySkipIisCustomErrors", false, _trySkipIisCustomErrors);
|
||||
return _trySkipIisCustomErrors ?? GetKeyValue("/settings/web.routing/@trySkipIisCustomErrors", false);
|
||||
}
|
||||
internal set
|
||||
{
|
||||
@@ -706,7 +700,7 @@ namespace Umbraco.Core.Configuration
|
||||
get
|
||||
{
|
||||
// default: 1800
|
||||
return GetKeyWithOverride("/settings/content/UmbracoLibraryCacheDuration", 1800, _umbracoLibraryCacheDuration);
|
||||
return _umbracoLibraryCacheDuration ?? GetKeyValue("/settings/content/UmbracoLibraryCacheDuration", 1800);
|
||||
}
|
||||
internal set
|
||||
{
|
||||
@@ -1069,11 +1063,11 @@ namespace Umbraco.Core.Configuration
|
||||
get
|
||||
{
|
||||
// default: true
|
||||
return GetKeyWithOverride("/settings/content/UseLegacyXmlSchema", true, _useLegacySchema);
|
||||
return _useLegacySchema ?? GetKeyValue("/settings/content/UseLegacyXmlSchema", true);
|
||||
}
|
||||
internal set
|
||||
{
|
||||
// used for unit testing
|
||||
// used for unit testing
|
||||
_useLegacySchema = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,6 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class ContentFinderByAliasTests : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We don't need a db for this test, will run faster without one
|
||||
/// </summary>
|
||||
|
||||
@@ -9,12 +9,6 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class ContentFinderByNiceUrlAndTemplateTests : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
Template CreateTemplate(string alias)
|
||||
{
|
||||
var template = new Template(alias, alias, alias);
|
||||
|
||||
@@ -10,12 +10,6 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class ContentFinderByNiceUrlTests : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We don't need a db for this test, will run faster without one
|
||||
/// </summary>
|
||||
@@ -41,7 +35,7 @@ namespace Umbraco.Tests.Routing
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docreq = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
SettingsForTests.HideTopLevelNodeFromPath = true;
|
||||
|
||||
var result = lookup.TryFindDocument(docreq);
|
||||
|
||||
@@ -68,7 +62,7 @@ namespace Umbraco.Tests.Routing
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docreq = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
var result = lookup.TryFindDocument(docreq);
|
||||
|
||||
|
||||
@@ -22,16 +22,8 @@ namespace Umbraco.Tests.Routing
|
||||
TestHelper.DropForeignKeys("umbracoDomains");
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void InitializeLanguagesAndDomains()
|
||||
{
|
||||
var domains = Domain.GetDomains();
|
||||
@@ -158,7 +150,7 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
SetDomains3();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
SettingsForTests.HideTopLevelNodeFromPath = true;
|
||||
|
||||
var routingContext = GetRoutingContext(url);
|
||||
var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
@@ -196,7 +188,7 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
SetDomains4();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
SettingsForTests.HideTopLevelNodeFromPath = true;
|
||||
|
||||
var routingContext = GetRoutingContext(url);
|
||||
var uri = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
|
||||
@@ -25,18 +25,7 @@ namespace Umbraco.Tests.Routing
|
||||
Path.Combine(currDir.Parent.Parent.FullName, "config", "umbracoSettings.config"),
|
||||
true);
|
||||
|
||||
Core.Configuration.UmbracoSettings.SettingsFilePath = Core.IO.IOHelper.MapPath(Core.IO.SystemDirectories.Config + Path.DirectorySeparatorChar, false);
|
||||
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
SettingsForTests.SettingsFilePath = Core.IO.IOHelper.MapPath(Core.IO.SystemDirectories.Config + Path.DirectorySeparatorChar, false);
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
@@ -52,18 +41,19 @@ namespace Umbraco.Tests.Routing
|
||||
public void Ensure_Cache_Is_Correct()
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
Umbraco.Core.Configuration.UmbracoSettings.AddTrailingSlash = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
SettingsForTests.AddTrailingSlash = false; // (cached routes have none)
|
||||
|
||||
var samples = new Dictionary<int, string> {
|
||||
{ 1046, "/home" },
|
||||
{ 1173, "/home/sub1/" },
|
||||
{ 1174, "/home/sub1/sub2/" },
|
||||
{ 1176, "/home/sub1/sub-3/" },
|
||||
{ 1177, "/home/sub1/custom-sub-1/" },
|
||||
{ 1178, "/home/sub1/custom-sub-2/" },
|
||||
{ 1175, "/home/sub-2/" },
|
||||
{ 1172, "/test-page/" }
|
||||
{ 1173, "/home/sub1" },
|
||||
{ 1174, "/home/sub1/sub2" },
|
||||
{ 1176, "/home/sub1/sub-3" },
|
||||
{ 1177, "/home/sub1/custom-sub-1" },
|
||||
{ 1178, "/home/sub1/custom-sub-2" },
|
||||
{ 1175, "/home/sub-2" },
|
||||
{ 1172, "/test-page" }
|
||||
};
|
||||
|
||||
foreach (var sample in samples)
|
||||
@@ -72,7 +62,7 @@ namespace Umbraco.Tests.Routing
|
||||
Assert.AreEqual(sample.Value, result);
|
||||
}
|
||||
|
||||
var randomSample = new KeyValuePair<int, string>(1177, "/home/sub1/custom-sub-1/");
|
||||
var randomSample = new KeyValuePair<int, string>(1177, "/home/sub1/custom-sub-1");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(randomSample.Key);
|
||||
@@ -112,9 +102,9 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
@@ -135,9 +125,9 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = true;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
var result = routingContext.NiceUrlProvider.GetNiceUrl(nodeId);
|
||||
Assert.AreEqual(niceUrlMatch, result);
|
||||
@@ -148,16 +138,16 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("http://example.com/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
Assert.AreEqual("/home/sub1/custom-sub-1/", routingContext.NiceUrlProvider.GetNiceUrl(1177));
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = true;
|
||||
SettingsForTests.UseDomainPrefixes = true;
|
||||
Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", routingContext.NiceUrlProvider.GetNiceUrl(1177));
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
|
||||
Assert.AreEqual("http://example.com/home/sub1/custom-sub-1/", routingContext.NiceUrlProvider.GetNiceUrl(1177));
|
||||
}
|
||||
@@ -167,14 +157,14 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("http://example.com/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
Assert.AreEqual("#", routingContext.NiceUrlProvider.GetNiceUrl(999999));
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = true;
|
||||
SettingsForTests.UseDomainPrefixes = true;
|
||||
Assert.AreEqual("#", routingContext.NiceUrlProvider.GetNiceUrl(999999));
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
|
||||
Assert.AreEqual("#", routingContext.NiceUrlProvider.GetNiceUrl(999999));
|
||||
}
|
||||
|
||||
@@ -22,14 +22,6 @@ namespace Umbraco.Tests.Routing
|
||||
TestHelper.DropForeignKeys("umbracoDomains");
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
{
|
||||
return new DefaultRoutesCache(false);
|
||||
@@ -203,9 +195,9 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains1();
|
||||
@@ -232,9 +224,9 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains2();
|
||||
@@ -253,9 +245,9 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains3();
|
||||
@@ -279,11 +271,11 @@ namespace Umbraco.Tests.Routing
|
||||
public void Get_Nice_Url_NestedDomains(int nodeId, string currentUrl, bool absolute, string expected)
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
|
||||
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains4();
|
||||
|
||||
@@ -297,9 +289,9 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains4();
|
||||
@@ -356,22 +348,22 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("http://domain1.com/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains4();
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
Assert.AreEqual("/en/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111));
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
Assert.AreEqual("/en/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100311));
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = true;
|
||||
Assert.AreEqual("http://domain1.com/en/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111));
|
||||
SettingsForTests.UseDomainPrefixes = true;
|
||||
Assert.AreEqual("http://domain1.com/en/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100311));
|
||||
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
routingContext.NiceUrlProvider.EnforceAbsoluteUrls = true;
|
||||
Assert.AreEqual("http://domain1.com/en/1001-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100111));
|
||||
Assert.AreEqual("http://domain3.com/en/1003-1-1/", routingContext.NiceUrlProvider.GetNiceUrl(100311));
|
||||
}
|
||||
@@ -381,8 +373,8 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext("http://domain1.com/test", 1111);
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains5();
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
base.Initialize();
|
||||
|
||||
System.Configuration.ConfigurationManager.AppSettings.Set("umbracoPath", "~/umbraco");
|
||||
SettingsForTests.UmbracoPath = "~/umbraco";
|
||||
|
||||
var webBoot = new WebBootManager(new UmbracoApplication(), true);
|
||||
//webBoot.Initialize();
|
||||
@@ -40,7 +40,6 @@ namespace Umbraco.Tests.Routing
|
||||
base.TearDown();
|
||||
UmbracoContext.Current = null;
|
||||
RouteTable.Routes.Clear();
|
||||
System.Configuration.ConfigurationManager.AppSettings.Set("umbracoPath", "");
|
||||
SurfaceControllerResolver.Reset();
|
||||
PluginManager.Current = null;
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ namespace Umbraco.Tests.Routing
|
||||
//create the module
|
||||
_module = new UmbracoModule();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoConfigurationStatus", UmbracoVersion.Current.ToString(3));
|
||||
ConfigurationManager.AppSettings.Set("umbracoReservedPaths", "~/umbraco,~/install/");
|
||||
ConfigurationManager.AppSettings.Set("umbracoReservedUrls", "~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd");
|
||||
SettingsForTests.ConfigurationStatus = UmbracoVersion.Current.ToString(3);
|
||||
SettingsForTests.ReservedPaths = "~/umbraco,~/install/";
|
||||
SettingsForTests.ReservedUrls = "~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd";
|
||||
|
||||
//create the not found handlers config
|
||||
using (var sw = File.CreateText(Umbraco.Core.IO.IOHelper.MapPath(Umbraco.Core.IO.SystemFiles.NotFoundhandlersConfig, false)))
|
||||
@@ -52,11 +52,6 @@ namespace Umbraco.Tests.Routing
|
||||
base.TearDown();
|
||||
|
||||
_module.DisposeIfDisposable();
|
||||
|
||||
//reset the app config
|
||||
ConfigurationManager.AppSettings.Set("umbracoConfigurationStatus", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoReservedPaths", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoReservedUrls", "");
|
||||
}
|
||||
|
||||
// do not test for /base here as it's handled before EnsureUmbracoRoutablePage is called
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace Umbraco.Tests.Routing
|
||||
[Test]
|
||||
public void DoNotPolluteCache()
|
||||
{
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false"); // ignored w/domains
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false; // ignored w/domains
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
InitializeLanguagesAndDomains();
|
||||
SetDomains1();
|
||||
@@ -71,15 +71,6 @@ namespace Umbraco.Tests.Routing
|
||||
TestHelper.DropForeignKeys("umbracoDomains");
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
{
|
||||
return new DefaultRoutesCache(false);
|
||||
|
||||
@@ -16,14 +16,6 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class uQueryGetNodeIdByUrlTests : BaseRoutingTest
|
||||
{
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
{
|
||||
return new DefaultRoutesCache(false);
|
||||
@@ -71,10 +63,9 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
public void GetNodeIdByUrl_Not_Hiding_Top_Level_Absolute(int nodeId, string url)
|
||||
{
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl("http://example.com" + url));
|
||||
}
|
||||
@@ -90,9 +81,9 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
public void GetNodeIdByUrl_Not_Hiding_Top_Level_Relative(int nodeId, string url)
|
||||
{
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "false");
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseDomainPrefixes = false;
|
||||
SettingsForTests.UseDirectoryUrls = true;
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
SettingsForTests.UseDomainPrefixes = false;
|
||||
|
||||
Assert.AreEqual(nodeId, global::umbraco.uQuery.GetNodeIdByUrl(url));
|
||||
}
|
||||
|
||||
@@ -13,18 +13,6 @@ namespace Umbraco.Tests.TestHelpers
|
||||
[TestFixture, RequiresSTA]
|
||||
public abstract class BaseRoutingTest : BaseWebTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a new RoutingContext
|
||||
/// </summary>
|
||||
|
||||
@@ -31,15 +31,14 @@ namespace Umbraco.Tests.TestHelpers
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
|
||||
SettingsForTests.Reset();
|
||||
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
TestHelper.InitializeContentDirectories();
|
||||
|
||||
string path = TestHelper.CurrentAssemblyDirectory;
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", path);
|
||||
|
||||
UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
|
||||
RepositoryResolver.Current = new RepositoryResolver(
|
||||
new RepositoryFactory());
|
||||
|
||||
@@ -138,7 +137,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
|
||||
Cache.ClearAllCache();
|
||||
|
||||
UmbracoSettings.ResetSetters();
|
||||
SettingsForTests.Reset();
|
||||
|
||||
PluginManager.Current = null;
|
||||
}
|
||||
|
||||
114
src/Umbraco.Tests/TestHelpers/SettingsForTests.cs
Normal file
114
src/Umbraco.Tests/TestHelpers/SettingsForTests.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
using Umbraco.Core.Configuration;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers
|
||||
{
|
||||
class SettingsForTests
|
||||
{
|
||||
// umbracoSettings
|
||||
|
||||
public static bool UseLegacyXmlSchema
|
||||
{
|
||||
get { return UmbracoSettings.UseLegacyXmlSchema; }
|
||||
set { UmbracoSettings.UseLegacyXmlSchema = value; }
|
||||
}
|
||||
|
||||
public static bool AddTrailingSlash
|
||||
{
|
||||
get { return UmbracoSettings.AddTrailingSlash; }
|
||||
set { UmbracoSettings.AddTrailingSlash = value; }
|
||||
}
|
||||
|
||||
public static bool UseDomainPrefixes
|
||||
{
|
||||
get { return UmbracoSettings.UseDomainPrefixes; }
|
||||
set { UmbracoSettings.UseDomainPrefixes = value; }
|
||||
}
|
||||
|
||||
public static string SettingsFilePath
|
||||
{
|
||||
get { return UmbracoSettings.SettingsFilePath; }
|
||||
set { UmbracoSettings.SettingsFilePath = value; }
|
||||
}
|
||||
|
||||
// from appSettings
|
||||
|
||||
private static readonly IDictionary<string, string> SavedAppSettings = new Dictionary<string, string>();
|
||||
|
||||
static void SaveSetting(string key)
|
||||
{
|
||||
SavedAppSettings[key] = ConfigurationManager.AppSettings[key];
|
||||
}
|
||||
|
||||
static void SaveSettings()
|
||||
{
|
||||
SaveSetting("umbracoHideTopLevelNodeFromPath");
|
||||
SaveSetting("umbracoUseDirectoryUrls");
|
||||
SaveSetting("umbracoPath");
|
||||
SaveSetting("umbracoReservedPaths");
|
||||
SaveSetting("umbracoReservedUrls");
|
||||
SaveSetting("umbracoConfigurationStatus");
|
||||
|
||||
SaveSetting(GlobalSettings.UmbracoConnectionName);
|
||||
}
|
||||
|
||||
public static bool HideTopLevelNodeFromPath
|
||||
{
|
||||
get { return GlobalSettings.HideTopLevelNodeFromPath; }
|
||||
set { ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", value ? "true" : "false"); }
|
||||
}
|
||||
|
||||
public static bool UseDirectoryUrls
|
||||
{
|
||||
get { return GlobalSettings.UseDirectoryUrls; }
|
||||
set { ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", value ? "true" : "false"); }
|
||||
}
|
||||
|
||||
public static string UmbracoPath
|
||||
{
|
||||
get { return GlobalSettings.Path; }
|
||||
set { ConfigurationManager.AppSettings.Set("umbracoPath", value); }
|
||||
}
|
||||
|
||||
public static string ReservedPaths
|
||||
{
|
||||
get { return GlobalSettings.ReservedPaths; }
|
||||
set { ConfigurationManager.AppSettings.Set("umbracoReservedPaths", value); }
|
||||
}
|
||||
|
||||
public static string ReservedUrls
|
||||
{
|
||||
get { return GlobalSettings.ReservedUrls; }
|
||||
set { ConfigurationManager.AppSettings.Set("umbracoReservedUrls", value); }
|
||||
}
|
||||
|
||||
public static string ConfigurationStatus
|
||||
{
|
||||
get { return GlobalSettings.ConfigurationStatus; }
|
||||
set { ConfigurationManager.AppSettings.Set("umbracoConfigurationStatus", value); }
|
||||
}
|
||||
|
||||
// reset & defaults
|
||||
|
||||
static SettingsForTests()
|
||||
{
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
UmbracoSettings.ResetSetters();
|
||||
|
||||
foreach (var kvp in SavedAppSettings)
|
||||
ConfigurationManager.AppSettings.Set(kvp.Key, kvp.Value);
|
||||
|
||||
// set some defaults that are wrong in the config file?!
|
||||
// this is annoying, really
|
||||
HideTopLevelNodeFromPath = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,6 +285,7 @@
|
||||
<Compile Include="TestHelpers\Entities\MockedContentTypes.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedEntity.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedMedia.cs" />
|
||||
<Compile Include="TestHelpers\SettingsForTests.cs" />
|
||||
<Compile Include="UmbracoExamine\ContentServiceTest.cs" />
|
||||
<Compile Include="UmbracoExamine\EventsTest.cs" />
|
||||
<Compile Include="UmbracoExamine\IndexInitializer.cs" />
|
||||
|
||||
Reference in New Issue
Block a user