Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ public bool RestoreFromBin(Guid key, Guid? targetParentKey = null)
/// <param name="readLock">The read lock value, should be -333 or -334 for content and media trees.</param>
/// <param name="objectTypeKey">The key of the object type to rebuild.</param>
/// <param name="trashed">Indicates whether the items are in the recycle bin.</param>
protected async Task HandleRebuildAsync(int readLock, Guid objectTypeKey, bool trashed)
protected Task HandleRebuildAsync(int readLock, Guid objectTypeKey, bool trashed)
{
// This is only relevant for items in the content and media trees
if (readLock != Constants.Locks.ContentTree && readLock != Constants.Locks.MediaTree)
{
return;
return Task.CompletedTask;
}

using ICoreScope scope = _coreScopeProvider.CreateCoreScope(autoComplete: true);
Expand All @@ -307,14 +307,18 @@ protected async Task HandleRebuildAsync(int readLock, Guid objectTypeKey, bool t
// Build the corresponding navigation structure
if (trashed)
{
_recycleBinRoots.Clear();
IEnumerable<INavigationModel> navigationModels = _navigationRepository.GetTrashedContentNodesByObjectType(objectTypeKey);
BuildNavigationDictionary(_recycleBinNavigationStructure, _recycleBinRoots, navigationModels);
}
else
{
_roots.Clear();
IEnumerable<INavigationModel> navigationModels = _navigationRepository.GetContentNodesByObjectType(objectTypeKey);
BuildNavigationDictionary(_navigationStructure, _roots, navigationModels);
}

return Task.CompletedTask;
}

private bool TryGetParentKeyFromStructure(ConcurrentDictionary<Guid, NavigationNode> structure, Guid childKey, out Guid? parentKey)
Expand Down
20 changes: 17 additions & 3 deletions tests/Umbraco.Tests.Integration/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@
<Right>lib/net9.0/Umbraco.Tests.Integration.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Core.Services.DocumentNavigationServiceTests.Bin_Structure_Can_Rebuild</Target>
<Left>lib/net9.0/Umbraco.Tests.Integration.dll</Left>
<Right>lib/net9.0/Umbraco.Tests.Integration.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Core.Services.DocumentNavigationServiceTests.Structure_Can_Rebuild</Target>
<Left>lib/net9.0/Umbraco.Tests.Integration.dll</Left>
<Right>lib/net9.0/Umbraco.Tests.Integration.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Core.Services.UserServiceCrudTests.Cannot_Request_Disabled_If_Hidden(Umbraco.Cms.Core.Models.Membership.UserState)</Target>
Expand All @@ -94,21 +108,21 @@
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.MemberEditingServiceTests.Cannot_Change_IsApproved_Without_Access</Target>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.EntityServiceTests.CreateTestData</Target>
<Left>lib/net9.0/Umbraco.Tests.Integration.dll</Left>
<Right>lib/net9.0/Umbraco.Tests.Integration.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.MemberEditingServiceTests.Cannot_Change_IsLockedOut_Without_Access</Target>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.MemberEditingServiceTests.Cannot_Change_IsApproved_Without_Access</Target>
<Left>lib/net9.0/Umbraco.Tests.Integration.dll</Left>
<Right>lib/net9.0/Umbraco.Tests.Integration.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.EntityServiceTests.CreateTestData</Target>
<Target>M:Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services.MemberEditingServiceTests.Cannot_Change_IsLockedOut_Without_Access</Target>
<Left>lib/net9.0/Umbraco.Tests.Integration.dll</Left>
<Right>lib/net9.0/Umbraco.Tests.Integration.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;

public partial class DocumentNavigationServiceTests
{
[Test]
public async Task Structure_Can_Rebuild()
[TestCase(1, TestName = "Structure_Can_Rebuild")]
[TestCase(2, TestName = "Structure_Can_Rebuild_MultipleTimes")]
public async Task Structure_Can_Rebuild(int numberOfRebuilds)
{
// Arrange
Guid nodeKey = Root.Key;
Expand All @@ -21,6 +22,7 @@ public async Task Structure_Can_Rebuild()
DocumentNavigationQueryService.TryGetDescendantsKeys(nodeKey, out IEnumerable<Guid> originalDescendantsKeys);
DocumentNavigationQueryService.TryGetAncestorsKeys(nodeKey, out IEnumerable<Guid> originalAncestorsKeys);
DocumentNavigationQueryService.TryGetSiblingsKeys(nodeKey, out IEnumerable<Guid> originalSiblingsKeys);
DocumentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> originalRouteKeys);

// In-memory navigation structure is empty here
var newDocumentNavigationService = new DocumentNavigationService(
Expand All @@ -30,14 +32,18 @@ public async Task Structure_Can_Rebuild()
var initialNodeExists = newDocumentNavigationService.TryGetParentKey(nodeKey, out _);

// Act
await newDocumentNavigationService.RebuildAsync();
for (int i = 0; i < numberOfRebuilds; i++)
{
await newDocumentNavigationService.RebuildAsync();
}

// Capture rebuilt state
var nodeExists = newDocumentNavigationService.TryGetParentKey(nodeKey, out Guid? parentKeyFromRebuild);
newDocumentNavigationService.TryGetChildrenKeys(nodeKey, out IEnumerable<Guid> childrenKeysFromRebuild);
newDocumentNavigationService.TryGetDescendantsKeys(nodeKey, out IEnumerable<Guid> descendantsKeysFromRebuild);
newDocumentNavigationService.TryGetAncestorsKeys(nodeKey, out IEnumerable<Guid> ancestorsKeysFromRebuild);
newDocumentNavigationService.TryGetSiblingsKeys(nodeKey, out IEnumerable<Guid> siblingsKeysFromRebuild);
newDocumentNavigationService.TryGetRootKeys(out IEnumerable<Guid> routeKeysFromRebuild);

// Assert
Assert.Multiple(() =>
Expand All @@ -53,11 +59,13 @@ public async Task Structure_Can_Rebuild()
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalRouteKeys, routeKeysFromRebuild);
});
}

[Test]
public async Task Bin_Structure_Can_Rebuild()
[TestCase(1, TestName = "Bin_Structure_Can_Rebuild")]
[TestCase(2, TestName = "Bin_Structure_Can_Rebuild_MultipleTimes")]
public async Task Bin_Structure_Can_Rebuild(int numberOfRebuilds)
{
// Arrange
Guid nodeKey = Root.Key;
Expand All @@ -69,6 +77,7 @@ public async Task Bin_Structure_Can_Rebuild()
DocumentNavigationQueryService.TryGetDescendantsKeysInBin(nodeKey, out IEnumerable<Guid> originalDescendantsKeys);
DocumentNavigationQueryService.TryGetAncestorsKeysInBin(nodeKey, out IEnumerable<Guid> originalAncestorsKeys);
DocumentNavigationQueryService.TryGetSiblingsKeysInBin(nodeKey, out IEnumerable<Guid> originalSiblingsKeys);
DocumentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> originalRouteKeys);

// In-memory navigation structure is empty here
var newDocumentNavigationService = new DocumentNavigationService(
Expand All @@ -78,14 +87,18 @@ public async Task Bin_Structure_Can_Rebuild()
var initialNodeExists = newDocumentNavigationService.TryGetParentKeyInBin(nodeKey, out _);

// Act
await newDocumentNavigationService.RebuildBinAsync();
for (int i = 0; i < numberOfRebuilds; i++)
{
await newDocumentNavigationService.RebuildBinAsync();
}

// Capture rebuilt state
var nodeExists = newDocumentNavigationService.TryGetParentKeyInBin(nodeKey, out Guid? parentKeyFromRebuild);
newDocumentNavigationService.TryGetChildrenKeysInBin(nodeKey, out IEnumerable<Guid> childrenKeysFromRebuild);
newDocumentNavigationService.TryGetDescendantsKeysInBin(nodeKey, out IEnumerable<Guid> descendantsKeysFromRebuild);
newDocumentNavigationService.TryGetAncestorsKeysInBin(nodeKey, out IEnumerable<Guid> ancestorsKeysFromRebuild);
newDocumentNavigationService.TryGetSiblingsKeysInBin(nodeKey, out IEnumerable<Guid> siblingsKeysFromRebuild);
newDocumentNavigationService.TryGetRootKeys(out IEnumerable<Guid> routeKeysFromRebuild);

// Assert
Assert.Multiple(() =>
Expand All @@ -101,6 +114,7 @@ public async Task Bin_Structure_Can_Rebuild()
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
CollectionAssert.AreEquivalent(originalRouteKeys, routeKeysFromRebuild);
});
}
}