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

@@ -4,7 +4,6 @@ using System.Globalization;
using System.Reflection;
using System.IO;
using System.Linq;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.Strings;
@@ -14,7 +13,7 @@ namespace Umbraco.Core.IO
{
private readonly IHostingEnvironment _hostingEnvironment;
public IOHelper(IHostingEnvironment hostingEnvironment, IGlobalSettings globalSettings)
public IOHelper(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
}

View File

@@ -40,7 +40,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
protected override ILanguage PerformGet(int id)
{
throw new NotSupportedException(); // not required since policy is full dataset
return PerformGetAll(id).FirstOrDefault();
}
protected override IEnumerable<ILanguage> PerformGetAll(params int[] ids)

View File

@@ -82,7 +82,7 @@ namespace Umbraco.Tests.Common
get
{
if (_ioHelper == null)
_ioHelper = new IOHelper(GetHostingEnvironment(), SettingsForTests.GenerateMockGlobalSettings());
_ioHelper = new IOHelper(GetHostingEnvironment());
return _ioHelper;
}
}

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

View File

@@ -1,29 +1,17 @@
using System;
using System.IO;
using System.Linq;
using Moq;
using NPoco;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Events;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Packaging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Core.Strings;
using Umbraco.Persistance.SqlCe;
using Umbraco.Tests.TestHelpers.Stubs;
using Current = Umbraco.Web.Composing.Current;
namespace Umbraco.Tests.TestHelpers
@@ -70,163 +58,6 @@ namespace Umbraco.Tests.TestHelpers
return new UmbracoDatabase(connection, sqlContext, logger, TestHelper.BulkSqlInsertProvider);
}
public void RegisterServices(IRegister register)
{ }
/// <summary>
/// Gets a ServiceContext.
/// </summary>
/// <param name="scopeProvider"></param>
/// <param name="scopeAccessor"></param>
/// <param name="cache">A cache.</param>
/// <param name="logger">A logger.</param>
/// <param name="ioHelper">An io helper.</param>
/// <param name="globalSettings"></param>
/// <param name="contentSettings"></param>
/// <param name="eventMessagesFactory">An event messages factory.</param>
/// <param name="urlSegmentProviders">Some url segment providers.</param>
/// <param name="umbracoVersion">An Umbraco Version.</param>
/// <param name="factory">A container.</param>
/// <returns>A ServiceContext.</returns>
/// <remarks>Should be used sparingly for integration tests only - for unit tests
/// just mock the services to be passed to the ctor of the ServiceContext.</remarks>
public ServiceContext GetServiceContext(IScopeProvider scopeProvider, IScopeAccessor scopeAccessor,
AppCaches cache,
ILogger logger,
IIOHelper ioHelper,
IGlobalSettings globalSettings,
IContentSettings contentSettings,
IEventMessagesFactory eventMessagesFactory,
UrlSegmentProviderCollection urlSegmentProviders,
IUmbracoVersion umbracoVersion,
IHostingEnvironment hostingEnvironment,
IFactory factory = null)
{
if (scopeProvider == null) throw new ArgumentNullException(nameof(scopeProvider));
if (scopeAccessor == null) throw new ArgumentNullException(nameof(scopeAccessor));
if (cache == null) throw new ArgumentNullException(nameof(cache));
if (logger == null) throw new ArgumentNullException(nameof(logger));
if (eventMessagesFactory == null) throw new ArgumentNullException(nameof(eventMessagesFactory));
var scheme = Mock.Of<IMediaPathScheme>();
var shortStringHelper = Mock.Of<IShortStringHelper>();
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), scheme, logger, shortStringHelper);
var externalLoginService = GetLazyService<IExternalLoginService>(factory, c => new ExternalLoginService(scopeProvider, logger, eventMessagesFactory, GetRepo<IExternalLoginRepository>(c)));
var publicAccessService = GetLazyService<IPublicAccessService>(factory, c => new PublicAccessService(scopeProvider, logger, eventMessagesFactory, GetRepo<IPublicAccessRepository>(c)));
var domainService = GetLazyService<IDomainService>(factory, c => new DomainService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDomainRepository>(c)));
var auditService = GetLazyService<IAuditService>(factory, c => new AuditService(scopeProvider, logger, eventMessagesFactory, GetRepo<IAuditRepository>(c), GetRepo<IAuditEntryRepository>(c)));
var localizedTextService = GetLazyService<ILocalizedTextService>(factory, c => new LocalizedTextService(
new Lazy<LocalizedTextServiceFileSources>(() =>
{
var mainLangFolder = new DirectoryInfo(ioHelper.MapPath(Current.Configs.Global().UmbracoPath + "/config/lang/"));
var appPlugins = new DirectoryInfo(ioHelper.MapPath(Constants.SystemDirectories.AppPlugins));
var configLangFolder = new DirectoryInfo(ioHelper.MapPath(Constants.SystemDirectories.Config + "/lang/"));
var pluginLangFolders = appPlugins.Exists == false
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
: appPlugins.GetDirectories()
.SelectMany(x => x.GetDirectories("Lang"))
.SelectMany(x => x.GetFiles("*.xml", SearchOption.TopDirectoryOnly))
.Where(x => Path.GetFileNameWithoutExtension(x.FullName).Length == 5)
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, false));
//user defined langs that overwrite the default, these should not be used by plugin creators
var userLangFolders = configLangFolder.Exists == false
? Enumerable.Empty<LocalizedTextServiceSupplementaryFileSource>()
: configLangFolder
.GetFiles("*.user.xml", SearchOption.TopDirectoryOnly)
.Where(x => Path.GetFileNameWithoutExtension(x.FullName).Length == 10)
.Select(x => new LocalizedTextServiceSupplementaryFileSource(x, true));
return new LocalizedTextServiceFileSources(
logger,
cache,
mainLangFolder,
pluginLangFolders.Concat(userLangFolders));
}),
logger));
var runtimeState = Mock.Of<IRuntimeState>();
var idkMap = new IdKeyMap(scopeProvider);
var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty<DataEditor>()));
var localizationService = GetLazyService<ILocalizationService>(factory, c => new LocalizationService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDictionaryRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<ILanguageRepository>(c)));
var userService = GetLazyService<IUserService>(factory, c => new UserService(scopeProvider, logger, eventMessagesFactory, runtimeState, GetRepo<IUserRepository>(c), GetRepo<IUserGroupRepository>(c),globalSettings));
var dataTypeService = GetLazyService<IDataTypeService>(factory, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDataTypeRepository>(c), GetRepo<IDataTypeContainerRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IEntityRepository>(c), GetRepo<IContentTypeRepository>(c), ioHelper, localizedTextService.Value, localizationService.Value, TestHelper.ShortStringHelper));
var propertyValidationService = new Lazy<IPropertyValidationService>(() => new PropertyValidationService(propertyEditorCollection, dataTypeService.Value, localizedTextService.Value));
var contentService = GetLazyService<IContentService>(factory, c => new ContentService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDocumentRepository>(c), GetRepo<IEntityRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IContentTypeRepository>(c), GetRepo<IDocumentBlueprintRepository>(c), GetRepo<ILanguageRepository>(c), propertyValidationService, TestHelper.ShortStringHelper));
var notificationService = GetLazyService<INotificationService>(factory, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, localizationService.Value, logger, ioHelper, GetRepo<INotificationsRepository>(c), globalSettings, contentSettings, TestHelper.EmailSender));
var serverRegistrationService = GetLazyService<IServerRegistrationService>(factory, c => new ServerRegistrationService(scopeProvider, logger, eventMessagesFactory, GetRepo<IServerRegistrationRepository>(c), TestHelper.GetHostingEnvironment()));
var memberGroupService = GetLazyService<IMemberGroupService>(factory, c => new MemberGroupService(scopeProvider, logger, eventMessagesFactory, GetRepo<IMemberGroupRepository>(c)));
var memberService = GetLazyService<IMemberService>(factory, c => new MemberService(scopeProvider, logger, eventMessagesFactory, memberGroupService.Value, GetRepo<IMemberRepository>(c), GetRepo<IMemberTypeRepository>(c), GetRepo<IMemberGroupRepository>(c), GetRepo<IAuditRepository>(c)));
var mediaService = GetLazyService<IMediaService>(factory, c => new MediaService(scopeProvider, mediaFileSystem, logger, eventMessagesFactory, GetRepo<IMediaRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IMediaTypeRepository>(c), GetRepo<IEntityRepository>(c), TestHelper.ShortStringHelper));
var contentTypeService = GetLazyService<IContentTypeService>(factory, c => new ContentTypeService(scopeProvider, logger, eventMessagesFactory, contentService.Value, GetRepo<IContentTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IDocumentTypeContainerRepository>(c), GetRepo<IEntityRepository>(c)));
var mediaTypeService = GetLazyService<IMediaTypeService>(factory, c => new MediaTypeService(scopeProvider, logger, eventMessagesFactory, mediaService.Value, GetRepo<IMediaTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IMediaTypeContainerRepository>(c), GetRepo<IEntityRepository>(c)));
var fileService = GetLazyService<IFileService>(factory, c => new FileService(scopeProvider, logger, eventMessagesFactory, GetRepo<IStylesheetRepository>(c), GetRepo<IScriptRepository>(c), GetRepo<ITemplateRepository>(c), GetRepo<IPartialViewRepository>(c), GetRepo<IPartialViewMacroRepository>(c), GetRepo<IAuditRepository>(c), TestHelper.ShortStringHelper, globalSettings, hostingEnvironment));
var memberTypeService = GetLazyService<IMemberTypeService>(factory, c => new MemberTypeService(scopeProvider, logger, eventMessagesFactory, memberService.Value, GetRepo<IMemberTypeRepository>(c), GetRepo<IAuditRepository>(c), GetRepo<IEntityRepository>(c)));
var entityService = GetLazyService<IEntityService>(factory, c => new EntityService(scopeProvider, logger, eventMessagesFactory, idkMap, GetRepo<IEntityRepository>(c)));
var macroService = GetLazyService<IMacroService>(factory, c => new MacroService(scopeProvider, logger, eventMessagesFactory, GetRepo<IMacroRepository>(c), GetRepo<IAuditRepository>(c)));
var packagingService = GetLazyService<IPackagingService>(factory, c =>
{
var compiledPackageXmlParser = new CompiledPackageXmlParser(new ConflictingPackageData(macroService.Value, fileService.Value), globalSettings);
return new PackagingService(
auditService.Value,
new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, hostingEnvironment,
new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, globalSettings, "createdPackages.config"),
new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, hostingEnvironment,
new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders, TestHelper.ShortStringHelper, propertyEditorCollection), logger, umbracoVersion, globalSettings, "installedPackages.config"),
new PackageInstallation(
new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider, shortStringHelper, GetGlobalSettings(), localizedTextService.Value),
new PackageFileInstallation(compiledPackageXmlParser, ioHelper, new ProfilingLogger(logger, new TestProfiler())),
compiledPackageXmlParser, Mock.Of<IPackageActionRunner>(),
Mock.Of<IHostingEnvironment>(x => x.ApplicationPhysicalPath == ioHelper.MapPath("~"))),
ioHelper);
});
var relationService = GetLazyService<IRelationService>(factory, c => new RelationService(scopeProvider, logger, eventMessagesFactory, entityService.Value, GetRepo<IRelationRepository>(c), GetRepo<IRelationTypeRepository>(c), GetRepo<IAuditRepository>(c)));
var tagService = GetLazyService<ITagService>(factory, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo<ITagRepository>(c)));
var redirectUrlService = GetLazyService<IRedirectUrlService>(factory, c => new RedirectUrlService(scopeProvider, logger, eventMessagesFactory, GetRepo<IRedirectUrlRepository>(c)));
var consentService = GetLazyService<IConsentService>(factory, c => new ConsentService(scopeProvider, logger, eventMessagesFactory, GetRepo<IConsentRepository>(c)));
var keyValueService = GetLazyService<IKeyValueService>(factory, c => new KeyValueService(scopeProvider, GetRepo<IKeyValueRepository>(c)));
var contentTypeServiceBaseFactory = GetLazyService<IContentTypeBaseServiceProvider>(factory, c => new ContentTypeBaseServiceProvider(factory.GetInstance<IContentTypeService>(),factory.GetInstance<IMediaTypeService>(),factory.GetInstance<IMemberTypeService>()));
return new ServiceContext(
publicAccessService,
domainService,
auditService,
localizedTextService,
tagService,
contentService,
userService,
memberService,
mediaService,
contentTypeService,
mediaTypeService,
dataTypeService,
fileService,
localizationService,
packagingService,
serverRegistrationService,
entityService,
relationService,
macroService,
memberTypeService,
memberGroupService,
notificationService,
externalLoginService,
redirectUrlService,
consentService,
keyValueService,
contentTypeServiceBaseFactory);
}
private Lazy<T> GetLazyService<T>(IFactory container, Func<IFactory, T> ctor)
where T : class
{

View File

@@ -325,7 +325,7 @@ namespace Umbraco.Extensions
var globalSettings = configs.Global();
hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment);
ioHelper = new IOHelper(hostingEnvironment, globalSettings);
ioHelper = new IOHelper(hostingEnvironment);
logger = AddLogger(services, hostingEnvironment, loggingConfiguration);
backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings);