refactor(core): delegate Count methods to QueryOperationService

ContentService now delegates Count, CountPublished, CountChildren,
CountDescendants to the new QueryOperationService.

This is Task 5 of Phase 2 - the first delegation task that converts
ContentService from direct repository calls to delegating to the
specialized query operation service.

All tests pass. Baseline tests confirm facade and direct service
return identical results. Full ContentService test suite passes
(excluding pre-existing benchmark regressions).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-22 23:46:59 +00:00
parent ff4bdb2509
commit fb20c480e3
2 changed files with 79 additions and 28 deletions

View File

@@ -302,40 +302,16 @@ public class ContentService : RepositoryService, IContentService
#region Count #region Count
public int CountPublished(string? contentTypeAlias = null) public int CountPublished(string? contentTypeAlias = null)
{ => QueryOperationService.CountPublished(contentTypeAlias);
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
{
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.CountPublished(contentTypeAlias);
}
}
public int Count(string? contentTypeAlias = null) public int Count(string? contentTypeAlias = null)
{ => QueryOperationService.Count(contentTypeAlias);
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
{
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.Count(contentTypeAlias);
}
}
public int CountChildren(int parentId, string? contentTypeAlias = null) public int CountChildren(int parentId, string? contentTypeAlias = null)
{ => QueryOperationService.CountChildren(parentId, contentTypeAlias);
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
{
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.CountChildren(parentId, contentTypeAlias);
}
}
public int CountDescendants(int parentId, string? contentTypeAlias = null) public int CountDescendants(int parentId, string? contentTypeAlias = null)
{ => QueryOperationService.CountDescendants(parentId, contentTypeAlias);
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
{
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.CountDescendants(parentId, contentTypeAlias);
}
}
#endregion #endregion

View File

@@ -673,6 +673,81 @@ internal sealed class ContentServiceRefactoringTests : UmbracoIntegrationTestWit
#endregion #endregion
#region Phase 2 - Count Method Delegation Tests
/// <summary>
/// Phase 2 Test: Verifies Count() via facade returns same result as direct service call.
/// </summary>
[Test]
public void Count_ViaFacade_ReturnsEquivalentResultToDirectService()
{
// Arrange
var queryService = GetRequiredService<IContentQueryOperationService>();
// Act
var facadeCount = ContentService.Count();
var directCount = queryService.Count();
// Assert
Assert.That(facadeCount, Is.EqualTo(directCount));
}
/// <summary>
/// Phase 2 Test: Verifies CountPublished() via facade returns same result as direct service call.
/// </summary>
[Test]
public void CountPublished_ViaFacade_ReturnsEquivalentResultToDirectService()
{
// Arrange
var queryService = GetRequiredService<IContentQueryOperationService>();
ContentService.Publish(Textpage, new[] { "*" });
// Act
var facadeCount = ContentService.CountPublished();
var directCount = queryService.CountPublished();
// Assert
Assert.That(facadeCount, Is.EqualTo(directCount));
}
/// <summary>
/// Phase 2 Test: Verifies CountChildren() via facade returns same result as direct service call.
/// </summary>
[Test]
public void CountChildren_ViaFacade_ReturnsEquivalentResultToDirectService()
{
// Arrange
var queryService = GetRequiredService<IContentQueryOperationService>();
var parentId = Textpage.Id;
// Act
var facadeCount = ContentService.CountChildren(parentId);
var directCount = queryService.CountChildren(parentId);
// Assert
Assert.That(facadeCount, Is.EqualTo(directCount));
}
/// <summary>
/// Phase 2 Test: Verifies CountDescendants() via facade returns same result as direct service call.
/// </summary>
[Test]
public void CountDescendants_ViaFacade_ReturnsEquivalentResultToDirectService()
{
// Arrange
var queryService = GetRequiredService<IContentQueryOperationService>();
var parentId = Textpage.Id;
// Act
var facadeCount = ContentService.CountDescendants(parentId);
var directCount = queryService.CountDescendants(parentId);
// Assert
Assert.That(facadeCount, Is.EqualTo(directCount));
}
#endregion
/// <summary> /// <summary>
/// Notification handler that tracks the order of notifications for test verification. /// Notification handler that tracks the order of notifications for test verification.
/// </summary> /// </summary>