diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/CreateWebhookController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/CreateWebhookController.cs
index c513c83d70..705292c82a 100644
--- a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/CreateWebhookController.cs
+++ b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/CreateWebhookController.cs
@@ -1,5 +1,4 @@
using Asp.Versioning;
-using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Factories;
@@ -8,12 +7,10 @@ using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
-using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
[ApiVersion("1.0")]
-[Authorize(Policy = AuthorizationPolicies.TreeAccessWebhooks)]
public class CreateWebhookController : WebhookControllerBase
{
private readonly IWebhookService _webhookService;
diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/DeleteWebhookController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/DeleteWebhookController.cs
index ecb8d7d9f7..a45302464a 100644
--- a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/DeleteWebhookController.cs
+++ b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/DeleteWebhookController.cs
@@ -1,5 +1,4 @@
using Asp.Versioning;
-using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core;
@@ -7,12 +6,10 @@ using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
-using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
[ApiVersion("1.0")]
-[Authorize(Policy = AuthorizationPolicies.TreeAccessWebhooks)]
public class DeleteWebhookController : WebhookControllerBase
{
private readonly IWebhookService _webhookService;
diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/UpdateWebhookController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/UpdateWebhookController.cs
index c5469d575f..8f22721b5e 100644
--- a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/UpdateWebhookController.cs
+++ b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/UpdateWebhookController.cs
@@ -1,5 +1,4 @@
using Asp.Versioning;
-using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Factories;
@@ -8,12 +7,10 @@ using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
-using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
[ApiVersion("1.0")]
-[Authorize(Policy = AuthorizationPolicies.TreeAccessWebhooks)]
public class UpdateWebhookController : WebhookControllerBase
{
private readonly IWebhookService _webhookService;
diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/WebhookControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/WebhookControllerBase.cs
index 98c3868c65..d32de4bf7a 100644
--- a/src/Umbraco.Cms.Api.Management/Controllers/Webhook/WebhookControllerBase.cs
+++ b/src/Umbraco.Cms.Api.Management/Controllers/Webhook/WebhookControllerBase.cs
@@ -1,13 +1,16 @@
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Common.Builders;
using Umbraco.Cms.Api.Management.Routing;
using Umbraco.Cms.Core.Services.OperationStatus;
+using Umbraco.Cms.Web.Common.Authorization;
namespace Umbraco.Cms.Api.Management.Controllers.Webhook;
[VersionedApiBackOfficeRoute("webhook")]
[ApiExplorerSettings(GroupName = "Webhook")]
+[Authorize(Policy = AuthorizationPolicies.TreeAccessWebhooks)]
public abstract class WebhookControllerBase : ManagementApiControllerBase
{
protected IActionResult WebhookOperationStatusResult(WebhookOperationStatus status) =>
diff --git a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs
index 8d2fe9a04f..38a3858904 100644
--- a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs
+++ b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs
@@ -1,4 +1,5 @@
using Umbraco.Cms.Core.PublishedCache;
+using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Infrastructure.HybridCache.Persistence;
namespace Umbraco.Cms.Infrastructure.HybridCache;
@@ -6,11 +7,18 @@ namespace Umbraco.Cms.Infrastructure.HybridCache;
internal class DatabaseCacheRebuilder : IDatabaseCacheRebuilder
{
private readonly IDatabaseCacheRepository _databaseCacheRepository;
+ private readonly ICoreScopeProvider _coreScopeProvider;
- public DatabaseCacheRebuilder(IDatabaseCacheRepository databaseCacheRepository)
+ public DatabaseCacheRebuilder(IDatabaseCacheRepository databaseCacheRepository, ICoreScopeProvider coreScopeProvider)
{
_databaseCacheRepository = databaseCacheRepository;
+ _coreScopeProvider = coreScopeProvider;
}
- public void Rebuild() => _databaseCacheRepository.Rebuild();
+ public void Rebuild()
+ {
+ using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
+ _databaseCacheRepository.Rebuild();
+ scope.Complete();
+ }
}
diff --git a/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs b/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs
index e263485cf4..7fa38dd626 100644
--- a/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs
+++ b/src/Umbraco.PublishedCache.HybridCache/Factories/CacheNodeFactory.cs
@@ -45,7 +45,7 @@ internal class CacheNodeFactory : ICacheNodeFactory
switch (content.PublishedState)
{
case PublishedState.Published:
- return preview;
+ return preview is false;
case PublishedState.Publishing:
return preview is false || content.Published; // The type changes after this operation
case PublishedState.Unpublished:
@@ -62,9 +62,10 @@ internal class CacheNodeFactory : ICacheNodeFactory
case PublishedState.Published:
return preview ? content.TemplateId : content.PublishTemplateId;
case PublishedState.Publishing:
- return content.TemplateId;// The type changes after this operation is we need to read the draft values
case PublishedState.Unpublished:
case PublishedState.Unpublishing:
+ return content.TemplateId;
+
default:
return null;
}
diff --git a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs
index 7b5d9e9b20..4efc2fbebe 100644
--- a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs
+++ b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs
@@ -87,7 +87,7 @@ internal sealed class DatabaseCacheRepository : RepositoryBase, IDatabaseCacheRe
public async Task RefreshMediaAsync(ContentCacheNode contentCacheNode)
{
IContentCacheDataSerializer serializer = _contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Media);
- await OnRepositoryRefreshed(serializer, contentCacheNode, false);
+ await OnRepositoryRefreshed(serializer, contentCacheNode, true);
}
///
@@ -117,20 +117,10 @@ internal sealed class DatabaseCacheRepository : RepositoryBase, IDatabaseCacheRe
}
}
- if (contentTypeIds != null)
- {
- RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds);
- }
+ RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds);
+ RebuildMediaDbCache(serializer, _nucacheSettings.Value.SqlPageSize, mediaTypeIds);
+ RebuildMemberDbCache(serializer, _nucacheSettings.Value.SqlPageSize, memberTypeIds);
- if (mediaTypeIds != null)
- {
- RebuildMediaDbCache(serializer, _nucacheSettings.Value.SqlPageSize, mediaTypeIds);
- }
-
- if (memberTypeIds != null)
- {
- RebuildMemberDbCache(serializer, _nucacheSettings.Value.SqlPageSize, memberTypeIds);
- }
}
// assumes content tree lock
diff --git a/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTemplateTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTemplateTests.cs
index 34045aa17b..eb352ff6c8 100644
--- a/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTemplateTests.cs
+++ b/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTemplateTests.cs
@@ -1,42 +1,42 @@
-// using NUnit.Framework;
-// using Umbraco.Cms.Core;
-// using Umbraco.Cms.Core.Models.ContentEditing;
-// using Umbraco.Cms.Core.PublishedCache;
-// using Umbraco.Cms.Core.Services;
-// using Umbraco.Cms.Core.Services.OperationStatus;
-// using Umbraco.Cms.Tests.Common.Testing;
-// using Umbraco.Cms.Tests.Integration.Testing;
-// FIXME: This is fixed in the release branch, uncomment this once that's merged in.
-// namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
-//
-// [TestFixture]
-// [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
-// public class DocumentHybridCacheTemplateTests : UmbracoIntegrationTestWithContentEditing
-// {
-// protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
-//
-// private IPublishedContentCache PublishedContentHybridCache => GetRequiredService();
-//
-// private IContentEditingService ContentEditingService => GetRequiredService();
-//
-// [Test]
-// public async Task Can_Get_Document_After_Removing_Template()
-// {
-// // Arrange
-// var textPageBefore = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
-// Assert.AreEqual(textPageBefore.TemplateId, TemplateId);
-// var updateModel = new ContentUpdateModel();
-// {
-// updateModel.TemplateKey = null;
-// updateModel.InvariantName = textPageBefore.Name;
-// }
-//
-// // Act
-// var updateContentResult = await ContentEditingService.UpdateAsync(textPageBefore.Key, updateModel, Constants.Security.SuperUserKey);
-//
-// // Assert
-// Assert.AreEqual(updateContentResult.Status, ContentEditingOperationStatus.Success);
-// var textPageAfter = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
-// Assert.AreEqual(textPageAfter.TemplateId, null);
-// }
-// }
+using NUnit.Framework;
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Models.ContentEditing;
+using Umbraco.Cms.Core.PublishedCache;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Services.OperationStatus;
+using Umbraco.Cms.Tests.Common.Testing;
+using Umbraco.Cms.Tests.Integration.Testing;
+namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
+
+[TestFixture]
+[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
+public class DocumentHybridCacheTemplateTests : UmbracoIntegrationTestWithContentEditing
+{
+ protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
+
+ private IPublishedContentCache PublishedContentHybridCache => GetRequiredService();
+
+ private IContentEditingService ContentEditingService => GetRequiredService();
+
+ [Test]
+ public async Task Can_Get_Document_After_Removing_Template()
+ {
+ // Arrange
+ var textPageBefore = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
+ Assert.AreEqual(textPageBefore.TemplateId, TemplateId);
+ var updateModel = new ContentUpdateModel();
+ {
+ updateModel.TemplateKey = null;
+ updateModel.InvariantName = textPageBefore.Name;
+ }
+
+ // Act
+ var updateContentResult = await ContentEditingService.UpdateAsync(textPageBefore.Key, updateModel, Constants.Security.SuperUserKey);
+
+ // Assert
+ Assert.AreEqual(updateContentResult.Status, ContentEditingOperationStatus.Success);
+ var textPageAfter = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
+ // Should this not be null?
+ Assert.AreEqual(textPageAfter.TemplateId, null);
+ }
+}
diff --git a/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTests.cs
index 69efb9a3e5..787fecaddf 100644
--- a/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTests.cs
+++ b/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTests.cs
@@ -1,494 +1,494 @@
-// using NUnit.Framework;
-// using Umbraco.Cms.Core;
-// using Umbraco.Cms.Core.Models.ContentEditing;
-// using Umbraco.Cms.Core.Models.PublishedContent;
-// using Umbraco.Cms.Core.PublishedCache;
-// using Umbraco.Cms.Core.Services;
-// using Umbraco.Cms.Tests.Common.Testing;
-// using Umbraco.Cms.Tests.Integration.Testing;
-// FIXME
-// namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
-//
-// [TestFixture]
-// [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
-// public class DocumentHybridCacheTests : UmbracoIntegrationTestWithContentEditing
-// {
-// protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
-//
-// private IPublishedContentCache PublishedContentHybridCache => GetRequiredService();
-//
-// private IContentEditingService ContentEditingService => GetRequiredService();
-//
-// private IContentPublishingService ContentPublishingService => GetRequiredService();
-//
-// private const string NewName = "New Name";
-// private const string NewTitle = "New Title";
-//
-// [Test]
-// public async Task Can_Get_Draft_Content_By_Id()
-// {
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
-//
-// // Assert
-// AssertTextPage(textPage);
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Content_By_Key()
-// {
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
-//
-// // Assert
-// AssertTextPage(textPage);
-// }
-//
-// [Test]
-// public async Task Can_Get_Published_Content_By_Id()
-// {
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId);
-//
-// // Assert
-// AssertPublishedTextPage(textPage);
-// }
-//
-// [Test]
-// public async Task Can_Get_Published_Content_By_Key()
-// {
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value);
-//
-// // Assert
-// AssertPublishedTextPage(textPage);
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Of_Published_Content_By_Id()
-// {
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, true);
-//
-// // Assert
-// AssertPublishedTextPage(textPage);
-// Assert.IsFalse(textPage.IsPublished());
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Of_Published_Content_By_Key()
-// {
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
-//
-// // Assert
-// AssertPublishedTextPage(textPage);
-// Assert.IsFalse(textPage.IsPublished());
-// }
-//
-// [Test]
-// public async Task Can_Get_Updated_Draft_Content_By_Id()
-// {
-// // Arrange
-// Textpage.InvariantName = NewName;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = NewName,
-// InvariantProperties = Textpage.InvariantProperties,
-// Variants = Textpage.Variants,
-// TemplateKey = Textpage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var updatedPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
-//
-// // Assert
-// Assert.AreEqual(NewName, updatedPage.Name);
-// }
-//
-// [Test]
-// public async Task Can_Get_Updated_Draft_Content_By_Key()
-// {
-// // Arrange
-// Textpage.InvariantName = NewName;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = NewName,
-// InvariantProperties = Textpage.InvariantProperties,
-// Variants = Textpage.Variants,
-// TemplateKey = Textpage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var updatedPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(NewName, updatedPage.Name);
-// }
-//
-// [Test]
-// [TestCase(true, true)]
-// [TestCase(false, false)]
-// // BETTER NAMING, CURRENTLY THIS IS TESTING BOTH THE PUBLISHED AND THE DRAFT OF THE PUBLISHED.
-// public async Task Can_Get_Updated_Draft_Published_Content_By_Id(bool preview, bool result)
-// {
-// // Arrange
-// PublishedTextPage.InvariantName = NewName;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = NewName,
-// InvariantProperties = PublishedTextPage.InvariantProperties,
-// Variants = PublishedTextPage.Variants,
-// TemplateKey = PublishedTextPage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, preview);
-//
-// // Assert
-// Assert.AreEqual(result, NewName.Equals(textPage.Name));
-// }
-//
-// [Test]
-// [TestCase(true, true)]
-// [TestCase(false, false)]
-// // BETTER NAMING, CURRENTLY THIS IS TESTING BOTH THE PUBLISHED AND THE DRAFT OF THE PUBLISHED.
-// public async Task Can_Get_Updated_Draft_Published_Content_By_Key(bool preview, bool result)
-// {
-// // Arrange
-// PublishedTextPage.InvariantName = NewName;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = NewName,
-// InvariantProperties = PublishedTextPage.InvariantProperties,
-// Variants = PublishedTextPage.Variants,
-// TemplateKey = PublishedTextPage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, preview);
-//
-// // Assert
-// Assert.AreEqual(result, NewName.Equals(textPage.Name));
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Content_Property_By_Id()
-// {
-// // Arrange
-// var titleValue = Textpage.InvariantProperties.First(x => x.Alias == "title").Value;
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
-//
-// // Assert
-// Assert.AreEqual(titleValue, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Content_Property_By_Key()
-// {
-// // Arrange
-// var titleValue = Textpage.InvariantProperties.First(x => x.Alias == "title").Value;
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(titleValue, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Published_Content_Property_By_Id()
-// {
-// // Arrange
-// var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, true);
-//
-// // Assert
-// Assert.AreEqual(titleValue, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Published_Content_Property_By_Key()
-// {
-// // Arrange
-// var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(titleValue, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Of_Published_Content_Property_By_Id()
-// {
-// // Arrange
-// var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, true);
-//
-// // Assert
-// Assert.AreEqual(titleValue, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Draft_Of_Published_Content_Property_By_Key()
-// {
-// // Arrange
-// var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(titleValue, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Updated_Draft_Content_Property_By_Id()
-// {
-// // Arrange
-// Textpage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = Textpage.InvariantName,
-// InvariantProperties = Textpage.InvariantProperties,
-// Variants = Textpage.Variants,
-// TemplateKey = Textpage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
-//
-// // Assert
-// Assert.AreEqual(NewTitle, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Updated_Draft_Content_Property_By_Key()
-// {
-// // Arrange
-// Textpage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = Textpage.InvariantName,
-// InvariantProperties = Textpage.InvariantProperties,
-// Variants = Textpage.Variants,
-// TemplateKey = Textpage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(NewTitle, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Updated_Published_Content_Property_By_Id()
-// {
-// // Arrange
-// PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = PublishedTextPage.InvariantName,
-// InvariantProperties = PublishedTextPage.InvariantProperties,
-// Variants = PublishedTextPage.Variants,
-// TemplateKey = PublishedTextPage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-// await ContentPublishingService.PublishAsync(PublishedTextPage.Key.Value, CultureAndSchedule, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(NewTitle, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Get_Updated_Published_Content_Property_By_Key()
-// {
-// // Arrange
-// PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = PublishedTextPage.InvariantName,
-// InvariantProperties = PublishedTextPage.InvariantProperties,
-// Variants = PublishedTextPage.Variants,
-// TemplateKey = PublishedTextPage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-// await ContentPublishingService.PublishAsync(PublishedTextPage.Key.Value, CultureAndSchedule, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value);
-//
-// // Assert
-// Assert.AreEqual(NewTitle, textPage.Value("title"));
-// }
-//
-// [Test]
-// [TestCase(true, "New Title")]
-// [TestCase(false, "Welcome to our Home page")]
-// public async Task Can_Get_Updated_Draft_Of_Published_Content_Property_By_Id(bool preview, string titleName)
-// {
-// // Arrange
-// PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = PublishedTextPage.InvariantName,
-// InvariantProperties = PublishedTextPage.InvariantProperties,
-// Variants = PublishedTextPage.Variants,
-// TemplateKey = PublishedTextPage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, preview);
-//
-// // Assert
-// Assert.AreEqual(titleName, textPage.Value("title"));
-// }
-//
-// [Test]
-// [TestCase(true, "New Name")]
-// [TestCase(false, "Welcome to our Home page")]
-// public async Task Can_Get_Updated_Draft_Of_Published_Content_Property_By_Key(bool preview, string titleName)
-// {
-// // Arrange
-// PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = titleName;
-// ContentUpdateModel updateModel = new ContentUpdateModel
-// {
-// InvariantName = PublishedTextPage.InvariantName,
-// InvariantProperties = PublishedTextPage.InvariantProperties,
-// Variants = PublishedTextPage.Variants,
-// TemplateKey = PublishedTextPage.TemplateKey,
-// };
-// await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
-//
-// // Assert
-// Assert.AreEqual(titleName, textPage.Value("title"));
-// }
-//
-// [Test]
-// public async Task Can_Not_Get_Deleted_Content_By_Id()
-// {
-// // Arrange
-// var content = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, true);
-// Assert.IsNotNull(content);
-// await ContentEditingService.DeleteAsync(Subpage1.Key.Value, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPagePublishedContent = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, false);
-//
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, true);
-//
-// // Assert
-// Assert.IsNull(textPage);
-// }
-//
-// [Test]
-// public async Task Can_Not_Get_Deleted_Content_By_Key()
-// {
-// // Arrange
-// await PublishedContentHybridCache.GetByIdAsync(Subpage1.Key.Value, true);
-// var hasContent = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, true);
-// Assert.IsNotNull(hasContent);
-// await ContentEditingService.DeleteAsync(Subpage1.Key.Value, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(Subpage1.Key.Value, true);
-//
-// // Assert
-// Assert.IsNull(textPage);
-// }
-//
-// [Test]
-// [TestCase(true)]
-// [TestCase(false)]
-// public async Task Can_Not_Get_Deleted_Published_Content_By_Id(bool preview)
-// {
-// // Arrange
-// await ContentEditingService.DeleteAsync(PublishedTextPage.Key.Value, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, preview);
-//
-// // Assert
-// Assert.IsNull(textPage);
-// }
-//
-// [Test]
-// [TestCase(true)]
-// [TestCase(false)]
-// public async Task Can_Not_Get_Deleted_Published_Content_By_Key(bool preview)
-// {
-// // Arrange
-// await ContentEditingService.DeleteAsync(PublishedTextPage.Key.Value, Constants.Security.SuperUserKey);
-//
-// // Act
-// var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, preview);
-//
-// // Assert
-// Assert.IsNull(textPage);
-// }
-//
-// private void AssertTextPage(IPublishedContent textPage)
-// {
-// Assert.Multiple(() =>
-// {
-// Assert.IsNotNull(textPage);
-// Assert.AreEqual(Textpage.Key, textPage.Key);
-// Assert.AreEqual(Textpage.ContentTypeKey, textPage.ContentType.Key);
-// Assert.AreEqual(Textpage.InvariantName, textPage.Name);
-// });
-//
-// AssertProperties(Textpage.InvariantProperties, textPage.Properties);
-// }
-//
-// private void AssertPublishedTextPage(IPublishedContent textPage)
-// {
-// Assert.Multiple(() =>
-// {
-// Assert.IsNotNull(textPage);
-// Assert.AreEqual(PublishedTextPage.Key, textPage.Key);
-// Assert.AreEqual(PublishedTextPage.ContentTypeKey, textPage.ContentType.Key);
-// Assert.AreEqual(PublishedTextPage.InvariantName, textPage.Name);
-// });
-//
-// AssertProperties(PublishedTextPage.InvariantProperties, textPage.Properties);
-// }
-//
-// private void AssertProperties(IEnumerable propertyCollection, IEnumerable publishedProperties)
-// {
-// foreach (var prop in propertyCollection)
-// {
-// AssertProperty(prop, publishedProperties.First(x => x.Alias == prop.Alias));
-// }
-// }
-//
-// private void AssertProperty(PropertyValueModel property, IPublishedProperty publishedProperty)
-// {
-// Assert.Multiple(() =>
-// {
-// Assert.AreEqual(property.Alias, publishedProperty.Alias);
-// Assert.AreEqual(property.Value, publishedProperty.GetSourceValue());
-// });
-// }
-// }
+using NUnit.Framework;
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Models.ContentEditing;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PublishedCache;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Tests.Common.Testing;
+using Umbraco.Cms.Tests.Integration.Testing;
+
+namespace Umbraco.Cms.Tests.Integration.Umbraco.PublishedCache.HybridCache;
+
+[TestFixture]
+[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
+public class DocumentHybridCacheTests : UmbracoIntegrationTestWithContentEditing
+{
+ protected override void CustomTestSetup(IUmbracoBuilder builder) => builder.AddUmbracoHybridCache();
+
+ private IPublishedContentCache PublishedContentHybridCache => GetRequiredService();
+
+ private IContentEditingService ContentEditingService => GetRequiredService();
+
+ private IContentPublishingService ContentPublishingService => GetRequiredService();
+
+ private const string NewName = "New Name";
+ private const string NewTitle = "New Title";
+
+ [Test]
+ public async Task Can_Get_Draft_Content_By_Id()
+ {
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
+
+ // Assert
+ AssertTextPage(textPage);
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Content_By_Key()
+ {
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
+
+ // Assert
+ AssertTextPage(textPage);
+ }
+
+ [Test]
+ public async Task Can_Get_Published_Content_By_Id()
+ {
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId);
+
+ // Assert
+ AssertPublishedTextPage(textPage);
+ }
+
+ [Test]
+ public async Task Can_Get_Published_Content_By_Key()
+ {
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value);
+
+ // Assert
+ AssertPublishedTextPage(textPage);
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Of_Published_Content_By_Id()
+ {
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, true);
+
+ // Assert
+ AssertPublishedTextPage(textPage);
+ Assert.IsFalse(textPage.IsPublished());
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Of_Published_Content_By_Key()
+ {
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
+
+ // Assert
+ AssertPublishedTextPage(textPage);
+ Assert.IsFalse(textPage.IsPublished());
+ }
+
+ [Test]
+ public async Task Can_Get_Updated_Draft_Content_By_Id()
+ {
+ // Arrange
+ Textpage.InvariantName = NewName;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = NewName,
+ InvariantProperties = Textpage.InvariantProperties,
+ Variants = Textpage.Variants,
+ TemplateKey = Textpage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var updatedPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
+
+ // Assert
+ Assert.AreEqual(NewName, updatedPage.Name);
+ }
+
+ [Test]
+ public async Task Can_Get_Updated_Draft_Content_By_Key()
+ {
+ // Arrange
+ Textpage.InvariantName = NewName;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = NewName,
+ InvariantProperties = Textpage.InvariantProperties,
+ Variants = Textpage.Variants,
+ TemplateKey = Textpage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var updatedPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(NewName, updatedPage.Name);
+ }
+
+ [Test]
+ [TestCase(true, true)]
+ [TestCase(false, false)]
+ // BETTER NAMING, CURRENTLY THIS IS TESTING BOTH THE PUBLISHED AND THE DRAFT OF THE PUBLISHED.
+ public async Task Can_Get_Updated_Draft_Published_Content_By_Id(bool preview, bool result)
+ {
+ // Arrange
+ PublishedTextPage.InvariantName = NewName;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = NewName,
+ InvariantProperties = PublishedTextPage.InvariantProperties,
+ Variants = PublishedTextPage.Variants,
+ TemplateKey = PublishedTextPage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, preview);
+
+ // Assert
+ Assert.AreEqual(result, NewName.Equals(textPage.Name));
+ }
+
+ [Test]
+ [TestCase(true, true)]
+ [TestCase(false, false)]
+ // BETTER NAMING, CURRENTLY THIS IS TESTING BOTH THE PUBLISHED AND THE DRAFT OF THE PUBLISHED.
+ public async Task Can_Get_Updated_Draft_Published_Content_By_Key(bool preview, bool result)
+ {
+ // Arrange
+ PublishedTextPage.InvariantName = NewName;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = NewName,
+ InvariantProperties = PublishedTextPage.InvariantProperties,
+ Variants = PublishedTextPage.Variants,
+ TemplateKey = PublishedTextPage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, preview);
+
+ // Assert
+ Assert.AreEqual(result, NewName.Equals(textPage.Name));
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Content_Property_By_Id()
+ {
+ // Arrange
+ var titleValue = Textpage.InvariantProperties.First(x => x.Alias == "title").Value;
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
+
+ // Assert
+ Assert.AreEqual(titleValue, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Content_Property_By_Key()
+ {
+ // Arrange
+ var titleValue = Textpage.InvariantProperties.First(x => x.Alias == "title").Value;
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(titleValue, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Published_Content_Property_By_Id()
+ {
+ // Arrange
+ var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, true);
+
+ // Assert
+ Assert.AreEqual(titleValue, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Published_Content_Property_By_Key()
+ {
+ // Arrange
+ var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(titleValue, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Of_Published_Content_Property_By_Id()
+ {
+ // Arrange
+ var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, true);
+
+ // Assert
+ Assert.AreEqual(titleValue, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Draft_Of_Published_Content_Property_By_Key()
+ {
+ // Arrange
+ var titleValue = PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value;
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(titleValue, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Updated_Draft_Content_Property_By_Id()
+ {
+ // Arrange
+ Textpage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = Textpage.InvariantName,
+ InvariantProperties = Textpage.InvariantProperties,
+ Variants = Textpage.Variants,
+ TemplateKey = Textpage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(TextpageId, true);
+
+ // Assert
+ Assert.AreEqual(NewTitle, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Updated_Draft_Content_Property_By_Key()
+ {
+ // Arrange
+ Textpage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = Textpage.InvariantName,
+ InvariantProperties = Textpage.InvariantProperties,
+ Variants = Textpage.Variants,
+ TemplateKey = Textpage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(Textpage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(Textpage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(NewTitle, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Updated_Published_Content_Property_By_Id()
+ {
+ // Arrange
+ PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = PublishedTextPage.InvariantName,
+ InvariantProperties = PublishedTextPage.InvariantProperties,
+ Variants = PublishedTextPage.Variants,
+ TemplateKey = PublishedTextPage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+ await ContentPublishingService.PublishAsync(PublishedTextPage.Key.Value, CultureAndSchedule, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(NewTitle, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Get_Updated_Published_Content_Property_By_Key()
+ {
+ // Arrange
+ PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = PublishedTextPage.InvariantName,
+ InvariantProperties = PublishedTextPage.InvariantProperties,
+ Variants = PublishedTextPage.Variants,
+ TemplateKey = PublishedTextPage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+ await ContentPublishingService.PublishAsync(PublishedTextPage.Key.Value, CultureAndSchedule, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value);
+
+ // Assert
+ Assert.AreEqual(NewTitle, textPage.Value("title"));
+ }
+
+ [Test]
+ [TestCase(true, "New Title")]
+ [TestCase(false, "Welcome to our Home page")]
+ public async Task Can_Get_Updated_Draft_Of_Published_Content_Property_By_Id(bool preview, string titleName)
+ {
+ // Arrange
+ PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = NewTitle;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = PublishedTextPage.InvariantName,
+ InvariantProperties = PublishedTextPage.InvariantProperties,
+ Variants = PublishedTextPage.Variants,
+ TemplateKey = PublishedTextPage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, preview);
+
+ // Assert
+ Assert.AreEqual(titleName, textPage.Value("title"));
+ }
+
+ [Test]
+ [TestCase(true, "New Name")]
+ [TestCase(false, "Welcome to our Home page")]
+ public async Task Can_Get_Updated_Draft_Of_Published_Content_Property_By_Key(bool preview, string titleName)
+ {
+ // Arrange
+ PublishedTextPage.InvariantProperties.First(x => x.Alias == "title").Value = titleName;
+ ContentUpdateModel updateModel = new ContentUpdateModel
+ {
+ InvariantName = PublishedTextPage.InvariantName,
+ InvariantProperties = PublishedTextPage.InvariantProperties,
+ Variants = PublishedTextPage.Variants,
+ TemplateKey = PublishedTextPage.TemplateKey,
+ };
+ await ContentEditingService.UpdateAsync(PublishedTextPage.Key.Value, updateModel, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, true);
+
+ // Assert
+ Assert.AreEqual(titleName, textPage.Value("title"));
+ }
+
+ [Test]
+ public async Task Can_Not_Get_Deleted_Content_By_Id()
+ {
+ // Arrange
+ var content = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, true);
+ Assert.IsNotNull(content);
+ await ContentEditingService.DeleteAsync(Subpage1.Key.Value, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPagePublishedContent = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, false);
+
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, true);
+
+ // Assert
+ Assert.IsNull(textPage);
+ }
+
+ [Test]
+ public async Task Can_Not_Get_Deleted_Content_By_Key()
+ {
+ // Arrange
+ await PublishedContentHybridCache.GetByIdAsync(Subpage1.Key.Value, true);
+ var hasContent = await PublishedContentHybridCache.GetByIdAsync(Subpage1Id, true);
+ Assert.IsNotNull(hasContent);
+ await ContentEditingService.DeleteAsync(Subpage1.Key.Value, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(Subpage1.Key.Value, true);
+
+ // Assert
+ Assert.IsNull(textPage);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public async Task Can_Not_Get_Deleted_Published_Content_By_Id(bool preview)
+ {
+ // Arrange
+ await ContentEditingService.DeleteAsync(PublishedTextPage.Key.Value, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPageId, preview);
+
+ // Assert
+ Assert.IsNull(textPage);
+ }
+
+ [Test]
+ [TestCase(true)]
+ [TestCase(false)]
+ public async Task Can_Not_Get_Deleted_Published_Content_By_Key(bool preview)
+ {
+ // Arrange
+ await ContentEditingService.DeleteAsync(PublishedTextPage.Key.Value, Constants.Security.SuperUserKey);
+
+ // Act
+ var textPage = await PublishedContentHybridCache.GetByIdAsync(PublishedTextPage.Key.Value, preview);
+
+ // Assert
+ Assert.IsNull(textPage);
+ }
+
+ private void AssertTextPage(IPublishedContent textPage)
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.IsNotNull(textPage);
+ Assert.AreEqual(Textpage.Key, textPage.Key);
+ Assert.AreEqual(Textpage.ContentTypeKey, textPage.ContentType.Key);
+ Assert.AreEqual(Textpage.InvariantName, textPage.Name);
+ });
+
+ AssertProperties(Textpage.InvariantProperties, textPage.Properties);
+ }
+
+ private void AssertPublishedTextPage(IPublishedContent textPage)
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.IsNotNull(textPage);
+ Assert.AreEqual(PublishedTextPage.Key, textPage.Key);
+ Assert.AreEqual(PublishedTextPage.ContentTypeKey, textPage.ContentType.Key);
+ Assert.AreEqual(PublishedTextPage.InvariantName, textPage.Name);
+ });
+
+ AssertProperties(PublishedTextPage.InvariantProperties, textPage.Properties);
+ }
+
+ private void AssertProperties(IEnumerable propertyCollection, IEnumerable publishedProperties)
+ {
+ foreach (var prop in propertyCollection)
+ {
+ AssertProperty(prop, publishedProperties.First(x => x.Alias == prop.Alias));
+ }
+ }
+
+ private void AssertProperty(PropertyValueModel property, IPublishedProperty publishedProperty)
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.AreEqual(property.Alias, publishedProperty.Alias);
+ Assert.AreEqual(property.Value, publishedProperty.GetSourceValue());
+ });
+ }
+}