Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/DocumentHybridCacheTests.cs
Mole 1258962429 V15: Remove Nucache (#17166)
* Remove nucache reference from Web.Common

* Get tests building-ish

* Move ReservedFieldNamesService to the right project

* Remove IPublishedSnapshotStatus

* Added functionality to the INavigationQueryService to get root keys

* Fixed issue with navigation

* Remove IPublishedSnapshot from UmbracoContext

* Begin removing usage of IPublishedSnapshot from PublishedContentExtensions

* Fix PublishedContentExtensions.cs

* Don't use snapshots in delivery media api

* Use IPublishedMediaCache in QueryMediaApiController

* Remove more usages of IPublishedSnapshotAccessor

* Comment out tests

* Remove more usages of PublishedSnapshotAccessor

* Remove PublishedSnapshot from property

* Fixed test build

* Fix errors

* Fix some tests

* Delete NuCache 🎉

* Implement DatabaseCacheRebuilder

* Remove usage of IPublishedSnapshotService

* Remove IPublishedSnapshotService

* Remove TestPublishedSnapshotAccessor and make tests build

* Don't test Snapshot cachelevel

It's no longer supported

* Fix BlockEditorConverter

Element != Element document type

* Remember to set cachemanager

* Fix RichTextParserTests

* Implement TryGetLevel on INavigationQueryService

* Fake level and obsolete it in PublishedContent

* Remove ChildrenForAllCultures

* Hack Path property on PublishedContent

* Remove usages of IPublishedSnapshot in tests

* More ConvertersTests

* Add hybrid cache to integration tests

We can actually do this now because we no longer save files on disk

* Rename IPublishedSnapshotRebuilder to ICacheRebuilder

* Comment out tests

* V15: Replacing the usages of Parent (navigation data) from IPublishedContent (#17125)

* Fix .Parent references in PublishedContentExtensions

* Add missing methods to FriendlyPublishedContentExtensions (ones that you were able to call on the content directly as they now require extra params)

* Fix references from the extension methods

* Fix dependencies in tests

* Replace IPublishedSnapshotAccessor with the content cache in tests

* Resolving more .Parent references

* Fix unit tests

* Obsolete and use extension methods

* Remove private method and use extension instead

* Moving code around

* Fix tests

* Fix more references

* Cleanup

* Fix more usages

* Resolve merge conflict

* Fix tests

* Cleanup

* Fix more tests

* Fixed unit tests

* Cleanup

* Replace last usages

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>

* Remove usage of IPublishedSnapshotAccessor from IRequestItemProvider

* Post merge fixup

* Remo IPublishedSnapshot

* Add HasAny to IDocumentUrlService

* Fix TextBuilder

* Fix modelsbuilder tests

* Use explicit types

* Implement GetByContentType

* Support element types in PublishedContentTypeCache

* Run enlistments before publishing notifications

* Fix elements cache refreshing

* Implement GetByUdi

* Implement GetAtRoot

* Implement GetByRoute

* Reimplement GetRouteById

* Fix blocks unit tests

* Initialize domain cache on boot

* Only return routes with domains on non default lanauges

* V15: Replacing the usages of `Children` (navigation data) from `IPublishedContent` (#17159)

* Update params in PublishedContentExtensions to the general interfaces for the published cache and navigation service, so that we can use the extension methods on both documents and media

* Introduce GetParent() which uses the right services

* Fix obsolete message on .Parent

* Obsolete .Children

* Fix usages of Children for ApiMediaQueryService

* Fix usage in internal

* Fix usages in views

* Fix indentation

* Fix issue with delete language

* Update nuget pacakges

* Clear elements cache when content is deleted

instead of trying to update it

* Reset publishedModelFactory

* Fixed publishing

---------

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
Co-authored-by: kjac <kja@umbraco.dk>
2024-10-01 15:03:02 +02:00

495 lines
19 KiB
C#

// 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<IPublishedContentCache>();
//
// private IContentEditingService ContentEditingService => GetRequiredService<IContentEditingService>();
//
// private IContentPublishingService ContentPublishingService => GetRequiredService<IContentPublishingService>();
//
// 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<PropertyValueModel> propertyCollection, IEnumerable<IPublishedProperty> 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());
// });
// }
// }