Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/ManagementApi/Services/Trees/ScriptTreeServiceTests.cs

72 lines
2.5 KiB
C#
Raw Normal View History

Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
using NUnit.Framework;
using Umbraco.Cms.Api.Management.Services.FileSystem;
using Umbraco.Cms.Api.Management.ViewModels.Tree;
using Umbraco.Cms.Core.IO;
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Services.Trees;
public class ScriptTreeServiceTests : FileSystemTreeServiceTestsBase
{
protected override string FileExtension { get; set; } = ".js";
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
protected override string FileSystemPath => GlobalSettings.UmbracoScriptsPath;
protected override IFileSystem? GetScriptsFileSystem() => TestFileSystem;
[Test]
public void Can_Get_Siblings()
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
{
var service = new ScriptTreeService(FileSystems);
FileSystemTreeItemPresentationModel[] treeModel = service.GetSiblingsViewModels($"file5{FileExtension}", 1, 1, out long before, out var after);
int index = Array.FindIndex(treeModel, item => item.Name == $"file5{FileExtension}");
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
Assert.AreEqual(treeModel[index].Name, $"file5{FileExtension}");
Assert.AreEqual(treeModel[index - 1].Name, $"file4{FileExtension}");
Assert.AreEqual(treeModel[index + 1].Name, $"file6{FileExtension}");
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
Assert.That(treeModel.Length == 3);
Assert.AreEqual(after, 3);
Assert.AreEqual(before, 4);
}
[Test]
public void Can_Get_Ancestors()
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
{
var service = new ScriptTreeService(FileSystems);
var path = Path.Join("tests", $"file5{FileExtension}");
FileSystemTreeItemPresentationModel[] treeModels = service.GetAncestorModels(path, true);
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
Assert.IsNotEmpty(treeModels);
Assert.AreEqual(treeModels.Length, 2);
Assert.AreEqual(treeModels[0].Name, "tests");
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
}
[Test]
public void Can_Get_PathViewModels()
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
{
var service = new ScriptTreeService(FileSystems);
FileSystemTreeItemPresentationModel[] treeModels = service.GetPathViewModels(string.Empty, 0, int.MaxValue, out var totalItems);
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
Assert.IsNotEmpty(treeModels);
Assert.AreEqual(treeModels.Length, totalItems);
}
[Test]
public void Will_Hide_Unsupported_File_Extensions()
{
var service = new ScriptTreeService(FileSystems);
for (int i = 0; i < 2; i++)
{
using var stream = CreateStream();
TestFileSystem.AddFile($"file{i}.invalid", stream);
}
FileSystemTreeItemPresentationModel[] treeModels = service.GetPathViewModels(string.Empty, 0, int.MaxValue, out var totalItems);
Assert.IsEmpty(treeModels.Where(file => file.Name.Contains(".invalid")));
Assert.AreEqual(treeModels.Length, totalItems);
}
Trees: Expanding sibling endpoints to include all entities with trees (#20150) * 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>
2025-09-23 11:17:25 +02:00
}