Fixes integration tests localization text

This commit is contained in:
Shannon
2020-09-04 01:30:47 +10:00
parent e6b6dd6d92
commit 1c83c68862
6 changed files with 48 additions and 174 deletions

View File

@@ -1,10 +1,17 @@
using Moq;
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Core.WebAssets;
using Umbraco.Examine;
using Umbraco.Web.Compose;
@@ -38,6 +45,43 @@ namespace Umbraco.Tests.Integration.Testing
// ensure all lucene indexes are using RAM directory (no file system)
composition.RegisterUnique<ILuceneDirectoryFactory, LuceneRAMDirectoryFactory>();
// replace this service so that it can lookup the correct file locations
composition.RegisterUnique<ILocalizedTextService>(GetLocalizedTextService);
}
/// <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>
/// <returns></returns>
private ILocalizedTextService GetLocalizedTextService(IFactory factory)
{
var configs = factory.GetInstance<Configs>();
var logger = factory.GetInstance<ILogger>();
var appCaches = factory.GetInstance<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;
}
var netcoreUI = currFolder.GetDirectories("Umbraco.Web.UI.NetCore", SearchOption.TopDirectoryOnly).First();
var mainLangFolder = new DirectoryInfo(Path.Combine(netcoreUI.FullName, configs.Global().UmbracoPath.TrimStart("~/"), "config", "lang"));
return new LocalizedTextServiceFileSources(
logger,
appCaches,
mainLangFolder);
}),
logger);
return localizedTextService;
}
// replace the default so there is no background index rebuilder