Files
Umbraco-CMS/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/NuCacheRebuildTests.cs
Nikolaj Geisle 7aeb400fce V10: fix build warnings in test projects (#12509)
* Run code cleanup

* Dotnet format benchmarks project

* Fix up Test.Common

* Run dotnet format + manual cleanup

* Run code cleanup for unit tests

* Run dotnet format

* Fix up errors

* Manual cleanup of Unit test project

* Update tests/Umbraco.Tests.Benchmarks/HexStringBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/TestDbMeta.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Benchmarks/TypeFinderBenchmarks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Update tests/Umbraco.Tests.Integration/Umbraco.Core/Events/EventAggregatorTests.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* Fix according to review

* Fix after merge

* Fix errors

Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk>
Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>
Co-authored-by: Zeegaan <nge@umbraco.dk>
2022-06-21 08:09:38 +02:00

87 lines
3.2 KiB
C#

using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.PublishedCache;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Cms.Tests.Common.Builders;
using Umbraco.Cms.Tests.Common.Testing;
using Umbraco.Cms.Tests.Integration.Testing;
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true,
WithApplication = true)]
public class NuCacheRebuildTests : UmbracoIntegrationTest
{
private IFileService FileService => GetRequiredService<IFileService>();
private IContentService ContentService => GetRequiredService<IContentService>();
private IContentTypeService ContentTypeService => GetRequiredService<IContentTypeService>();
private IPublishedSnapshotService PublishedSnapshotService => GetRequiredService<IPublishedSnapshotService>();
[Test]
public void UnpublishedNameChanges()
{
var urlSegmentProvider = new DefaultUrlSegmentProvider(ShortStringHelper);
var template = TemplateBuilder.CreateTextPageTemplate();
FileService.SaveTemplate(template);
var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id);
ContentTypeService.Save(contentType);
var content = ContentBuilder.CreateTextpageContent(contentType, "hello", Constants.System.Root);
ContentService.SaveAndPublish(content);
var cachedContent = ContentService.GetById(content.Id);
var segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// Does a new node work?
Assert.AreEqual("hello", segment);
content.Name = "goodbye";
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// We didn't save anything, so all should still be the same
Assert.AreEqual("hello", segment);
ContentService.Save(content);
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// At this point we have saved the new name, but not published. The url should still be the previous name
Assert.AreEqual("hello", segment);
PublishedSnapshotService.Rebuild();
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// After a rebuild, the unpublished name should still not be the url.
// This was previously incorrect, per #11074
Assert.AreEqual("hello", segment);
ContentService.SaveAndPublish(content);
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// The page has now been published, so we should see the new url segment
Assert.AreEqual("goodbye", segment);
PublishedSnapshotService.Rebuild();
cachedContent = ContentService.GetById(content.Id);
segment = urlSegmentProvider.GetUrlSegment(cachedContent);
// Just double checking that things remain after a rebuild
Assert.AreEqual("goodbye", segment);
}
}