Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentNavigationServiceTestsBase.cs
Elitsa Marinovska c26016b0b0 V15: Implement content type filtering for in-memory navigation structure (#17456)
* 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>
2024-11-11 12:00:20 +01:00

62 lines
2.2 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.ContentEditing;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.Navigation;
using Umbraco.Cms.Core.Sync;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Scoping;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Services;
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
public abstract class DocumentNavigationServiceTestsBase : UmbracoIntegrationTest
{
protected IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
// Testing with IContentEditingService as it calls IContentService underneath
protected IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
protected IDocumentNavigationQueryService DocumentNavigationQueryService => GetRequiredService<IDocumentNavigationQueryService>();
protected IContentType ContentType { get; set; }
protected IContent Root { get; set; }
protected IContent Child1 { get; set; }
protected IContent Grandchild1 { get; set; }
protected IContent Grandchild2 { get; set; }
protected IContent Child2 { get; set; }
protected IContent Grandchild3 { get; set; }
protected IContent GreatGrandchild1 { get; set; }
protected IContent Child3 { get; set; }
protected IContent Grandchild4 { get; set; }
protected ContentCreateModel CreateContentCreateModel(string name, Guid key, Guid? contentTypeKey = null, Guid? parentKey = null)
=> new()
{
ContentTypeKey = contentTypeKey ?? ContentType.Key,
ParentKey = parentKey ?? Constants.System.RootKey,
InvariantName = name,
Key = key,
};
protected override void CustomTestSetup(IUmbracoBuilder builder)
{
builder.Services.AddUnique<IServerMessenger, ScopedRepositoryTests.LocalServerMessenger>();
builder.AddNotificationHandler<ContentTreeChangeNotification, ContentTreeChangeDistributedCacheNotificationHandler>();
}
}