diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs index 5a3359c677..7e306a6361 100644 --- a/src/Umbraco.Core/ApplicationContext.cs +++ b/src/Umbraco.Core/ApplicationContext.cs @@ -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(); diff --git a/src/Umbraco.Tests/MockTests.cs b/src/Umbraco.Tests/MockTests.cs index dcb590889b..d9a8ef785e 100644 --- a/src/Umbraco.Tests/MockTests.cs +++ b/src/Umbraco.Tests/MockTests.cs @@ -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(), Mock.Of())); 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(), Mock.Of())); 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(), Mock.Of())), true); + + var appCtx = new ApplicationContext( + CacheHelper.CreateDisabledCacheHelper(), + new ProfilingLogger(Mock.Of(), Mock.Of())); 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(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( Mock.Of(), @@ -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(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( Mock.Of(), @@ -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(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( Mock.Of(), diff --git a/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs index 566b90b157..0286a5bd0f 100644 --- a/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Mvc/SurfaceControllerTests.cs @@ -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(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( new Mock().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(), Mock.Of())); + 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(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( new Mock().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(), Mock.Of())); var webRoutingSettings = Mock.Of(section => section.UrlProviderMode == "AutoLegacy"); diff --git a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs index 3cac22e448..e1a3a4203e 100644 --- a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs @@ -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()); + request.Culture = CultureInfo.InvariantCulture; umbracoContext.PublishedContentRequest = request; diff --git a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs index 3bb1135cee..5883562f3b 100644 --- a/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs +++ b/src/Umbraco.Tests/Persistence/DatabaseContextTests.cs @@ -28,7 +28,9 @@ namespace Umbraco.Tests.Persistence Mock.Of(), 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(), Mock.Of())) { DatabaseContext = _dbContext, IsReady = true diff --git a/src/Umbraco.Tests/ServerEnvironmentHelperTests.cs b/src/Umbraco.Tests/ServerEnvironmentHelperTests.cs index a1f71f4f0d..7b0bdce8b4 100644 --- a/src/Umbraco.Tests/ServerEnvironmentHelperTests.cs +++ b/src/Umbraco.Tests/ServerEnvironmentHelperTests.cs @@ -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(), Mock.Of())) { 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( section => section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) @@ -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(), Mock.Of())); ConfigurationManager.AppSettings.Set("umbracoUseSSL", "false"); - ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger, + ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger, Mock.Of( section => section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) @@ -63,17 +69,19 @@ namespace Umbraco.Tests && section.ScheduledTasks == Mock.Of(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(), Mock.Of())); ConfigurationManager.AppSettings.Set("umbracoUseSSL", "true"); - ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger, + ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger, Mock.Of( section => section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) @@ -81,17 +89,19 @@ namespace Umbraco.Tests && section.ScheduledTasks == Mock.Of(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(), Mock.Of())); ConfigurationManager.AppSettings.Set("umbracoUseSSL", "true"); // does not make a diff here - ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appContext, _logger, + ServerEnvironmentHelper.TrySetApplicationUrlFromSettings(appCtx, _logger, Mock.Of( section => section.DistributedCall == Mock.Of(callSection => callSection.Servers == Enumerable.Empty()) @@ -99,7 +109,7 @@ namespace Umbraco.Tests && section.ScheduledTasks == Mock.Of(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); } } } \ No newline at end of file