refactor(core): delegate GetPagedOfType/s to QueryOperationService
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 <noreply@anthropic.com>
This commit is contained in:
@@ -549,63 +549,11 @@ public class ContentService : RepositoryService, IContentService
|
||||
out long totalRecords,
|
||||
IQuery<IContent>? 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<IContent>()?.Where(x => x.ContentTypeId == contentTypeId),
|
||||
pageIndex,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.GetPagedOfType(contentTypeId, pageIndex, pageSize, out totalRecords, filter, ordering);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IContent> GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery<IContent>? 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<int> contentTypeIdsAsList = [.. contentTypeIds];
|
||||
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.GetPage(
|
||||
Query<IContent>()?.Where(x => contentTypeIdsAsList.Contains(x.ContentTypeId)),
|
||||
pageIndex,
|
||||
pageSize,
|
||||
out totalRecords,
|
||||
filter,
|
||||
ordering);
|
||||
}
|
||||
}
|
||||
=> QueryOperationService.GetPagedOfTypes(contentTypeIds, pageIndex, pageSize, out totalRecords, filter, ordering);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of <see cref="IContent" /> objects by Level
|
||||
|
||||
@@ -764,6 +764,44 @@ internal sealed class ContentServiceRefactoringTests : UmbracoIntegrationTestWit
|
||||
Assert.That(facadeItems.Select(x => x.Id), Is.EquivalentTo(directItems.Select(x => x.Id)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies GetPagedOfType() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetPagedOfType_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
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)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phase 2 Test: Verifies GetPagedOfTypes() via facade returns same result as direct service call.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetPagedOfTypes_ViaFacade_ReturnsEquivalentResultToDirectService()
|
||||
{
|
||||
// Arrange
|
||||
var queryService = GetRequiredService<IContentQueryOperationService>();
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user