2025-03-21 18:02:31 +01:00
|
|
|
using NUnit.Framework;
|
2024-09-10 00:49:18 +09:00
|
|
|
using Umbraco.Cms.Core;
|
2025-02-17 12:51:33 +01:00
|
|
|
using Umbraco.Cms.Core.Cache;
|
|
|
|
|
using Umbraco.Cms.Core.Models.ContentPublishing;
|
|
|
|
|
using Umbraco.Cms.Core.Notifications;
|
2024-09-10 00:49:18 +09:00
|
|
|
using Umbraco.Cms.Core.PublishedCache;
|
|
|
|
|
using Umbraco.Cms.Core.Scoping;
|
|
|
|
|
using Umbraco.Cms.Core.Services;
|
2025-02-17 12:51:33 +01:00
|
|
|
using Umbraco.Cms.Core.Sync;
|
2024-09-10 00:49:18 +09:00
|
|
|
using Umbraco.Cms.Tests.Common.Testing;
|
|
|
|
|
using Umbraco.Cms.Tests.Integration.Testing;
|
2025-02-17 12:51:33 +01:00
|
|
|
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
2025-03-21 18:02:31 +01:00
|
|
|
internal sealed class DocumentHybridCacheScopeTests : UmbracoIntegrationTestWithContentEditing
|
2024-09-10 00:49:18 +09:00
|
|
|
{
|
2025-02-17 12:51:33 +01:00
|
|
|
protected override void CustomTestSetup(IUmbracoBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.AddNotificationHandler<ContentTreeChangeNotification, ContentTreeChangeDistributedCacheNotificationHandler>();
|
|
|
|
|
builder.Services.AddUnique<IServerMessenger, ContentEventsTests.LocalServerMessenger>();
|
|
|
|
|
}
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
private IPublishedContentCache PublishedContentHybridCache => GetRequiredService<IPublishedContentCache>();
|
|
|
|
|
|
|
|
|
|
private IContentPublishingService ContentPublishingService => GetRequiredService<IContentPublishingService>();
|
|
|
|
|
|
2024-10-02 13:36:26 +02:00
|
|
|
private ICoreScopeProvider CoreScopeProvider => GetRequiredService<ICoreScopeProvider>();
|
2024-09-10 00:49:18 +09:00
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Can_Get_Correct_Content_After_Rollback_With_Id()
|
|
|
|
|
{
|
2024-10-02 13:36:26 +02:00
|
|
|
using (CoreScopeProvider.CreateCoreScope())
|
2024-09-10 00:49:18 +09:00
|
|
|
{
|
2025-08-28 12:09:59 +02:00
|
|
|
await ContentPublishingService.PublishAsync(
|
|
|
|
|
Textpage.Key.Value,
|
|
|
|
|
[new CulturePublishScheduleModel { Culture = "*" }],
|
|
|
|
|
Constants.Security.SuperUserKey);
|
2024-09-10 00:49:18 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId);
|
|
|
|
|
|
|
|
|
|
// Published page should not be in cache, as we rolled scope back.
|
|
|
|
|
Assert.IsNull(textPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Can_Get_Correct_Content_After_Rollback_With_Key()
|
|
|
|
|
{
|
2024-10-02 13:36:26 +02:00
|
|
|
using (CoreScopeProvider.CreateCoreScope())
|
2024-09-10 00:49:18 +09:00
|
|
|
{
|
2025-08-28 12:09:59 +02:00
|
|
|
await ContentPublishingService.PublishAsync(Textpage.Key.Value,
|
|
|
|
|
[new CulturePublishScheduleModel { Culture = "*" }],
|
|
|
|
|
Constants.Security.SuperUserKey);
|
2024-09-10 00:49:18 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value);
|
|
|
|
|
|
|
|
|
|
// Published page should not be in cache, as we rolled scope back.
|
|
|
|
|
Assert.IsNull(textPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Can_Get_Document_After_Scope_Complete_With_Id()
|
|
|
|
|
{
|
2024-10-02 13:36:26 +02:00
|
|
|
using (var scope = CoreScopeProvider.CreateCoreScope())
|
2024-09-10 00:49:18 +09:00
|
|
|
{
|
2025-08-28 12:09:59 +02:00
|
|
|
await ContentPublishingService.PublishAsync(
|
|
|
|
|
Textpage.Key.Value,
|
|
|
|
|
[new CulturePublishScheduleModel { Culture = "*" }],
|
|
|
|
|
Constants.Security.SuperUserKey);
|
2024-09-10 00:49:18 +09:00
|
|
|
scope.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var publishedPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId);
|
|
|
|
|
|
|
|
|
|
// Published page should not be in cache, as we rolled scope back.
|
|
|
|
|
Assert.IsNotNull(publishedPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Can_Get_Document_After_Scope_Completes_With_Key()
|
|
|
|
|
{
|
2024-10-02 13:36:26 +02:00
|
|
|
using (var scope = CoreScopeProvider.CreateCoreScope())
|
2024-09-10 00:49:18 +09:00
|
|
|
{
|
2025-08-28 12:09:59 +02:00
|
|
|
await ContentPublishingService.PublishAsync(
|
|
|
|
|
Textpage.Key.Value,
|
|
|
|
|
[new CulturePublishScheduleModel { Culture = "*" }],
|
|
|
|
|
Constants.Security.SuperUserKey);
|
2024-09-10 00:49:18 +09:00
|
|
|
scope.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
var publishedPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value);
|
|
|
|
|
|
|
|
|
|
// Published page should not be in cache, as we rolled scope back.
|
|
|
|
|
Assert.IsNotNull(publishedPage);
|
|
|
|
|
}
|
2025-02-17 12:51:33 +01:00
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Can_Save_And_Publish_In_Same_Scope()
|
|
|
|
|
{
|
|
|
|
|
var key = Guid.NewGuid();
|
|
|
|
|
using (var scope = CoreScopeProvider.CreateCoreScope())
|
|
|
|
|
{
|
|
|
|
|
Textpage.Key = key;
|
|
|
|
|
var result = await ContentEditingService.CreateAsync(Textpage, Constants.Security.SuperUserKey);
|
|
|
|
|
Assert.IsTrue(result);
|
|
|
|
|
var publishResult = await ContentPublishingService.PublishAsync(Textpage.Key.Value, new List<CulturePublishScheduleModel>
|
|
|
|
|
{
|
|
|
|
|
new() { Culture = "*" },
|
|
|
|
|
}, Constants.Security.SuperUserKey);
|
|
|
|
|
Assert.IsTrue(publishResult.Success);
|
|
|
|
|
|
|
|
|
|
scope.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var published = await PublishedContentHybridCache.GetByIdAsync(key);
|
|
|
|
|
Assert.IsNotNull(published);
|
|
|
|
|
}
|
2024-09-10 00:49:18 +09:00
|
|
|
}
|