diff --git a/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs b/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs new file mode 100644 index 0000000000..a252a7996c --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/ConnectionStringsBuilder.cs @@ -0,0 +1,25 @@ +using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; + +namespace Umbraco.Tests.Common.Builders +{ + public class ConnectionStringsBuilder : BuilderBase + { + private string _umbracoConnectionString; + + public ConnectionStringsBuilder WithUmbracoConnectionString(string umbracoConnectionString) + { + _umbracoConnectionString = umbracoConnectionString; + return this; + } + + public override ConnectionStrings Build() + { + var umbracoConnectionString = _umbracoConnectionString ?? string.Empty; + + return new ConnectionStrings + { + UmbracoConnectionString = umbracoConnectionString, + }; + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs new file mode 100644 index 0000000000..f5fb1fc08f --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/ContentSettingsBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class ContentSettingsBuilder : BuilderBase + { + public override ContentSettings Build() + { + return new ContentSettings(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs new file mode 100644 index 0000000000..e14fb0ade5 --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilder.cs @@ -0,0 +1,34 @@ +using CoreDebugSettings = Umbraco.Core.Configuration.Models.CoreDebugSettings; + +namespace Umbraco.Tests.Common.Builders +{ + public class CoreDebugSettingsBuilder : BuilderBase + { + private bool? _dumpOnTimeoutThreadAbort; + private bool? _logUncompletedScopes; + + public CoreDebugSettingsBuilder WithDumpOnTimeoutThreadAbort(bool dumpOnTimeoutThreadAbort) + { + _dumpOnTimeoutThreadAbort = dumpOnTimeoutThreadAbort; + return this; + } + + public CoreDebugSettingsBuilder WithLogUncompletedScopes(bool logUncompletedScopes) + { + _logUncompletedScopes = logUncompletedScopes; + return this; + } + + public override CoreDebugSettings Build() + { + var dumpOnTimeoutThreadAbort = _dumpOnTimeoutThreadAbort ?? false; + var logUncompletedScopes = _logUncompletedScopes ?? false; + + return new CoreDebugSettings + { + DumpOnTimeoutThreadAbort = dumpOnTimeoutThreadAbort, + LogUncompletedScopes = logUncompletedScopes, + }; + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs new file mode 100644 index 0000000000..35d5c66e4a --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/NuCacheSettingsBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class NuCacheSettingsBuilder : BuilderBase + { + public override NuCacheSettings Build() + { + return new NuCacheSettings(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs index 8c90678705..43cdacbb9b 100644 --- a/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilder.cs @@ -1,4 +1,3 @@ -using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; namespace Umbraco.Tests.Common.Builders diff --git a/src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs new file mode 100644 index 0000000000..3a0dfc3e9a --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/UserPasswordConfigurationSettingsBuilder.cs @@ -0,0 +1,12 @@ +using Umbraco.Core.Configuration.Models; + +namespace Umbraco.Tests.Common.Builders +{ + public class UserPasswordConfigurationSettingsBuilder : BuilderBase + { + public override UserPasswordConfigurationSettings Build() + { + return new UserPasswordConfigurationSettings(); + } + } +} diff --git a/src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs b/src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs new file mode 100644 index 0000000000..e32fff31fa --- /dev/null +++ b/src/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilder.cs @@ -0,0 +1,89 @@ +using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Tests.Common.Builders +{ + public class WebRoutingSettingsBuilder : BuilderBase + { + private bool? _trySkipIisCustomErrors; + private bool? _internalRedirectPreservesTemplate; + private bool? _disableAlternativeTemplates; + private bool? _validateAlternativeTemplates; + private bool? _disableFindContentByIdPath; + private bool? _disableRedirectUrlTracking; + private string _urlProviderMode; + private string _umbracoApplicationUrl; + + public WebRoutingSettingsBuilder WithTrySkipIisCustomErrors(bool trySkipIisCustomErrors) + { + _trySkipIisCustomErrors = trySkipIisCustomErrors; + return this; + } + + public WebRoutingSettingsBuilder WithInternalRedirectPreservesTemplate(bool internalRedirectPreservesTemplate) + { + _internalRedirectPreservesTemplate = internalRedirectPreservesTemplate; + return this; + } + + public WebRoutingSettingsBuilder WithDisableAlternativeTemplates(bool disableAlternativeTemplates) + { + _disableAlternativeTemplates = disableAlternativeTemplates; + return this; + } + + public WebRoutingSettingsBuilder WithValidateAlternativeTemplates(bool validateAlternativeTemplates) + { + _validateAlternativeTemplates = validateAlternativeTemplates; + return this; + } + + public WebRoutingSettingsBuilder WithDisableFindContentByIdPath(bool disableFindContentByIdPath) + { + _disableFindContentByIdPath = disableFindContentByIdPath; + return this; + } + + public WebRoutingSettingsBuilder WithDisableRedirectUrlTracking(bool disableRedirectUrlTracking) + { + _disableRedirectUrlTracking = disableRedirectUrlTracking; + return this; + } + + public WebRoutingSettingsBuilder WithUrlProviderMode(string urlProviderMode) + { + _urlProviderMode = urlProviderMode; + return this; + } + + public WebRoutingSettingsBuilder WithUmbracoApplicationUrl(string umbracoApplicationUrl) + { + _umbracoApplicationUrl = umbracoApplicationUrl; + return this; + } + + public override WebRoutingSettings Build() + { + var trySkipIisCustomErrors = _trySkipIisCustomErrors ?? false; + var internalRedirectPreservesTemplate = _internalRedirectPreservesTemplate ?? false; + var disableAlternativeTemplates = _disableAlternativeTemplates ?? false; + var validateAlternativeTemplates = _validateAlternativeTemplates ?? false; + var disableFindContentByIdPath = _disableFindContentByIdPath ?? false; + var disableRedirectUrlTracking = _disableRedirectUrlTracking ?? false; + var urlProviderMode = _urlProviderMode ?? UrlMode.Auto.ToString(); + var umbracoApplicationUrl = _umbracoApplicationUrl ?? string.Empty; + + return new WebRoutingSettings + { + TrySkipIisCustomErrors = trySkipIisCustomErrors, + InternalRedirectPreservesTemplate = internalRedirectPreservesTemplate, + DisableAlternativeTemplates = disableAlternativeTemplates, + ValidateAlternativeTemplates = validateAlternativeTemplates, + DisableFindContentByIdPath = disableFindContentByIdPath, + DisableRedirectUrlTracking = disableRedirectUrlTracking, + UrlProviderMode = urlProviderMode, + UmbracoApplicationUrl = umbracoApplicationUrl, + }; + } + } +} diff --git a/src/Umbraco.Tests.Integration/ContainerTests.cs b/src/Umbraco.Tests.Integration/ContainerTests.cs index 2098b7241e..a50a24e780 100644 --- a/src/Umbraco.Tests.Integration/ContainerTests.cs +++ b/src/Umbraco.Tests.Integration/ContainerTests.cs @@ -44,7 +44,7 @@ namespace Umbraco.Tests.Integration // Register in the container var composition = new Composition(umbracoContainer, typeLoader, - testHelper.Logger, runtimeState, testHelper.GetConfigs(), testHelper.IOHelper, testHelper.AppCaches); + testHelper.Logger, runtimeState, testHelper.IOHelper, testHelper.AppCaches); composition.RegisterEssentials(testHelper.Logger, testHelper.Profiler, testHelper.Logger, testHelper.MainDom, testHelper.AppCaches, umbracoDatabaseFactory, typeLoader, runtimeState, testHelper.GetTypeFinder(), testHelper.IOHelper, testHelper.GetUmbracoVersion(), dbProviderFactoryCreator, diff --git a/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs b/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs index 3961657afe..0d1d373262 100644 --- a/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs +++ b/src/Umbraco.Tests.Integration/Extensions/ApplicationBuilderExtensions.cs @@ -5,9 +5,11 @@ using System.IO; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; using Umbraco.Tests.Integration.Testing; @@ -46,7 +48,7 @@ namespace Umbraco.Tests.Integration.Extensions var db = UmbracoIntegrationTest.GetOrCreate(dbFilePath, app.ApplicationServices.GetRequiredService(), - app.ApplicationServices.GetRequiredService(), + app.ApplicationServices.GetRequiredService>().Value, app.ApplicationServices.GetRequiredService()); diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs index a6cd372411..affb274662 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHelper.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Runtime; using Umbraco.Tests.Common; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; +using Umbraco.Tests.Common.Builders; namespace Umbraco.Tests.Integration.Implementations { @@ -102,14 +103,17 @@ namespace Umbraco.Tests.Integration.Implementations public override IBackOfficeInfo GetBackOfficeInfo() { if (_backOfficeInfo == null) - _backOfficeInfo = - new AspNetCoreBackOfficeInfo(SettingsForTests.GetDefaultGlobalSettings(GetUmbracoVersion())); + { + var globalSettings = new GlobalSettingsBuilder().Build(); + _backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); + } + return _backOfficeInfo; } public override IHostingEnvironment GetHostingEnvironment() => _hostingEnvironment ??= new TestHostingEnvironment( - SettingsForTests.DefaultHostingSettings, + new HostingSettingsBuilder().Build(), _hostEnvironment); public override IApplicationShutdownRegistry GetHostingEnvironmentLifetime() => _hostingLifetime; diff --git a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs index 076cecef4a..c03a1a1699 100644 --- a/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs +++ b/src/Umbraco.Tests.Integration/Implementations/TestHostingEnvironment.cs @@ -1,16 +1,15 @@ using Microsoft.AspNetCore.Hosting; -using Umbraco.Core.Configuration; -using Umbraco.Core.Logging; +using Microsoft.Extensions.Options; +using Umbraco.Core.Configuration.Models; using Umbraco.Web.Common.AspNetCore; using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment; namespace Umbraco.Tests.Integration.Implementations { - public class TestHostingEnvironment : AspNetCoreHostingEnvironment, IHostingEnvironment { - public TestHostingEnvironment(IHostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) - : base(hostingSettings, webHostEnvironment) + public TestHostingEnvironment(HostingSettings hostingSettings, IWebHostEnvironment webHostEnvironment) + : base(Options.Create(hostingSettings), webHostEnvironment) { } diff --git a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs index dec3b55c76..cf8f091dbc 100644 --- a/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Persistence/Repositories/UserRepositoryTest.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -118,7 +119,7 @@ namespace Umbraco.Tests.Persistence.Repositories var id = user.Id; - var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(),GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); + var repository2 = new UserRepository((IScopeAccessor) provider, AppCaches.Disabled, Logger, Mock.Of(), GlobalSettings, new UserPasswordConfigurationSettings(), new JsonNetSerializer()); repository2.Delete(user); diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index bd7684fcae..11bda500b2 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -17,6 +17,8 @@ using Umbraco.Tests.Integration.Implementations; using Umbraco.Tests.Integration.Testing; using Umbraco.Web.Common.AspNetCore; using Umbraco.Extensions; +using Umbraco.Tests.Common.Builders; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.Integration { @@ -54,8 +56,11 @@ namespace Umbraco.Tests.Integration var testHelper = new TestHelper(); + var globalSettings = new GlobalSettingsBuilder().Build(); + var connectionStrings = new ConnectionStringsBuilder().Build(); + // Create the core runtime - var coreRuntime = new CoreRuntime(testHelper.GetConfigs(), testHelper.GetUmbracoVersion(), + var coreRuntime = new CoreRuntime(globalSettings, connectionStrings, testHelper.GetUmbracoVersion(), testHelper.IOHelper, testHelper.Logger, testHelper.Profiler, testHelper.UmbracoBootPermissionChecker, testHelper.GetHostingEnvironment(), testHelper.GetBackOfficeInfo(), testHelper.DbProviderFactoryCreator, testHelper.MainDom, testHelper.GetTypeFinder(), NoAppCache.Instance); @@ -70,6 +75,23 @@ namespace Umbraco.Tests.Integration Assert.IsFalse(MyComponent.IsInit); Assert.IsFalse(MyComponent.IsTerminated); + // TODO: found these registration were necessary here (as we haven't called the HostBuilder?), and dependencies for ComponentCollection + // are not resolved. Need to check this if these explicit registrations are the best way to handle this. + var contentSettings = new ContentSettingsBuilder().Build(); + var coreDebugSettings = new CoreDebugSettingsBuilder().Build(); + var nuCacheSettings = new NuCacheSettingsBuilder().Build(); + var requestHandlerSettings = new RequestHandlerSettingsBuilder().Build(); + var userPasswordConfigurationSettings = new UserPasswordConfigurationSettingsBuilder().Build(); + var webRoutingSettings = new WebRoutingSettingsBuilder().Build(); + + umbracoContainer.Register(x => Options.Create(globalSettings)); + umbracoContainer.Register(x => Options.Create(contentSettings)); + umbracoContainer.Register(x => Options.Create(coreDebugSettings)); + umbracoContainer.Register(x => Options.Create(nuCacheSettings)); + umbracoContainer.Register(x => Options.Create(requestHandlerSettings)); + umbracoContainer.Register(x => Options.Create(userPasswordConfigurationSettings)); + umbracoContainer.Register(x => Options.Create(webRoutingSettings)); + coreRuntime.Start(); Assert.IsTrue(MyComponent.IsInit); diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 9988362d3b..f628437507 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Threading; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence; @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Integration.Testing public const string DatabaseName = "UmbracoTests"; private readonly ILogger _logger; - private readonly IGlobalSettings _globalSettings; + private readonly GlobalSettings _globalSettings; private readonly LocalDb _localDb; private readonly IUmbracoVersion _umbracoVersion; private static LocalDb.Instance _instance; @@ -38,7 +39,7 @@ namespace Umbraco.Tests.Integration.Testing private DatabasePool _currentPool; //It's internal because `Umbraco.Core.Persistence.LocalDb` is internal - internal LocalDbTestDatabase(ILogger logger, IGlobalSettings globalSettings, LocalDb localDb, string filesPath, IUmbracoDatabaseFactory dbFactory) + internal LocalDbTestDatabase(ILogger logger, GlobalSettings globalSettings, LocalDb localDb, string filesPath, IUmbracoDatabaseFactory dbFactory) { _umbracoVersion = new UmbracoVersion(); _logger = logger; diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 89cbfa992d..562480df83 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -22,6 +22,8 @@ using Umbraco.Extensions; using Umbraco.Tests.Testing; using Umbraco.Web; using ILogger = Umbraco.Core.Logging.ILogger; +using Umbraco.Core.Configuration.Models; +using Microsoft.Extensions.Options; namespace Umbraco.Tests.Integration.Testing { @@ -54,7 +56,7 @@ namespace Umbraco.Tests.Integration.Testing /// /// There must only be ONE instance shared between all tests in a session /// - public static LocalDbTestDatabase GetOrCreate(string filesPath, ILogger logger, IGlobalSettings globalSettings, IUmbracoDatabaseFactory dbFactory) + public static LocalDbTestDatabase GetOrCreate(string filesPath, ILogger logger, GlobalSettings globalSettings, IUmbracoDatabaseFactory dbFactory) { lock (_dbLocker) { @@ -175,7 +177,7 @@ namespace Umbraco.Tests.Integration.Testing protected AppCaches AppCaches => Services.GetRequiredService(); protected IIOHelper IOHelper => Services.GetRequiredService(); protected IShortStringHelper ShortStringHelper => Services.GetRequiredService(); - protected IGlobalSettings GlobalSettings => Services.GetRequiredService(); + protected GlobalSettings GlobalSettings => Services.GetRequiredService>().Value; protected IMapperCollection Mappers => Services.GetRequiredService(); #endregion diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs index 3464259052..6fd5672085 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice.Security/BackOfficeCookieManagerTests.cs @@ -9,6 +9,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Hosting; using Umbraco.Extensions; +using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Implementations; using Umbraco.Web; using Umbraco.Web.BackOffice.Controllers; @@ -25,7 +26,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( @@ -50,8 +51,8 @@ namespace Umbraco.Tests.Security //hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); - + var globalSettings = new GlobalSettingsBuilder().Build(); + var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); var mgr = new BackOfficeCookieManager( Mock.Of(), @@ -72,7 +73,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -97,7 +98,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); @@ -119,7 +120,7 @@ namespace Umbraco.Tests.Security var testHelper = new TestHelper(); var httpContextAccessor = testHelper.GetHttpContextAccessor(); - var globalSettings = testHelper.SettingsForTests.GenerateMockGlobalSettings(); + var globalSettings = new GlobalSettingsBuilder().Build(); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs new file mode 100644 index 0000000000..c8ba34be60 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/ConnectionStringsBuilderTests.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class ConnectionStringsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const string umbracoConnectionString = "connection string"; + + var builder = new ConnectionStringsBuilder(); + + // Act + var connectionStrings = builder + .WithUmbracoConnectionString(umbracoConnectionString) + .Build(); + + // Assert + Assert.AreEqual(umbracoConnectionString, connectionStrings.UmbracoConnectionString); + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs new file mode 100644 index 0000000000..d576f44072 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/CoreDebugSettingsBuilderTests.cs @@ -0,0 +1,29 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class CoreDebugSettingsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const bool dumpOnTimeoutThreadAbort = true; + const bool logUncompletedScopes = true; + + var builder = new CoreDebugSettingsBuilder(); + + // Act + var coreDebugSettings = builder + .WithDumpOnTimeoutThreadAbort(dumpOnTimeoutThreadAbort) + .WithLogUncompletedScopes(logUncompletedScopes) + .Build(); + + // Assert + Assert.AreEqual(dumpOnTimeoutThreadAbort, coreDebugSettings.DumpOnTimeoutThreadAbort); + Assert.AreEqual(logUncompletedScopes, coreDebugSettings.LogUncompletedScopes); + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs similarity index 100% rename from src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTestsy.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/RequestHandlerSettingsBuilderTests.cs diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs new file mode 100644 index 0000000000..e3f4bcf04e --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/WebRoutingSettingsBuilderTests.cs @@ -0,0 +1,47 @@ +using NUnit.Framework; +using Umbraco.Tests.Common.Builders; + +namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders +{ + [TestFixture] + public class WebRoutingSettingsBuilderTests + { + [Test] + public void Is_Built_Correctly() + { + // Arrange + const bool disableAlternativeTemplates = true; + const bool disableFindContentByIdPath = true; + const bool disableRedirectUrlTracking = true; + const bool internalRedirectPreservesTemplate = true; + const bool trySkipIisCustomErrors = true; + const string umbracoApplicationUrl = "/test/"; + const string urlProviderMode = "test"; + const bool validateAlternativeTemplates = true; + + var builder = new WebRoutingSettingsBuilder(); + + // Act + var webRoutingSettings = builder + .WithDisableAlternativeTemplates(disableAlternativeTemplates) + .WithDisableFindContentByIdPath(disableFindContentByIdPath) + .WithDisableRedirectUrlTracking(disableRedirectUrlTracking) + .WithInternalRedirectPreservesTemplate(internalRedirectPreservesTemplate) + .WithTrySkipIisCustomErrors(trySkipIisCustomErrors) + .WithUmbracoApplicationUrl(umbracoApplicationUrl) + .WithUrlProviderMode(urlProviderMode) + .WithValidateAlternativeTemplates(validateAlternativeTemplates) + .Build(); + + // Assert + Assert.AreEqual(disableAlternativeTemplates, webRoutingSettings.DisableAlternativeTemplates); + Assert.AreEqual(disableFindContentByIdPath, webRoutingSettings.DisableFindContentByIdPath); + Assert.AreEqual(disableRedirectUrlTracking, webRoutingSettings.DisableRedirectUrlTracking); + Assert.AreEqual(internalRedirectPreservesTemplate, webRoutingSettings.InternalRedirectPreservesTemplate); + Assert.AreEqual(trySkipIisCustomErrors, webRoutingSettings.TrySkipIisCustomErrors); + Assert.AreEqual(umbracoApplicationUrl, webRoutingSettings.UmbracoApplicationUrl); + Assert.AreEqual(urlProviderMode, webRoutingSettings.UrlProviderMode); + Assert.AreEqual(validateAlternativeTemplates, webRoutingSettings.ValidateAlternativeTemplates); + } + } +}