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 LookupByAliasTests : 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 LookupByNiceUrlAndTemplateTests : BaseRoutingTest
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
[TestCase("/blah")]
|
||||
[TestCase("/default.aspx/blah")] //this one is actually rather important since this is the path that comes through when we are running in pre-IIS 7 for the root document '/' !
|
||||
[TestCase("/home/Sub1/blah")]
|
||||
|
||||
@@ -10,12 +10,6 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class LookupByNiceUrlTests : 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 LookupByNiceUrl();
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "true");
|
||||
SettingsForTests.HideTopLevelNodeFromPath = true;
|
||||
|
||||
var result = lookup.TrySetDocument(docreq);
|
||||
|
||||
@@ -68,7 +62,8 @@ 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 LookupByNiceUrl();
|
||||
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
var result = lookup.TrySetDocument(docreq);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
|
||||
@@ -18,16 +18,8 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
base.Initialize();
|
||||
InitializeLanguagesAndDomains();
|
||||
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = false;
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void InitializeLanguagesAndDomains()
|
||||
{
|
||||
var domains = Domain.GetDomains();
|
||||
@@ -154,7 +146,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
|
||||
@@ -193,7 +185,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()
|
||||
@@ -53,17 +42,19 @@ namespace Umbraco.Tests.Routing
|
||||
public void Ensure_Cache_Is_Correct()
|
||||
{
|
||||
var routingContext = GetRoutingContext("/test", 1111);
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "true");
|
||||
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 +63,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 +103,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 +126,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 +139,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 +158,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));
|
||||
}
|
||||
|
||||
@@ -14,20 +14,11 @@ namespace Umbraco.Tests.Routing
|
||||
[TestFixture]
|
||||
public class NiceUrlsProviderWithDomainsTests : BaseRoutingTest
|
||||
{
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
ConfigurationManager.AppSettings.Set("umbracoUseDirectoryUrls", "");
|
||||
ConfigurationManager.AppSettings.Set("umbracoHideTopLevelNodeFromPath", "");
|
||||
}
|
||||
|
||||
internal override IRoutesCache GetRoutesCache()
|
||||
{
|
||||
return new DefaultRoutesCache(false);
|
||||
}
|
||||
|
||||
|
||||
void InitializeLanguagesAndDomains()
|
||||
{
|
||||
var domains = Domain.GetDomains();
|
||||
@@ -195,9 +186,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();
|
||||
@@ -224,9 +215,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();
|
||||
@@ -245,9 +236,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();
|
||||
@@ -271,11 +262,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();
|
||||
|
||||
@@ -289,9 +280,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();
|
||||
@@ -348,22 +339,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));
|
||||
}
|
||||
@@ -373,8 +364,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();
|
||||
|
||||
@@ -27,7 +27,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();
|
||||
RouteTable.Routes.Clear();
|
||||
System.Configuration.ConfigurationManager.AppSettings.Set("umbracoPath", "");
|
||||
SurfaceControllerResolver.Reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,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)))
|
||||
@@ -79,11 +79,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();
|
||||
@@ -64,15 +64,6 @@ namespace Umbraco.Tests.Routing
|
||||
//Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -70,10 +62,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));
|
||||
}
|
||||
@@ -89,9 +80,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>
|
||||
|
||||
@@ -24,7 +24,9 @@ namespace Umbraco.Tests.TestHelpers
|
||||
[SetUp]
|
||||
public virtual void Initialize()
|
||||
{
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
SettingsForTests.Reset();
|
||||
|
||||
TestHelper.SetupLog4NetForTests();
|
||||
TestHelper.InitializeContentDirectories();
|
||||
|
||||
AppDomain.CurrentDomain.SetData("DataDirectory", TestHelper.CurrentAssemblyDirectory);
|
||||
@@ -66,7 +68,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
|
||||
Cache.ClearAllCache();
|
||||
|
||||
UmbracoSettings.ResetSetters();
|
||||
SettingsForTests.Reset();
|
||||
}
|
||||
|
||||
protected virtual void CreateDirectories(string[] directories)
|
||||
|
||||
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="TestHelpers\ExamineHelpers\IndexInitializer.cs" />
|
||||
<Compile Include="UriUtilityTests.cs" />
|
||||
<Compile Include="Resolvers\MacroFieldEditorsResolverTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user