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:
@@ -302,40 +302,16 @@ public class ContentService : RepositoryService, IContentService
|
||||
#region Count
|
||||
|
||||
public int CountPublished(string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.CountPublished(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.CountPublished(contentTypeAlias);
|
||||
|
||||
public int Count(string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.Count(contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.Count(contentTypeAlias);
|
||||
|
||||
public int CountChildren(int parentId, string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.CountChildren(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.CountChildren(parentId, contentTypeAlias);
|
||||
|
||||
public int CountDescendants(int parentId, string? contentTypeAlias = null)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.CountDescendants(parentId, contentTypeAlias);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.CountDescendants(parentId, contentTypeAlias);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -673,6 +673,81 @@ internal sealed class ContentServiceRefactoringTests : UmbracoIntegrationTestWit
|
||||
|
||||
#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>
|
||||
/// Notification handler that tracks the order of notifications for test verification.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user