From 1bc741b4703a3b7253aa4e1d55ab86b5e134a846 Mon Sep 17 00:00:00 2001 From: yv01p Date: Tue, 23 Dec 2025 00:03:12 +0000 Subject: [PATCH] refactor(core): delegate GetPagedOfType/s to QueryOperationService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ContentService now delegates all paged type queries to the new QueryOperationService, completing Phase 2 delegation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/Umbraco.Core/Services/ContentService.cs | 56 +------------------ .../ContentServiceRefactoringTests.cs | 38 +++++++++++++ 2 files changed, 40 insertions(+), 54 deletions(-) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index 1f40dee264..176fd693c7 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -549,63 +549,11 @@ public class ContentService : RepositoryService, IContentService out long totalRecords, IQuery? filter = null, Ordering? ordering = null) - { - if (pageIndex < 0) - { - throw new ArgumentOutOfRangeException(nameof(pageIndex)); - } - - if (pageSize <= 0) - { - throw new ArgumentOutOfRangeException(nameof(pageSize)); - } - - ordering ??= Ordering.By("sortOrder"); - - using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) - { - scope.ReadLock(Constants.Locks.ContentTree); - return _documentRepository.GetPage( - Query()?.Where(x => x.ContentTypeId == contentTypeId), - pageIndex, - pageSize, - out totalRecords, - filter, - ordering); - } - } + => QueryOperationService.GetPagedOfType(contentTypeId, pageIndex, pageSize, out totalRecords, filter, ordering); /// public IEnumerable GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery? filter, Ordering? ordering = null) - { - if (pageIndex < 0) - { - throw new ArgumentOutOfRangeException(nameof(pageIndex)); - } - - if (pageSize <= 0) - { - throw new ArgumentOutOfRangeException(nameof(pageSize)); - } - - ordering ??= Ordering.By("sortOrder"); - - using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) - { - // Need to use a List here because the expression tree cannot convert the array when used in Contains. - // See ExpressionTests.Sql_In(). - List contentTypeIdsAsList = [.. contentTypeIds]; - - scope.ReadLock(Constants.Locks.ContentTree); - return _documentRepository.GetPage( - Query()?.Where(x => contentTypeIdsAsList.Contains(x.ContentTypeId)), - pageIndex, - pageSize, - out totalRecords, - filter, - ordering); - } - } + => QueryOperationService.GetPagedOfTypes(contentTypeIds, pageIndex, pageSize, out totalRecords, filter, ordering); /// /// Gets a collection of objects by Level diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs index ba2c5a1392..5c6599eb16 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceRefactoringTests.cs @@ -764,6 +764,44 @@ internal sealed class ContentServiceRefactoringTests : UmbracoIntegrationTestWit Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id))); } + /// + /// Phase 2 Test: Verifies GetPagedOfType() via facade returns same result as direct service call. + /// + [Test] + public void GetPagedOfType_ViaFacade_ReturnsEquivalentResultToDirectService() + { + // Arrange + var queryService = GetRequiredService(); + var contentTypeId = ContentType.Id; + + // Act + var facadeItems = ContentService.GetPagedOfType(contentTypeId, 0, 10, out var facadeTotal).ToList(); + var directItems = queryService.GetPagedOfType(contentTypeId, 0, 10, out var directTotal).ToList(); + + // Assert + Assert.That(facadeTotal, Is.EqualTo(directTotal)); + Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id))); + } + + /// + /// Phase 2 Test: Verifies GetPagedOfTypes() via facade returns same result as direct service call. + /// + [Test] + public void GetPagedOfTypes_ViaFacade_ReturnsEquivalentResultToDirectService() + { + // Arrange + var queryService = GetRequiredService(); + var contentTypeIds = new[] { ContentType.Id }; + + // Act + var facadeItems = ContentService.GetPagedOfTypes(contentTypeIds, 0, 10, out var facadeTotal, null).ToList(); + var directItems = queryService.GetPagedOfTypes(contentTypeIds, 0, 10, out var directTotal).ToList(); + + // Assert + Assert.That(facadeTotal, Is.EqualTo(directTotal)); + Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id))); + } + #endregion ///