Starts fixing up integration tests

This commit is contained in:
Shannon
2020-04-03 13:16:01 +11:00
parent 4349115f0d
commit 60abdd60b5
14 changed files with 162 additions and 121 deletions
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -6,9 +7,9 @@ namespace Umbraco.Configuration.Implementations
{
internal class RequestHandlerSettings : ConfigurationManagerConfigBase, IRequestHandlerSettings
{
public bool AddTrailingSlash => UmbracoSettingsSection.RequestHandler.AddTrailingSlash;
public bool ConvertUrlsToAscii => UmbracoSettingsSection.RequestHandler.UrlReplacing.ConvertUrlsToAscii.InvariantEquals("true");
public bool TryConvertUrlsToAscii => UmbracoSettingsSection.RequestHandler.UrlReplacing.ConvertUrlsToAscii.InvariantEquals("try");
public IEnumerable<IChar> CharCollection => UmbracoSettingsSection.RequestHandler.UrlReplacing.CharCollection;
public bool AddTrailingSlash => UmbracoSettingsSection?.RequestHandler?.AddTrailingSlash ?? true;
public bool ConvertUrlsToAscii => UmbracoSettingsSection?.RequestHandler?.UrlReplacing?.ConvertUrlsToAscii.InvariantEquals("true") ?? false;
public bool TryConvertUrlsToAscii => UmbracoSettingsSection?.RequestHandler?.UrlReplacing?.ConvertUrlsToAscii.InvariantEquals("try") ?? false;
public IEnumerable<IChar> CharCollection => UmbracoSettingsSection?.RequestHandler?.UrlReplacing?.CharCollection ?? Enumerable.Empty<IChar>();
}
}
@@ -4,13 +4,13 @@ namespace Umbraco.Configuration.Implementations
{
internal class WebRoutingSettings : ConfigurationManagerConfigBase, IWebRoutingSettings
{
public bool TrySkipIisCustomErrors => UmbracoSettingsSection.WebRouting.TrySkipIisCustomErrors;
public bool InternalRedirectPreservesTemplate => UmbracoSettingsSection.WebRouting.InternalRedirectPreservesTemplate;
public bool DisableAlternativeTemplates => UmbracoSettingsSection.WebRouting.DisableAlternativeTemplates;
public bool ValidateAlternativeTemplates => UmbracoSettingsSection.WebRouting.ValidateAlternativeTemplates;
public bool DisableFindContentByIdPath => UmbracoSettingsSection.WebRouting.DisableFindContentByIdPath;
public bool DisableRedirectUrlTracking => UmbracoSettingsSection.WebRouting.DisableRedirectUrlTracking;
public string UrlProviderMode => UmbracoSettingsSection.WebRouting.UrlProviderMode;
public string UmbracoApplicationUrl => UmbracoSettingsSection.WebRouting.UmbracoApplicationUrl;
public bool TrySkipIisCustomErrors => UmbracoSettingsSection?.WebRouting?.TrySkipIisCustomErrors ?? false;
public bool InternalRedirectPreservesTemplate => UmbracoSettingsSection?.WebRouting?.InternalRedirectPreservesTemplate ?? false;
public bool DisableAlternativeTemplates => UmbracoSettingsSection?.WebRouting?.DisableAlternativeTemplates ?? false;
public bool ValidateAlternativeTemplates => UmbracoSettingsSection?.WebRouting?.ValidateAlternativeTemplates ?? false;
public bool DisableFindContentByIdPath => UmbracoSettingsSection?.WebRouting?.DisableFindContentByIdPath ?? false;
public bool DisableRedirectUrlTracking => UmbracoSettingsSection?.WebRouting?.DisableRedirectUrlTracking ?? false;
public string UrlProviderMode => UmbracoSettingsSection?.WebRouting?.UrlProviderMode ?? "Auto";
public string UmbracoApplicationUrl => UmbracoSettingsSection?.WebRouting?.UmbracoApplicationUrl;
}
}
@@ -31,6 +31,7 @@ namespace Umbraco.Core.Composing
/// <param name="runtimeState">The runtime state.</param>
/// <param name="configs">Optional configs.</param>
/// <param name="ioHelper">An IOHelper</param>
/// <param name="appCaches"></param>
public Composition(IRegister register, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, Configs configs, IIOHelper ioHelper, AppCaches appCaches)
{
_register = register ?? throw new ArgumentNullException(nameof(register));
@@ -23,15 +23,14 @@ namespace Umbraco.Tests.Integration.Extensions
/// Creates a LocalDb instance to use for the test
/// </summary>
/// <param name="app"></param>
/// <param name="hostEnvironment"></param>
/// <param name="workingDirectory"></param>
/// <param name="integrationTest"></param>
/// <returns></returns>
public static IApplicationBuilder UseTestLocalDb(this IApplicationBuilder app,
IHostEnvironment hostEnvironment,
string workingDirectory,
UmbracoIntegrationTest integrationTest)
{
var dbFilePath = Path.Combine(hostEnvironment.ContentRootPath, "LocalDb");
var dbFilePath = Path.Combine(workingDirectory, "LocalDb");
// get the currently set db options
var testOptions = TestOptionAttributeBase.GetTestOptions<UmbracoTestAttribute>();
@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Umbraco.Core.Composing;
using Umbraco.Tests.Integration.Implementations;
namespace Umbraco.Tests.Integration.Extensions
@@ -7,6 +7,7 @@ using Moq;
using System.Data.Common;
using System.IO;
using System.Net;
using System.Reflection;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Diagnostics;
@@ -42,7 +43,7 @@ namespace Umbraco.Tests.Integration.Implementations
var hostEnvironment = new Mock<IWebHostEnvironment>();
hostEnvironment.Setup(x => x.ApplicationName).Returns("UmbracoIntegrationTests");
hostEnvironment.Setup(x => x.ContentRootPath).Returns(() => WorkingDirectory);
hostEnvironment.Setup(x => x.ContentRootPath).Returns(() => Assembly.GetExecutingAssembly().GetRootDirectorySafe());
hostEnvironment.Setup(x => x.WebRootPath).Returns(() => WorkingDirectory);
_hostEnvironment = hostEnvironment.Object;
@@ -4,6 +4,7 @@ using Moq;
using NUnit.Framework;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Smidge;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
@@ -0,0 +1,23 @@
using Moq;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.WebAssets;
namespace Umbraco.Tests.Integration.Testing
{
/// <summary>
/// This is used to replace certain services that are normally registered from our Core / Infrastructure that
/// we do not want active within integration tests
/// </summary>
/// <remarks>
/// This is a IUserComposer so that it runs after all core composers
/// </remarks>
[RuntimeLevel(MinLevel = RuntimeLevel.Boot)]
public class IntegrationTestComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.RegisterUnique<IRuntimeMinifier>(factory => Mock.Of<IRuntimeMinifier>());
}
}
}
@@ -7,10 +7,12 @@ using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Threading;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Migrations.Install;
using Umbraco.Core.Persistence;
using Umbraco.Web.Common.RuntimeMinification;
namespace Umbraco.Tests.Integration.Testing
{
@@ -308,7 +310,8 @@ namespace Umbraco.Tests.Integration.Testing
ResetLocalDb(cmd);
_prepare?.Invoke(conn, cmd);
}
_readyQueue.Add(i);
if (!_readyQueue.IsAddingCompleted)
_readyQueue.Add(i);
}
}
@@ -126,7 +126,7 @@ namespace Umbraco.Tests.Integration.Testing
Services = app.ApplicationServices;
// This will create a db, install the schema and ensure the app is configured to run
app.UseTestLocalDb(Services.GetRequiredService<IHostEnvironment>(), this);
app.UseTestLocalDb(testHelper.WorkingDirectory, this);
app.UseUmbracoCore();
}
@@ -7,6 +7,12 @@
<LangVersion>8</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="TEMP\**" />
<EmbeddedResource Remove="TEMP\**" />
<None Remove="TEMP\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
@@ -89,7 +89,7 @@ namespace Umbraco.Web.Common.AspNetCore
public string ToAbsolute(string virtualPath)
{
if (!virtualPath.StartsWith("~/") && !virtualPath.StartsWith("/"))
throw new InvalidOperationException($"{nameof(virtualPath)} must start with ~/ or /");
throw new InvalidOperationException($"The value {virtualPath} for parameter {nameof(virtualPath)} must start with ~/ or /");
// will occur if it starts with "/"
if (Uri.IsWellFormedUriString(virtualPath, UriKind.Absolute))
@@ -9,6 +9,11 @@ namespace Umbraco.Web.Common.RuntimeMinification
{
public void Compose(Composition composition)
{
// TODO: For this to work we need to have services.AddSmidge() based on the Smidge APIs but our composer APIs don't really let us do that
// This makes it a bit awkward to boot the runtime since that call would need to be made outside of the composer... .hrm...
composition.RegisterUnique<IRuntimeMinifier, SmidgeRuntimeMinifier>();
composition.RegisterUnique<SmidgeHelperAccessor>();
}
+101 -101
View File
@@ -12,111 +12,111 @@
"AllowedHosts": "*",
"Umbraco": {
"CMS": {
"Hosting": {
"Debug": false
},
"RuntimeMinification": {
"dataFolder": "App_Data/TEMP/Smidge",
"version": "637212411755687059"
},
"Imaging": {
"Resize": {
"MaxWidth": 5000,
"MaxHeight": 5000
"Hosting": {
"Debug": true
},
"Cache": {
"Folder": "../App_Data/Cache",
"MaxBrowserCacheDays": 7,
"MaxCacheDays": 365,
"CachedNameLength": 8
}
},
"HealthChecks": {
"DisabledChecks": [
{
"id": "1B5D221B-CE99-4193-97CB-5F3261EC73DF",
"disabledBy": 1,
"disabledOn": "2020-03-15 19:19:10"
}
],
"NotificationSettings": {
"Enabled": true,
"FirstRunTime": "",
"PeriodInHours": 24,
"NotificationMethods": {
"Email": {
"Enabled": true,
"Verbosity": "Summary",
"Settings": {
"RecipientEmail": ""
}
"RuntimeMinification": {
"dataFolder": "App_Data/TEMP/Smidge",
"version": "637212411755687059"
},
"Imaging": {
"Resize": {
"MaxWidth": 5000,
"MaxHeight": 5000
},
"Cache": {
"Folder": "../App_Data/Cache",
"MaxBrowserCacheDays": 7,
"MaxCacheDays": 365,
"CachedNameLength": 8
}
},
"DisabledChecks": [
{
"id": "1B5D221B-CE99-4193-97CB-5F3261EC73DF",
"disabledBy": 1,
"disabledOn": "2020-03-15 19:19:10"
},
"HealthChecks": {
"DisabledChecks": [
{
"id": "1B5D221B-CE99-4193-97CB-5F3261EC73DF",
"disabledBy": 1,
"disabledOn": "2020-03-15 19:19:10"
}
],
"NotificationSettings": {
"Enabled": true,
"FirstRunTime": "",
"PeriodInHours": 24,
"NotificationMethods": {
"Email": {
"Enabled": true,
"Verbosity": "Summary",
"Settings": {
"RecipientEmail": ""
}
}
},
"DisabledChecks": [
{
"id": "1B5D221B-CE99-4193-97CB-5F3261EC73DF",
"disabledBy": 1,
"disabledOn": "2020-03-15 19:19:10"
}
]
}
]
},
"Tours": {
"EnableTours": true
},
"Core": {
"Debug": {}
},
"Content": {
"Errors": {
"Error404": {
"default": "1047",
"en-US": "$site/error [@name = 'error']",
"en-UK": "8560867F-B88F-4C74-A9A4-679D8E5B3BFC"
}
}
},
"RequestHandler": {
"AddTrailingSlash": true,
"CharCollection": [
{
"Char": " ",
"Replacement": "-"
},
{
"Char": "\"",
"Replacement": ""
},
{
"Char": "'",
"Replacement": ""
},
{
"Char": "%",
"Replacement": ""
},
{
"Char": ".",
"Replacement": ""
},
{
"Char": ";",
"Replacement": ""
},
{
"Char": "/",
"Replacement": ""
},
{
"Char": "\\",
"Replacement": ""
},
{
"Char": ":",
"Replacement": ""
}
]
}
},
"Tours": {
"EnableTours": true
},
"Core": {
"Debug": {}
},
"Content": {
"Errors": {
"Error404": {
"default": "1047",
"en-US": "$site/error [@name = 'error']",
"en-UK": "8560867F-B88F-4C74-A9A4-679D8E5B3BFC"
}
}
},
"RequestHandler": {
"AddTrailingSlash": true,
"CharCollection": [
{
"Char": " ",
"Replacement": "-"
},
{
"Char": "\"",
"Replacement": ""
},
{
"Char": "'",
"Replacement": ""
},
{
"Char": "%",
"Replacement": ""
},
{
"Char": ".",
"Replacement": ""
},
{
"Char": ";",
"Replacement": ""
},
{
"Char": "/",
"Replacement": ""
},
{
"Char": "\\",
"Replacement": ""
},
{
"Char": ":",
"Replacement": ""
}
]
}
}
}
}