* Ensure user group cache is cleared on language delete. * Apply code review feedback.
2.5 KiB
Umbraco.Tests.Integration
Integration tests that boot a real Umbraco container (UmbracoBuilder) against a real database
(SQLite in-memory by default, LocalDb/SQL Server optionally — see the root CLAUDE.md →
"Integration Test Database Configuration"). Most fixtures derive from UmbracoIntegrationTest.
Testing caching and cache refreshers
UmbracoIntegrationTest is wired for isolation and speed, not cache fidelity. Three harness
defaults will silently make a cache-related test pass regardless of the code under test (a false
green — it passes with and without the fix). When the behaviour under test involves repository
caching, cache invalidation, or a *DistributedCacheNotificationHandler, override them in
CustomTestSetup(IUmbracoBuilder builder):
-
AppCaches.NoCacheis registered, so repositories never actually cache and a stale-cache scenario cannot be reproduced. Register a real cache (pattern:Umbraco.Core/Cache/RuntimeCacheTests):builder.Services.AddUnique(_ => new AppCaches( new DeepCloneAppCache(new ObjectCacheAppCache()), NoAppCache.Instance, new IsolatedCaches(_ => new DeepCloneAppCache(new ObjectCacheAppCache())))); -
A no-op server messenger is registered (
NoopServerMessenger, inDependencyInjection/UmbracoBuilderExtensions.cs), soDistributedCache.Refresh*/RefreshAllnever actually runs the cache refreshers. Register a synchronous local messenger so refreshers execute in-process:builder.Services.AddUnique<IServerMessenger, ContentEventsTests.LocalServerMessenger>();LocalServerMessenger(inUmbraco.Infrastructure/Services/ContentEventsTests.cs) usesdistributedEnabled: false, soServerMessengerBasedelivers locally and invokes the refresher synchronously. -
The
*DistributedCacheNotificationHandlerset is NOT auto-registered by the harness — these are wired inUmbracoBuilder.CoreServicesfor the real app only. To test that a notification invalidates a cache, register the handler under test explicitly (pattern:Umbraco.Core/Services/ContentTypeEditingServiceTests):builder.AddNotificationHandler<LanguageDeletedNotification, LanguageDeletedDistributedCacheNotificationHandler>();
Always confirm the test fails before the fix and passes after (root CLAUDE.md → "Tests for a bug
fix must fail before the fix"). With the defaults above left in place, a cache test cannot fail, so
it proves nothing.