* Tests * Remove props and use local vars * Adding preliminary navigation service and content implementation * Adding preliminary unit tests * Change from async methods * Refactor GetParentKey to TryGetParentKey * Refactor GetChildrenKeys to TryGetChildrenKeys * Refactor GetDescendantsKeys to TryGetDescendantsKeys * Refactor GetAncestorsKeys to TryGetAncestorsKeys * Refactor GetSiblingsKeys to TryGetSiblingsKeys * Refactor TryGetChildrenKeys * Initial integration tests * Use ContentEditingService instead of ContentService * Remove INavigationService.Copy implementation and unit tests * Rename var * Adding clarification * Initial ContentNavigationRepository * Initial NavigationFactory * Remove filtering from factory * NavigationRepository and implementation * InitializationService responsible for seeding the in-memory structure * Register repository and service * Adding NavigationDto and NavigationNode * Adding INavigationService dependency and Enlist updating navigation structure actions * Documentation * Adding tests for removing descendants as well * Changed to ConcurrentDictionary * Remove keys comments for tests * Adding documentation * Forgotten ConcurrentDictionary change * Isolating the operations on the model * Splitting the INavigationService to separate the querying from the managing functionality * Introducing specific navigation services for document, document recycle bin, media and media recycle bin * Making ContentNavigationService into a base as the functionality will be shared between the document, document recycle bin, media and media recycle bin services * Adding the implementations of document, document recycle bin, media and media recycle bin navigation services * Fixing comments * Initializing all 4 collections * Adapting the navigation unit tests to the base now * Adapting integration tests to specific navigation service * Adding test for rebuilding the structure * Adding implementation for Adding and Getting a node - needed for moving to and restoring from the recycle bin + tests * Updating the document navigation structure from the ContentService * Fix typo * Adding trashed items implementation in base - currently managing 2 structures * Removing no longer relevant GetNavigationNode and AddNavigationNode * Fix removing parent when child is removed supporting methods * Added restoring functionality * Adding Bin functionality to DocumentNavigationService * Removing Move signature from IDocumentNavigationService * Adding RecycleBin query and management services * Re-adding Move and removing GetNavigationNode and AddNavigationNode signatures from interface * Rebuilding bin structure using _documentNavigationService, instead of _documentRecycleBinNavigationService * Fixing test name * Adding more tests for remove * Adding tests for restore and removing ones for GetNavigationNode and AddNavigationNode * Remove comments * Removing document and media RecycleBinNavigationService and their interfaces * Adding media rebuild bin * Fixing initialization with correct interfaces * Removing RecycleBinNavigationServices' registration * Remove IDocumentRecycleBinNavigationService dependency * Updating in-memory nav structure when content updates happen * Adding the rest of the integration tests * Clean up IMediaNavigationService * Fix comments * Remove CustomTestSetup in integration tests as the structure is updated when content updates happen * Adding and fixing comments * Making RebuildBinAsync abstract as well * Adding DocumentNavigationServiceTestsBase * Splitting DocumentNavigationServiceTests into partial test classes * Cleaning up DocumentNavigationServiceTests since tests have been moved to specific partial classes * Reuse a method for creating content in tests * Change type in test base * Adding navigation structure updates in media service * Adding MediaNavigationServiceTestsBase * Adding integration tests for media nav str * Remove services as we will have more concrete ones * Add document and media IXNavigationQueryService and IXNavigationManagementService * Inject ManagementService in ContentService.cs and MediaService.cs * Change implementation to implement the new services + registration * Make classes sealed * Inject correct services in InitializationService * Using the right services in integration tests * Adding comments * Removing bin interfaces from main navigation ones * Rename Remove to MoveToBin * Added tests for Copy * Added additional tests * Split test * Added Media tests * Updated and added content tests * Cleaned up naming * Cleaned up * Rename initialization service to initialization hosted service * Refactor repository to return a collection * Add interface for the NavigationDto * Add constants to bind property names between DTOs * Move factory and fix input type * Use constants for column names * Use factory from base * Fixed indentation * Fix bug when rebuilding the recycle bin structure * Fix comments * Fix merged in code * Fix bug again after merge * Minor things --------- Co-authored-by: Elitsa <elm@umbraco.dk> Co-authored-by: Bjarke Berg <mail@bergmania.dk>
110 lines
5.3 KiB
C#
110 lines
5.3 KiB
C#
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
|
|
|
public partial class DocumentNavigationServiceTests
|
|
{
|
|
[Test]
|
|
[TestCase("A1B1B217-B02F-4307-862C-A5E22DB729EB", "A1B1B217-B02F-4307-862C-A5E22DB729EB")] // Grandchild 2 to itself
|
|
[TestCase("B606E3FF-E070-4D46-8CB9-D31352029FDF", "C6173927-0C59-4778-825D-D7B9F45D8DDE")] // Child 3 to Child 1
|
|
public async Task Structure_Updates_When_Copying_Content(Guid nodeToCopy, Guid targetParentKey)
|
|
{
|
|
// Arrange
|
|
DocumentNavigationQueryService.TryGetParentKey(nodeToCopy, out Guid? sourceParentKey);
|
|
|
|
// Act
|
|
var copyAttempt = await ContentEditingService.CopyAsync(nodeToCopy, targetParentKey, false, false, Constants.Security.SuperUserKey);
|
|
Guid copiedItemKey = copyAttempt.Result.Key;
|
|
|
|
// Assert
|
|
Assert.AreNotEqual(nodeToCopy, copiedItemKey);
|
|
|
|
DocumentNavigationQueryService.TryGetParentKey(copiedItemKey, out Guid? copiedItemParentKey);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.IsNotNull(copiedItemParentKey);
|
|
Assert.AreEqual(targetParentKey, copiedItemParentKey);
|
|
Assert.AreNotEqual(sourceParentKey, copiedItemParentKey);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Structure_Updates_When_Copying_Content_To_Root()
|
|
{
|
|
// Arrange
|
|
DocumentNavigationQueryService.TryGetParentKey(Grandchild2.Key, out Guid? sourceParentKey);
|
|
DocumentNavigationQueryService.TryGetSiblingsKeys(Root.Key, out IEnumerable<Guid> beforeCopyRootSiblingsKeys);
|
|
var initialRootSiblingsCount = beforeCopyRootSiblingsKeys.Count();
|
|
|
|
// Act
|
|
var copyAttempt = await ContentEditingService.CopyAsync(Grandchild2.Key, null, false, false, Constants.Security.SuperUserKey);
|
|
Guid copiedItemKey = copyAttempt.Result.Key;
|
|
|
|
// Assert
|
|
Assert.AreNotEqual(Grandchild2.Key, copiedItemKey);
|
|
|
|
DocumentNavigationQueryService.TryGetParentKey(copiedItemKey, out Guid? copiedItemParentKey);
|
|
DocumentNavigationQueryService.TryGetSiblingsKeys(Root.Key, out IEnumerable<Guid> afterCopyRootSiblingsKeys);
|
|
DocumentNavigationQueryService.TryGetChildrenKeys(sourceParentKey.Value, out IEnumerable<Guid> sourceParentChildrenKeys);
|
|
List<Guid> rootSiblingsList = afterCopyRootSiblingsKeys.ToList();
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
// Verifies that the node actually has been copied
|
|
Assert.AreNotEqual(sourceParentKey, copiedItemParentKey);
|
|
Assert.IsNull(copiedItemParentKey);
|
|
|
|
// Verifies that the siblings amount has been updated after copying
|
|
Assert.AreEqual(initialRootSiblingsCount + 1, rootSiblingsList.Count);
|
|
Assert.IsTrue(rootSiblingsList.Contains(copiedItemKey));
|
|
|
|
// Verifies that the node was copied and not moved
|
|
Assert.IsTrue(sourceParentChildrenKeys.Contains(Grandchild2.Key));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Structure_Updates_When_Copying_Content_With_Descendants()
|
|
{
|
|
// Arrange
|
|
DocumentNavigationQueryService.TryGetParentKey(Grandchild3.Key, out Guid? sourceParentKey);
|
|
DocumentNavigationQueryService.TryGetDescendantsKeys(Grandchild3.Key, out IEnumerable<Guid> beforeCopyGrandChild1Descendents);
|
|
DocumentNavigationQueryService.TryGetChildrenKeys(Child3.Key, out IEnumerable<Guid> beforeCopyChild3ChildrenKeys);
|
|
var initialChild3ChildrenCount = beforeCopyChild3ChildrenKeys.Count();
|
|
var initialGrandChild1DescendentsCount = beforeCopyGrandChild1Descendents.Count();
|
|
|
|
// Act
|
|
var copyAttempt = await ContentEditingService.CopyAsync(Grandchild3.Key, Child3.Key, false, true, Constants.Security.SuperUserKey);
|
|
Guid copiedItemKey = copyAttempt.Result.Key;
|
|
|
|
// Assert
|
|
Assert.AreNotEqual(Grandchild3.Key, copiedItemKey);
|
|
|
|
DocumentNavigationQueryService.TryGetParentKey(copiedItemKey, out Guid? copiedItemParentKey);
|
|
DocumentNavigationQueryService.TryGetChildrenKeys(Child3.Key, out IEnumerable<Guid> afterCopyChild3ChildrenKeys);
|
|
DocumentNavigationQueryService.TryGetChildrenKeys(copiedItemKey, out IEnumerable<Guid> afterCopyGrandChild1Descendents);
|
|
List<Guid> child3ChildrenList = afterCopyChild3ChildrenKeys.ToList();
|
|
List<Guid> grandChild1DescendantsList = afterCopyGrandChild1Descendents.ToList();
|
|
|
|
// Retrieves the child of the copied item to check its content
|
|
var copiedGreatGrandChild1 = await ContentEditingService.GetAsync(grandChild1DescendantsList.First());
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
// Verifies that the node actually has been copied
|
|
Assert.AreNotEqual(sourceParentKey, copiedItemParentKey);
|
|
Assert.AreEqual(Child3.Key, copiedItemParentKey);
|
|
Assert.AreEqual(initialChild3ChildrenCount + 1, child3ChildrenList.Count);
|
|
|
|
// Verifies that the descendant amount is the same for the original and the moved GrandChild1 node
|
|
Assert.AreEqual(initialGrandChild1DescendentsCount, grandChild1DescendantsList.Count);
|
|
|
|
// Verifies that the keys are not the same
|
|
Assert.AreEqual(GreatGrandchild1.Name, copiedGreatGrandChild1.Name);
|
|
Assert.AreNotEqual(GreatGrandchild1.Key, copiedGreatGrandChild1.Key);
|
|
});
|
|
}
|
|
}
|