Merge remote-tracking branch 'origin/netcore/netcore' into feature/clean-up-umbraco-integration-tests

# Conflicts:
#	src/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs
#	src/Umbraco.Tests.Integration/RuntimeTests.cs
#	src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs
#	src/Umbraco.Tests.Integration/Umbraco.Core/IO/FileSystemsTests.cs
#	src/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UmbracoMapperTests.cs
#	src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs
#	src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs
This commit is contained in:
Bjarke Berg
2021-01-18 07:34:59 +01:00
398 changed files with 8136 additions and 7403 deletions

View File

@@ -1,149 +0,0 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using System.IO;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.Models;
using Umbraco.Core.DependencyInjection;
using Umbraco.Core.Hosting;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Core.Sync;
using Umbraco.Core.WebAssets;
using Umbraco.Examine;
using Umbraco.Tests.TestHelpers.Stubs;
using Umbraco.Web.Compose;
using Umbraco.Web.PublishedCache.NuCache;
using Umbraco.Web.Search;
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>
public class IntegrationTestComposer : ComponentComposer<IntegrationTestComponent>
{
public override void Compose(IUmbracoBuilder builder)
{
base.Compose(builder);
builder.Components().Remove<DatabaseServerRegistrarAndMessengerComponent>();
builder.Services.AddUnique<BackgroundIndexRebuilder, TestBackgroundIndexRebuilder>();
builder.Services.AddUnique<IRuntimeMinifier>(factory => Mock.Of<IRuntimeMinifier>());
// we don't want persisted nucache files in tests
builder.Services.AddTransient(factory => new PublishedSnapshotServiceOptions { IgnoreLocalDb = true });
#if IS_WINDOWS
// ensure all lucene indexes are using RAM directory (no file system)
builder.Services.AddUnique<ILuceneDirectoryFactory, LuceneRAMDirectoryFactory>();
#endif
// replace this service so that it can lookup the correct file locations
builder.Services.AddUnique<ILocalizedTextService>(GetLocalizedTextService);
builder.Services.AddUnique<IServerMessenger, NoopServerMessenger>();
builder.Services.AddUnique<IProfiler, TestProfiler>();
}
/// <summary>
/// Used to register a replacement for <see cref="ILocalizedTextService"/> where the file sources are the ones within the netcore project so
/// we don't need to copy files
/// </summary>
private ILocalizedTextService GetLocalizedTextService(IServiceProvider factory)
{
IOptions<GlobalSettings> globalSettings = factory.GetRequiredService<IOptions<GlobalSettings>>();
ILoggerFactory loggerFactory = factory.GetRequiredService<ILoggerFactory>();
AppCaches appCaches = factory.GetRequiredService<AppCaches>();
var localizedTextService = new LocalizedTextService(
new Lazy<LocalizedTextServiceFileSources>(() =>
{
// get the src folder
var currFolder = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
while (!currFolder.Name.Equals("src", StringComparison.InvariantCultureIgnoreCase))
{
currFolder = currFolder.Parent;
}
DirectoryInfo netcoreUI = currFolder.GetDirectories("Umbraco.Web.UI.NetCore", SearchOption.TopDirectoryOnly).First();
var mainLangFolder = new DirectoryInfo(Path.Combine(netcoreUI.FullName, globalSettings.Value.UmbracoPath.TrimStart("~/"), "config", "lang"));
return new LocalizedTextServiceFileSources(
loggerFactory.CreateLogger<LocalizedTextServiceFileSources>(),
appCaches,
mainLangFolder);
}),
loggerFactory.CreateLogger<LocalizedTextService>());
return localizedTextService;
}
// replace the default so there is no background index rebuilder
private class TestBackgroundIndexRebuilder : BackgroundIndexRebuilder
{
public TestBackgroundIndexRebuilder(IMainDom mainDom, IProfilingLogger profilingLogger, ILoggerFactory loggerFactory, IApplicationShutdownRegistry hostingEnvironment, IndexRebuilder indexRebuilder)
: base(mainDom, profilingLogger, loggerFactory, hostingEnvironment, indexRebuilder)
{
}
public override void RebuildIndexes(bool onlyEmptyIndexes, int waitMilliseconds = 0)
{
// noop
}
}
private class NoopServerMessenger : IServerMessenger
{
public NoopServerMessenger()
{
}
public void PerformRefresh<TPayload>(ICacheRefresher refresher, TPayload[] payload)
{
}
public void PerformRefresh<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances)
{
}
public void PerformRefresh<T>(ICacheRefresher refresher, Func<T, Guid> getGuidId, params T[] instances)
{
}
public void PerformRemove<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances)
{
}
public void PerformRemove(ICacheRefresher refresher, params int[] numericIds)
{
}
public void PerformRefresh(ICacheRefresher refresher, params int[] numericIds)
{
}
public void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds)
{
}
public void PerformRefreshAll(ICacheRefresher refresher)
{
}
}
}
}

View File

@@ -29,10 +29,13 @@ using Umbraco.Core.Runtime;
using Umbraco.Core.Scoping;
using Umbraco.Core.Strings;
using Umbraco.Extensions;
using Umbraco.Infrastructure.DependencyInjection;
using Umbraco.Infrastructure.PublishedCache.DependencyInjection;
using Umbraco.Tests.Common.Builders;
using Umbraco.Tests.Integration.DependencyInjection;
using Umbraco.Tests.Integration.Extensions;
using Umbraco.Tests.Integration.Implementations;
using Umbraco.Tests.Integration.TestServerTest;
using Umbraco.Tests.Testing;
using Umbraco.Web;
using Umbraco.Web.BackOffice.DependencyInjection;
@@ -210,24 +213,27 @@ namespace Umbraco.Tests.Integration.Testing
builder.Services.AddLogger(TestHelper.GetHostingEnvironment(), TestHelper.GetLoggingConfiguration(), Configuration);
builder.AddConfiguration()
.AddUmbracoCore();
.AddUmbracoCore()
.AddWebComponents()
.AddRuntimeMinifier()
.AddBackOfficeAuthentication()
.AddBackOfficeIdentity()
.AddTestServices(TestHelper, GetAppCaches());
builder.Services.AddUnique<AppCaches>(GetAppCaches());
builder.Services.AddUnique<IUmbracoBootPermissionChecker>(Mock.Of<IUmbracoBootPermissionChecker>());
builder.Services.AddUnique<IMainDom>(TestHelper.MainDom);
if (TestOptions.Mapper)
{
// TODO: Should these just be called from within AddUmbracoCore/AddWebComponents?
builder
.AddCoreMappingProfiles()
.AddWebMappingProfiles();
}
services.AddSignalR();
builder.AddWebComponents();
builder.AddRuntimeMinifier();
builder.AddBackOfficeAuthentication();
builder.AddBackOfficeIdentity();
services.AddMvc();
builder.Build();
CustomTestSetup(builder);
builder.Build();
}
protected virtual AppCaches GetAppCaches() =>