Files
Umbraco-CMS/thoughts/shared/handoffs/general/2025-12-20_01-01-02_contentservice-test-coverage-analysis.md
yv01p 9962df50ee feat(core): register IContentCrudService in DI container
Adds IContentCrudService registration to UmbracoBuilder alongside
IContentService. Both services are now resolvable from DI.

Includes integration test verifying successful resolution.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-21 03:31:23 +00:00

5.8 KiB

date, researcher, git_commit, branch, repository, topic, tags, status, last_updated, last_updated_by, type
date researcher git_commit branch repository topic tags status last_updated last_updated_by type
2025-12-20T01:01:02+00:00 Claude f4a01ed50d refactor/ContentService Umbraco-CMS ContentService Refactoring Test Coverage Analysis
testing
refactoring
contentservice
test-strategy
complete 2025-12-20 Claude implementation_strategy

Handoff: ContentService Test Coverage Analysis for Refactoring

Task(s)

  • Completed: Analyzed the ContentService refactoring design document
  • Completed: Reviewed all existing ContentService test files
  • Completed: Mapped existing test coverage to proposed service extraction
  • Completed: Identified test coverage gaps
  • Completed: Recommended test strategy for the refactoring
  • Planned: Write specific tests for identified gaps (not started)

Critical References

  1. docs/plans/2025-12-19-contentservice-refactor-design.md - The master refactoring design document
  2. tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs - Main test file (3707 lines, 91 tests)

Recent changes

No code changes made - this was a research/analysis session.

Learnings

Existing Test Coverage Summary

The ContentService has substantial existing test coverage across 6 test files:

Test File Tests Focus Area
ContentServiceTests.cs 91 Core CRUD, publishing, scheduling, hierarchy
ContentServiceNotificationTests.cs 8 Saving/publishing notification handlers, culture variants
ContentServicePublishBranchTests.cs 10 Branch publishing with various filters, variant/invariant content
ContentServiceVariantTests.cs 3 Culture code casing consistency
ContentServiceTagsTests.cs 16 Tag handling, invariant/variant transitions
ContentServicePerformanceTest.cs 8 Bulk operations, caching performance

Proposed Service Extraction (from design doc)

The design splits ContentService into 5 public services + 2 internal managers:

  1. IContentCrudService - Create, Get, Save, Delete
  2. IContentPublishOperationService - Publish, Unpublish, Scheduling, Branch
  3. IContentMoveService - Move, RecycleBin, Copy, Sort
  4. IContentQueryService - Count, Paged queries, Hierarchy
  5. IContentVersionService - Versions, Rollback, DeleteVersions
  6. ContentPermissionManager (internal)
  7. ContentBlueprintManager (internal)

Test Strategy Recommendation

Option A with targeted additions (recommended approach):

  • Keep existing tests as primary safety net (they test via IContentService which becomes the facade)
  • Add targeted tests for areas with new risk introduced by the refactoring

Identified Test Coverage Gaps

Gap Area Current State Why It Matters
Notification ordering in orchestrated ops No explicit test MoveToRecycleBin must unpublish→move in correct sequence
Sort operation No test exists IContentMoveService.Sort() has no coverage
DeleteOfType/DeleteOfTypes 1 test only Complex orchestration: moves descendants to bin first
Permission operations No tests SetPermissions/SetPermission have zero coverage
Transaction boundaries Implicit only When services call each other, ambient scope must work
Lock coordination No explicit test Services acquiring locks within ambient scopes
CommitDocumentChanges internal Limited Culture unpublishing within this method not well tested
Independent service usage N/A (new) Consumers may inject services directly (e.g., IContentCrudService)

Key Test File Locations

  • Integration tests: tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs
  • More integration tests: tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentService*Tests.cs
  • Unit tests referencing ContentService: tests/Umbraco.Tests.UnitTests/ (13 files, but mostly mock ContentService)

Artifacts

  • docs/plans/2025-12-19-contentservice-refactor-design.md - Design document (reviewed)
  • This handoff document

Action Items & Next Steps

  1. Write notification ordering tests - Verify MoveToRecycleBin fires ContentUnpublishingNotification before ContentMovingToRecycleBinNotification
  2. Add Sort operation tests - Test Sort(IEnumerable<IContent>) and Sort(IEnumerable<int>) methods
  3. Expand DeleteOfType tests - Verify descendant handling and notification ordering
  4. Add permission tests - Test SetPermissions and SetPermission methods
  5. Add transaction boundary tests - Verify ambient scope behavior when services chain calls
  6. Consider independent service tests - Once services are extracted, add tests that use them directly (not via facade)
  7. Proceed with Phase 1 of refactoring - Extract IContentCrudService first (establishes patterns)

Other Notes

Test Infrastructure Observations

  • Tests use UmbracoIntegrationTest base class with NewSchemaPerTest for isolation
  • ContentRepositoryBase.ThrowOnWarning = true is set in many tests for strict validation
  • Custom notification handlers are registered via CustomTestSetup(IUmbracoBuilder builder)
  • Tests use builder pattern extensively: ContentTypeBuilder, ContentBuilder, TemplateBuilder

Key Methods That Need Careful Testing During Refactor

Per the design doc's Notification Responsibility Matrix (docs/plans/2025-12-19-contentservice-refactor-design.md:507-538):

  • MoveToRecycleBin - Orchestrated in Facade (unpublish + move)
  • DeleteOfType/DeleteOfTypes - Orchestrated in Facade
  • All operations with cancellable notifications need pre/post verification

Design Doc Key Sections

  • Service dependency diagram: lines 39-68
  • Method mapping tables: lines 386-496
  • Notification responsibility matrix: lines 507-538
  • Transaction/scope ownership: lines 105-156