Clear roots before rebuilding navigation dictionary (#18766)
* Clear roots before rebuilding navigation dictionary. * Added tests to verify fix. * Correct test implementation. * Convert integration tests with method overloads into test cases. * Integration test compatibility supressions.
This commit is contained in:
@@ -293,12 +293,12 @@ internal abstract class ContentNavigationServiceBase<TContentType, TContentTypeS
|
||||
/// <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);
|
||||
@@ -307,14 +307,18 @@ internal abstract class ContentNavigationServiceBase<TContentType, TContentTypeS
|
||||
// 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)
|
||||
|
||||
@@ -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>
|
||||
@@ -92,6 +106,13 @@
|
||||
<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>
|
||||
<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_IsApproved_Without_Access</Target>
|
||||
@@ -106,13 +127,6 @@
|
||||
<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>
|
||||
<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.TemplateServiceTests.Deleting_Master_Template_Also_Deletes_Children</Target>
|
||||
|
||||
@@ -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;
|
||||
@@ -21,6 +22,7 @@ public partial class DocumentNavigationServiceTests
|
||||
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(
|
||||
@@ -30,7 +32,10 @@ public partial class DocumentNavigationServiceTests
|
||||
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);
|
||||
@@ -38,6 +43,7 @@ public partial class DocumentNavigationServiceTests
|
||||
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(() =>
|
||||
@@ -53,11 +59,13 @@ public partial class DocumentNavigationServiceTests
|
||||
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;
|
||||
@@ -69,6 +77,7 @@ public partial class DocumentNavigationServiceTests
|
||||
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(
|
||||
@@ -78,7 +87,10 @@ public partial class DocumentNavigationServiceTests
|
||||
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);
|
||||
@@ -86,6 +98,7 @@ public partial class DocumentNavigationServiceTests
|
||||
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(() =>
|
||||
@@ -101,6 +114,7 @@ public partial class DocumentNavigationServiceTests
|
||||
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
|
||||
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
|
||||
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
|
||||
CollectionAssert.AreEquivalent(originalRouteKeys, routeKeysFromRebuild);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user