* Removed obsoletes from IConfigManipulator. * Removed obsolete models builder extensions. * Removed the obsolete ContentDashboardSettings. * Removed the obsolete InstallMissingDatabase setting on GlobalSettings. * Removed obsolete NuCache settings. * Removed obsolete RuntimeMinificationSettings. * Removed obsolete health check constant. * Removed obsolete icon constant. * Removed obsolete telemetry constant. * Removed obsolete property and constructor on UmbracoBuilder. * Removed obsolete constructor on AuditNotificationsHandler. * Removed obsolete constructor on HTTP header health checks. * Removed obsolete constructor on MediaFileManager. * Removed obsolete GetDefaultFileContent on ViewHelper. * Remove obsoleted methods on embed providers. * Fix tests. * Removed obsolete constructors on BlockEditorDataConverter. * Removed obsolete SeedCacheDuration property on CacheSettings. * Removed obsolete PublishCulture on ContentRepositoryExtensions. * Removed obsolete MonitorLock. * Removed obsolete synchronous HasSavedValues from IDataTypeUsageService and IDataTypeUsageRepository. * Removed obsolete HasSavedPropertyValues from IPropertyTypeUsageService and IPropertyTypeUsageRepository. * Removed obsolete methods in ITrackedReferencesService and ITrackedReferencesRepository. * Removed obsolete DateValueEditor constructors. * Removed obsolete GetAutomaticRelationTypesAliases. * Removed obsolete constructor on TextOnlyValueEditor. * Removed obsolete constructors on RegexValidator and RequiredValidator. * Removed obsolete constructs on SliderValueConverter and TagsValueConverter. * Removed obsolete GetContentType methods from IPublishedCache. * Removed ContentFinderByIdPath. * Removed obsolete constructor on DefaultMediaUrlProvider. * Removed obsolete constructor on Domain. * Removed obsolete constructor on PublishedRequest. * Removed obsolete methods on CheckPermissions. * Removed obsolete GetUserId from IBackOfficeSecurity. * Removed obsolete methods on LegacyPasswordSecurity. * Removed obsolete constructors on AuditService. * Removed obsolete methods on IContentEditingService. * Remove obsolete constructors and methods on ContentService/IContentService. * Removed obsolete constructor in ContentTypeEditingService. * Removed obsolete constructor in MediaTypeEditingService. * Removed obsolete constructor in MemberTypeEditingService. * Removed obsolete constructor in ContentTypeService. * Removed obsolete constructors in ContentTypeServiceBase. * Removed obsolete constructors and methods in ContentVersionService. * Removed obsolete constructor in DataTypeUsageService. * Removed obsolete constructor in DomainService. * Removed obsolete constructor in FileService. * Removes obsolete AttemptMove from IContentService. * Removes obsolete SetPreventCleanup from IContentVersionService. * Removes obsolete GetReferences from IDataTypeService. * Removed obsolete SetConsentLevel from IMetricsConsentService. * Removed obsolete methods from IPackageDataInstallation. * Removed obsolete methods from IPackagingService. * Removed obsolete methods on ITwoFactorLoginService. Removed obsolete ITemporaryMediaService. * Removed obsolete constructor from MediaService, MemberTypeService and MediaTypeService. * More obsolete constructors. * Removed obsoleted overloads on IPropertyValidationService. * Fixed build for tests. * Removed obsolete constructor for PublicAccessService, UserService and RelationService. * Removed GetDefaultMemberType. * Removed obsolete user group functionality from IUserService. * Removed obsolete extension methods on IUserService. * Removed obsolete method from ITelemetryService. * Removed obsolete UdiParserServiceConnectors. * Removed obsolete method on ICookieManager. * Removed obsolete DynamicContext. * Removed obsolete XmlHelper. * Fixed failing integration tests. * Removed obsoletes in Umbraco.Cms.Api.Common * Removed obsoletes in Umbraco.Cms.Api.Delivery * Removed obsoletes in Umbraco.Cms.Api.Management * Removed obsoletes in Umbraco.Examine.Lucene * Removed obsoletes in Umbraco.Infrastructure * Fix failing delivery API contract integration test. * Made integration tests internal. * Removed obsoletes from web projects. * Fix build. * Removed Twitter OEmbed provider * Removed obsolete constructor on PublishedDataType. * Removed obsolete constructors on PublishedCacheBase. * Removed the obsolete PropertyEditorTagsExtensions. * Removed obsoletion properties on configuration response models (#18697) * Removed obsolete methods from server-side models. * Update client-side types and sdk. * Update client-side files. * Removed obsoletion of Utf8ToAsciiConverter.ToAsciiString overload. (#18694) * Removed obsolete method in UserService. (#18710) * Removed obsoleted group alias keys from being publicly available. (#18682) * Removed unneceessary ApiVersion attribute. * Clean-up obsoletions on MemberService (#18703) * Removed obsoleted method on MemberService, added future obsoletion to interface and updated all callers. * Removed obsoletion on member service method that's not obsolete on the interface.
212 lines
8.5 KiB
C#
212 lines
8.5 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Hosting;
|
|
using Umbraco.Cms.Core.IO;
|
|
using Umbraco.Cms.Persistence.EFCore.Scoping;
|
|
using Umbraco.Cms.Tests.Common;
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
using Umbraco.Cms.Tests.Integration.Umbraco.Persistence.EFCore.DbContext;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Persistence.EFCore.Scoping;
|
|
|
|
[TestFixture]
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console)]
|
|
internal sealed class EFCoreScopedFileSystemsTests : UmbracoIntegrationTest
|
|
{
|
|
[SetUp]
|
|
public void SetUp() => ClearFiles(IOHelper);
|
|
|
|
[TearDown]
|
|
public void Teardown() => ClearFiles(IOHelper);
|
|
|
|
private MediaFileManager MediaFileManager => GetRequiredService<MediaFileManager>();
|
|
|
|
private IHostingEnvironment HostingEnvironment => GetRequiredService<IHostingEnvironment>();
|
|
|
|
private IEFCoreScopeProvider<TestUmbracoDbContext> EfCoreScopeProvider => GetRequiredService<IEFCoreScopeProvider<TestUmbracoDbContext>>();
|
|
private IEFCoreScopeAccessor<TestUmbracoDbContext> EfCoreScopeAccessor => GetRequiredService<IEFCoreScopeAccessor<TestUmbracoDbContext>>();
|
|
|
|
private void ClearFiles(IIOHelper ioHelper)
|
|
{
|
|
TestHelper.DeleteDirectory(ioHelper.MapPath("media"));
|
|
TestHelper.DeleteDirectory(ioHelper.MapPath("FileSysTests"));
|
|
TestHelper.DeleteDirectory(ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
|
|
}
|
|
|
|
[Test]
|
|
public void MediaFileManager_Does_Not_Write_To_Physical_File_System_When_Scoped_If_Scope_Does_Not_Complete()
|
|
{
|
|
var rootPath = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoMediaPhysicalRootPath);
|
|
var rootUrl = HostingEnvironment.ToAbsolute(GlobalSettings.UmbracoMediaPath);
|
|
var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, GetRequiredService<ILogger<PhysicalFileSystem>>(), rootPath, rootUrl);
|
|
var mediaFileManager = MediaFileManager;
|
|
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
|
|
using (EfCoreScopeProvider.CreateScope(scopeFileSystems: true))
|
|
{
|
|
using (var ms = new MemoryStream("foo"u8.ToArray()))
|
|
{
|
|
MediaFileManager.FileSystem.AddFile("f1.txt", ms);
|
|
}
|
|
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
}
|
|
|
|
// After scope is disposed ensure shadow wrapper didn't commit to physical
|
|
Assert.IsFalse(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
}
|
|
|
|
[Test]
|
|
public void MediaFileManager_Writes_To_Physical_File_System_When_Scoped_And_Scope_Is_Completed()
|
|
{
|
|
var rootPath = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoMediaPhysicalRootPath);
|
|
var rootUrl = HostingEnvironment.ToAbsolute(GlobalSettings.UmbracoMediaPath);
|
|
var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, GetRequiredService<ILogger<PhysicalFileSystem>>(), rootPath, rootUrl);
|
|
var mediaFileManager = MediaFileManager;
|
|
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
|
|
using (var scope = EfCoreScopeProvider.CreateScope(scopeFileSystems: true))
|
|
{
|
|
using (var ms = new MemoryStream("foo"u8.ToArray()))
|
|
{
|
|
mediaFileManager.FileSystem.AddFile("f1.txt", ms);
|
|
}
|
|
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
|
|
scope.Complete();
|
|
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
}
|
|
|
|
// After scope is disposed ensure shadow wrapper writes to physical file system
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
Assert.IsTrue(physMediaFileSystem.FileExists("f1.txt"));
|
|
}
|
|
|
|
[Test]
|
|
public void MultiThread()
|
|
{
|
|
var rootPath = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoMediaPhysicalRootPath);
|
|
var rootUrl = HostingEnvironment.ToAbsolute(GlobalSettings.UmbracoMediaPath);
|
|
var physMediaFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, GetRequiredService<ILogger<PhysicalFileSystem>>(), rootPath, rootUrl);
|
|
var mediaFileManager = MediaFileManager;
|
|
var taskHelper = new TaskHelper(Mock.Of<ILogger<TaskHelper>>());
|
|
|
|
using (EfCoreScopeProvider.CreateScope(scopeFileSystems: true))
|
|
{
|
|
using (var ms = new MemoryStream("foo"u8.ToArray()))
|
|
{
|
|
mediaFileManager.FileSystem.AddFile("f1.txt", ms);
|
|
}
|
|
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
|
|
|
|
// execute on another disconnected thread (execution context will not flow)
|
|
var t = taskHelper.ExecuteBackgroundTask(() =>
|
|
{
|
|
Assert.IsFalse(mediaFileManager.FileSystem.FileExists("f1.txt"));
|
|
|
|
using (var ms = new MemoryStream("foo"u8.ToArray()))
|
|
{
|
|
mediaFileManager.FileSystem.AddFile("f2.txt", ms);
|
|
}
|
|
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f2.txt"));
|
|
Assert.IsTrue(physMediaFileSystem.FileExists("f2.txt"));
|
|
|
|
return Task.CompletedTask;
|
|
});
|
|
|
|
t.Wait();
|
|
|
|
Assert.IsTrue(mediaFileManager.FileSystem.FileExists("f2.txt"));
|
|
Assert.IsTrue(physMediaFileSystem.FileExists("f2.txt"));
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void SingleShadow()
|
|
{
|
|
var taskHelper = new TaskHelper(Mock.Of<ILogger<TaskHelper>>());
|
|
var isThrown = false;
|
|
using (EfCoreScopeProvider.CreateScope(scopeFileSystems: true))
|
|
{
|
|
// This is testing when another thread concurrently tries to create a scoped file system
|
|
// because at the moment we don't support concurrent scoped filesystems.
|
|
var t = taskHelper.ExecuteBackgroundTask(() =>
|
|
{
|
|
// ok to create a 'normal' other scope
|
|
using (var other = EfCoreScopeProvider.CreateScope())
|
|
{
|
|
other.Complete();
|
|
}
|
|
|
|
// not ok to create a 'scoped filesystems' other scope
|
|
// we will get a "Already shadowing." exception.
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
using var other = EfCoreScopeProvider.CreateScope(scopeFileSystems: true);
|
|
});
|
|
|
|
isThrown = true;
|
|
|
|
return Task.CompletedTask;
|
|
});
|
|
|
|
t.Wait();
|
|
}
|
|
|
|
Assert.IsTrue(isThrown);
|
|
}
|
|
|
|
[Test]
|
|
public void SingleShadowEvenDetached()
|
|
{
|
|
var taskHelper = new TaskHelper(Mock.Of<ILogger<TaskHelper>>());
|
|
using (var scope = EfCoreScopeProvider.CreateScope(scopeFileSystems: true))
|
|
{
|
|
// This is testing when another thread concurrently tries to create a scoped file system
|
|
// because at the moment we don't support concurrent scoped filesystems.
|
|
var t = taskHelper.ExecuteBackgroundTask(() =>
|
|
{
|
|
// not ok to create a 'scoped filesystems' other scope
|
|
// because at the moment we don't support concurrent scoped filesystems
|
|
// even a detached one
|
|
// we will get a "Already shadowing." exception.
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
using var other = EfCoreScopeProvider.CreateDetachedScope(scopeFileSystems: true);
|
|
});
|
|
|
|
return Task.CompletedTask;
|
|
});
|
|
|
|
t.Wait();
|
|
}
|
|
|
|
var detached = EfCoreScopeProvider.CreateDetachedScope(scopeFileSystems: true);
|
|
|
|
Assert.IsNull(EfCoreScopeAccessor.AmbientScope);
|
|
|
|
Assert.Throws<InvalidOperationException>(() =>
|
|
{
|
|
// even if there is no ambient scope, there's a single shadow
|
|
using var other = EfCoreScopeProvider.CreateScope(scopeFileSystems: true);
|
|
});
|
|
|
|
EfCoreScopeProvider.AttachScope(detached);
|
|
detached.Dispose();
|
|
}
|
|
}
|