Fixes more tests and more decoupling of singletons

This commit is contained in:
Shannon
2015-07-15 16:40:50 +02:00
parent 0efeba3744
commit 85ebcadcdd
6 changed files with 68 additions and 25 deletions

View File

@@ -60,6 +60,7 @@ namespace Umbraco.Core
[Obsolete("Use the other constructor specifying a ProfilingLogger instead")]
public ApplicationContext(CacheHelper cache)
{
if (cache == null) throw new ArgumentNullException("cache");
ApplicationCache = cache;
ProfilingLogger = new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler);
Init();

View File

@@ -30,7 +30,9 @@ namespace Umbraco.Tests
[Test]
public void Can_Create_Empty_App_Context()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
Assert.Pass();
}
@@ -63,7 +65,9 @@ namespace Umbraco.Tests
[Test]
public void Can_Assign_App_Context_Singleton()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var result = ApplicationContext.EnsureContext(appCtx, true);
Assert.AreEqual(appCtx, result);
}
@@ -71,8 +75,14 @@ namespace Umbraco.Tests
[Test]
public void Does_Not_Overwrite_App_Context_Singleton()
{
ApplicationContext.EnsureContext(new ApplicationContext(CacheHelper.CreateDisabledCacheHelper()), true);
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
ApplicationContext.EnsureContext(
new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>())), true);
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var result = ApplicationContext.EnsureContext(appCtx, false);
Assert.AreNotEqual(appCtx, result);
}
@@ -80,7 +90,9 @@ namespace Umbraco.Tests
[Test]
public void Can_Get_Umbraco_Context()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var umbCtx = UmbracoContext.EnsureContext(
Mock.Of<HttpContextBase>(),
@@ -96,7 +108,9 @@ namespace Umbraco.Tests
[Test]
public void Can_Mock_Umbraco_Helper()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var umbCtx = UmbracoContext.EnsureContext(
Mock.Of<HttpContextBase>(),
@@ -122,7 +136,9 @@ namespace Umbraco.Tests
[Test]
public void Can_Mock_Umbraco_Helper_Get_Url()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var umbCtx = UmbracoContext.EnsureContext(
Mock.Of<HttpContextBase>(),

View File

@@ -32,7 +32,9 @@ namespace Umbraco.Tests.Mvc
[Test]
public void Can_Construct_And_Get_Result()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var umbCtx = UmbracoContext.EnsureContext(
new Mock<HttpContextBase>().Object,
@@ -52,7 +54,10 @@ namespace Umbraco.Tests.Mvc
[Test]
public void Umbraco_Context_Not_Null()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
ApplicationContext.EnsureContext(appCtx, true);
var umbCtx = UmbracoContext.EnsureContext(
@@ -93,7 +98,9 @@ namespace Umbraco.Tests.Mvc
[Test]
public void Can_Lookup_Content()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var umbCtx = UmbracoContext.EnsureContext(
new Mock<HttpContextBase>().Object,
@@ -127,7 +134,9 @@ namespace Umbraco.Tests.Mvc
[Test]
public void Mock_Current_Page()
{
var appCtx = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper());
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
var webRoutingSettings = Mock.Of<IWebRoutingSection>(section => section.UrlProviderMode == "AutoLegacy");

View File

@@ -431,7 +431,12 @@ namespace Umbraco.Tests.Mvc
urlProvider);
umbracoContext.RoutingContext = routingContext;
var request = new PublishedContentRequest(new Uri("http://localhost/dang"), routingContext);
var request = new PublishedContentRequest(
new Uri("http://localhost/dang"),
routingContext,
settings.WebRouting,
s => Enumerable.Empty<string>());
request.Culture = CultureInfo.InvariantCulture;
umbracoContext.PublishedContentRequest = request;

View File

@@ -28,7 +28,9 @@ namespace Umbraco.Tests.Persistence
Mock.Of<ILogger>(), new SqlCeSyntaxProvider(), "System.Data.SqlServerCe.4.0");
//unfortunately we have to set this up because the PetaPocoExtensions require singleton access
ApplicationContext.Current = new ApplicationContext(CacheHelper.CreateDisabledCacheHelper())
ApplicationContext.Current = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()))
{
DatabaseContext = _dbContext,
IsReady = true

View File

@@ -29,14 +29,18 @@ namespace Umbraco.Tests
[Test]
public void SetApplicationUrlWhenNoSettings()
{
var appContext = new ApplicationContext(null)
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()))
{
UmbracoApplicationUrl = null // NOT set
};
ConfigurationManager.AppSettings.Set("umbracoUseSSL", "true"); // does not make a diff here
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger,
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger,
Mock.Of<IUmbracoSettingsSection>(
section =>
section.DistributedCall == Mock.Of<IDistributedCallSection>(callSection => callSection.Servers == Enumerable.Empty<IServer>())
@@ -45,17 +49,19 @@ namespace Umbraco.Tests
// still NOT set
Assert.IsNull(appContext._umbracoApplicationUrl);
Assert.IsNull(appCtx._umbracoApplicationUrl);
}
[Test]
public void SetApplicationUrlFromDcSettingsNoSsl()
{
var appContext = new ApplicationContext(null);
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
ConfigurationManager.AppSettings.Set("umbracoUseSSL", "false");
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger,
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger,
Mock.Of<IUmbracoSettingsSection>(
section =>
section.DistributedCall == Mock.Of<IDistributedCallSection>(callSection => callSection.Servers == Enumerable.Empty<IServer>())
@@ -63,17 +69,19 @@ namespace Umbraco.Tests
&& section.ScheduledTasks == Mock.Of<IScheduledTasksSection>(tasksSection => tasksSection.BaseUrl == "mycoolhost.com/hello/world/")));
Assert.AreEqual("http://mycoolhost.com/hello/world", appContext._umbracoApplicationUrl);
Assert.AreEqual("http://mycoolhost.com/hello/world", appCtx._umbracoApplicationUrl);
}
[Test]
public void SetApplicationUrlFromDcSettingsSsl()
{
var appContext = new ApplicationContext(null);
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
ConfigurationManager.AppSettings.Set("umbracoUseSSL", "true");
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger,
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger,
Mock.Of<IUmbracoSettingsSection>(
section =>
section.DistributedCall == Mock.Of<IDistributedCallSection>(callSection => callSection.Servers == Enumerable.Empty<IServer>())
@@ -81,17 +89,19 @@ namespace Umbraco.Tests
&& section.ScheduledTasks == Mock.Of<IScheduledTasksSection>(tasksSection => tasksSection.BaseUrl == "mycoolhost.com/hello/world")));
Assert.AreEqual("https://mycoolhost.com/hello/world", appContext._umbracoApplicationUrl);
Assert.AreEqual("https://mycoolhost.com/hello/world", appCtx._umbracoApplicationUrl);
}
[Test]
public void SetApplicationUrlFromWrSettingsSsl()
{
var appContext = new ApplicationContext(null);
var appCtx = new ApplicationContext(
CacheHelper.CreateDisabledCacheHelper(),
new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
ConfigurationManager.AppSettings.Set("umbracoUseSSL", "true"); // does not make a diff here
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger,
ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger,
Mock.Of<IUmbracoSettingsSection>(
section =>
section.DistributedCall == Mock.Of<IDistributedCallSection>(callSection => callSection.Servers == Enumerable.Empty<IServer>())
@@ -99,7 +109,7 @@ namespace Umbraco.Tests
&& section.ScheduledTasks == Mock.Of<IScheduledTasksSection>(tasksSection => tasksSection.BaseUrl == "mycoolhost.com/hello/world")));
Assert.AreEqual("httpx://whatever.com/hello/world", appContext._umbracoApplicationUrl);
Assert.AreEqual("httpx://whatever.com/hello/world", appCtx._umbracoApplicationUrl);
}
}
}