* Adding member types sibling endpoints * Introducing sibling endpoint for Partial Views and logic. * Introducing sibling endpoint for stylesheets * Introducing sibling endpoint for scripts * Introducing FileSystemTreeServiceBase.cs * Introducing interfaces for implementation specific services * Introducing services for specific trees * Modifying controller bases to fit new interface and logic. * Obsoleting old constructors related to PartialView * Obsoleting ctors related to Stylesheets * Obsoleting ctors related to scripts * Adding tests for scriptsTreeService * Adding tests for siblings * Removing unused dependencies * Removing signs and replacing it with flags * Fixing breaking changes by obsoletion * Fixing more breaking changes * Registering missing service * Fixing breaking changes again * Changing name of method GetSiblingsViewModels * Rewritten tests for less bloat and less duplicate code * Expanding tests to include other methods from service * Test refactoring: avoided populating file systems that weren't under test, updated encapsulation, renaming, further re-use. * Management API: Expanding the existing sibling endpoints to support trashed entities (#20154) * Refactoring existing logic to include trashed items * Including tests for trashed entities * Groundwork for trashed siblings * Documents trashed siblings endpoint * Controller for Media trashed items * Expanding tests to include a test for trashed siblings * Code review corrections * Resolving code review --------- Co-authored-by: Andy Butland <abutland73@gmail.com>
84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
using System.Text;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Hosting;
|
|
using Umbraco.Cms.Core.IO;
|
|
using Umbraco.Cms.Tests.Common.TestHelpers;
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Services.Trees;
|
|
|
|
public abstract class FileSystemTreeServiceTestsBase : UmbracoIntegrationTest
|
|
{
|
|
protected FileSystems FileSystems { get; private set; }
|
|
|
|
protected IFileSystem TestFileSystem { get; private set; }
|
|
|
|
protected abstract string FileSystemPath { get; }
|
|
|
|
protected IHostingEnvironment HostingEnvironment => GetRequiredService<IHostingEnvironment>();
|
|
|
|
[SetUp]
|
|
public void SetUpFileSystem()
|
|
{
|
|
TestFileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger<PhysicalFileSystem>(), HostingEnvironment.MapPathWebRoot(FileSystemPath), HostingEnvironment.ToAbsolute(FileSystemPath));
|
|
|
|
FileSystems = FileSystemsCreator.CreateTestFileSystems(
|
|
LoggerFactory,
|
|
IOHelper,
|
|
GetRequiredService<IOptions<GlobalSettings>>(),
|
|
HostingEnvironment,
|
|
GetPartialViewsFileSystem(),
|
|
GetStylesheetsFileSystem(),
|
|
GetScriptsFileSystem(),
|
|
null);
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
using var stream = CreateStream(Path.Join("tests"));
|
|
TestFileSystem.AddFile($"file{i}", stream);
|
|
}
|
|
}
|
|
|
|
private static Stream CreateStream(string contents = null)
|
|
{
|
|
if (string.IsNullOrEmpty(contents))
|
|
{
|
|
contents = "/* test */";
|
|
}
|
|
|
|
var bytes = Encoding.UTF8.GetBytes(contents);
|
|
return new MemoryStream(bytes);
|
|
}
|
|
|
|
protected virtual IFileSystem? GetPartialViewsFileSystem() => null;
|
|
|
|
protected virtual IFileSystem? GetStylesheetsFileSystem() => null;
|
|
|
|
protected virtual IFileSystem? GetScriptsFileSystem() => null;
|
|
|
|
[TearDown]
|
|
public void TearDownFileSystem()
|
|
{
|
|
Purge(TestFileSystem, string.Empty);
|
|
FileSystems = null;
|
|
}
|
|
|
|
private static void Purge(IFileSystem fs, string path)
|
|
{
|
|
var files = fs.GetFiles(path, "*");
|
|
foreach (var file in files)
|
|
{
|
|
fs.DeleteFile(file);
|
|
}
|
|
|
|
var dirs = fs.GetDirectories(path);
|
|
foreach (var dir in dirs)
|
|
{
|
|
Purge(fs, dir);
|
|
fs.DeleteDirectory(dir);
|
|
}
|
|
}
|
|
}
|