* Adding contentType to navigation node * Loading contentType from DB * Considering contentTypeKey when adding a navigation node & fixing references * Using IContentTypeBaseService to load content types * Adding generics to ContentNavigationServiceBase and fixing references * Adding TryGetChildrenKeysOfType and implementation * Refactoring test data * Adding unit tests for TryGetChildrenKeysOfType * Update CreateContentCreateModel in tests to receive content type * Fix references * Cleanup * Adding integration tests for TryGetChildrenKeysOfType * Cleanup * Cleanup * Descendants of type implementation * Descendants of type tests * Interface updates * Ancestors of type implementation and tests * Siblings of type implementation and tests * Cleanup * Integration tests * Adding root of type implementation and tests * Fix Ancestors extension methods * Fix descendants extension methods * Fix children extension methods * Fix siblings extension methods * Add helper methods * Fix a bug * Fixed unit tests by setting up mocks * Adding missing extension method --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
107 lines
5.5 KiB
C#
107 lines
5.5 KiB
C#
using NUnit.Framework;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
|
using Umbraco.Cms.Core.Scoping;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Core.Services.Navigation;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
|
|
|
|
public partial class MediaNavigationServiceTests
|
|
{
|
|
[Test]
|
|
public async Task Structure_Can_Rebuild()
|
|
{
|
|
// Arrange
|
|
Guid nodeKey = Album.Key;
|
|
|
|
// Capture original built state of MediaNavigationQueryService
|
|
MediaNavigationQueryService.TryGetParentKey(nodeKey, out Guid? originalParentKey);
|
|
MediaNavigationQueryService.TryGetChildrenKeys(nodeKey, out IEnumerable<Guid> originalChildrenKeys);
|
|
MediaNavigationQueryService.TryGetDescendantsKeys(nodeKey, out IEnumerable<Guid> originalDescendantsKeys);
|
|
MediaNavigationQueryService.TryGetAncestorsKeys(nodeKey, out IEnumerable<Guid> originalAncestorsKeys);
|
|
MediaNavigationQueryService.TryGetSiblingsKeys(nodeKey, out IEnumerable<Guid> originalSiblingsKeys);
|
|
|
|
// In-memory navigation structure is empty here
|
|
var newMediaNavigationService = new MediaNavigationService(
|
|
GetRequiredService<ICoreScopeProvider>(),
|
|
GetRequiredService<INavigationRepository>(),
|
|
GetRequiredService<IMediaTypeService>());
|
|
var initialNodeExists = newMediaNavigationService.TryGetParentKey(nodeKey, out _);
|
|
|
|
// Act
|
|
await newMediaNavigationService.RebuildAsync();
|
|
|
|
// Capture rebuilt state
|
|
var nodeExists = newMediaNavigationService.TryGetParentKey(nodeKey, out Guid? parentKeyFromRebuild);
|
|
newMediaNavigationService.TryGetChildrenKeys(nodeKey, out IEnumerable<Guid> childrenKeysFromRebuild);
|
|
newMediaNavigationService.TryGetDescendantsKeys(nodeKey, out IEnumerable<Guid> descendantsKeysFromRebuild);
|
|
newMediaNavigationService.TryGetAncestorsKeys(nodeKey, out IEnumerable<Guid> ancestorsKeysFromRebuild);
|
|
newMediaNavigationService.TryGetSiblingsKeys(nodeKey, out IEnumerable<Guid> siblingsKeysFromRebuild);
|
|
|
|
// Assert
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.IsFalse(initialNodeExists);
|
|
|
|
// Verify that the item is present in the navigation structure after a rebuild
|
|
Assert.IsTrue(nodeExists);
|
|
|
|
// Verify that we have the same items as in the original built state of MediaNavigationService
|
|
Assert.AreEqual(originalParentKey, parentKeyFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalChildrenKeys, childrenKeysFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task Bin_Structure_Can_Rebuild()
|
|
{
|
|
// Arrange
|
|
Guid nodeKey = Album.Key;
|
|
await MediaEditingService.MoveToRecycleBinAsync(nodeKey, Constants.Security.SuperUserKey);
|
|
|
|
// Capture original built state of MediaNavigationQueryService
|
|
MediaNavigationQueryService.TryGetParentKeyInBin(nodeKey, out Guid? originalParentKey);
|
|
MediaNavigationQueryService.TryGetChildrenKeysInBin(nodeKey, out IEnumerable<Guid> originalChildrenKeys);
|
|
MediaNavigationQueryService.TryGetDescendantsKeysInBin(nodeKey, out IEnumerable<Guid> originalDescendantsKeys);
|
|
MediaNavigationQueryService.TryGetAncestorsKeysInBin(nodeKey, out IEnumerable<Guid> originalAncestorsKeys);
|
|
MediaNavigationQueryService.TryGetSiblingsKeysInBin(nodeKey, out IEnumerable<Guid> originalSiblingsKeys);
|
|
|
|
// In-memory navigation structure is empty here
|
|
var newMediaNavigationService = new MediaNavigationService(
|
|
GetRequiredService<ICoreScopeProvider>(),
|
|
GetRequiredService<INavigationRepository>(),
|
|
GetRequiredService<IMediaTypeService>());
|
|
var initialNodeExists = newMediaNavigationService.TryGetParentKeyInBin(nodeKey, out _);
|
|
|
|
// Act
|
|
await newMediaNavigationService.RebuildBinAsync();
|
|
|
|
// Capture rebuilt state
|
|
var nodeExists = newMediaNavigationService.TryGetParentKeyInBin(nodeKey, out Guid? parentKeyFromRebuild);
|
|
newMediaNavigationService.TryGetChildrenKeysInBin(nodeKey, out IEnumerable<Guid> childrenKeysFromRebuild);
|
|
newMediaNavigationService.TryGetDescendantsKeysInBin(nodeKey, out IEnumerable<Guid> descendantsKeysFromRebuild);
|
|
newMediaNavigationService.TryGetAncestorsKeysInBin(nodeKey, out IEnumerable<Guid> ancestorsKeysFromRebuild);
|
|
newMediaNavigationService.TryGetSiblingsKeysInBin(nodeKey, out IEnumerable<Guid> siblingsKeysFromRebuild);
|
|
|
|
// Assert
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.IsFalse(initialNodeExists);
|
|
|
|
// Verify that the item is present in the navigation structure after a rebuild
|
|
Assert.IsTrue(nodeExists);
|
|
|
|
// Verify that we have the same items as in the original built state of MediaNavigationService
|
|
Assert.AreEqual(originalParentKey, parentKeyFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalChildrenKeys, childrenKeysFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalDescendantsKeys, descendantsKeysFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalAncestorsKeys, ancestorsKeysFromRebuild);
|
|
CollectionAssert.AreEquivalent(originalSiblingsKeys, siblingsKeysFromRebuild);
|
|
});
|
|
}
|
|
}
|