From c1d3bfaa5daf1e0ef302c635d78e819fa44788a5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 16 Sep 2019 17:21:12 +0200 Subject: [PATCH] Add breaking NuCache test --- .../PublishedContent/NuCacheChildrenTests.cs | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 47572a63ee..fbcdf7731a 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Reflection; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -25,6 +27,7 @@ using Umbraco.Web.Cache; using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.NuCache; using Umbraco.Web.PublishedCache.NuCache.DataSource; +using Umbraco.Web.PublishedCache.NuCache.Snap; namespace Umbraco.Tests.PublishedContent { @@ -163,7 +166,7 @@ namespace Umbraco.Tests.PublishedContent //1x variant (root) yield return CreateVariantKit(1, -1, 1, paths); - + //1x invariant under root yield return CreateInvariantKit(4, 1, 1, paths); @@ -952,6 +955,43 @@ namespace Umbraco.Tests.PublishedContent AssertDocuments(documents, "N1-en-US", "N2-en-US", "N3-en-US"); } + [Test] + public void Issue6353() + { + IEnumerable GetKits() + { + var paths = new Dictionary { { -1, "-1" } }; + + yield return CreateInvariantKit(1, -1, 1, paths); + yield return CreateInvariantKit(2, 1, 1, paths); + } + + Init(GetKits()); + + var snapshotService = (PublishedSnapshotService) _snapshotService; + var contentStoreField = typeof(PublishedSnapshotService).GetField("_contentStore", BindingFlags.Instance | BindingFlags.NonPublic); + var contentStore = (ContentStore) contentStoreField.GetValue(snapshotService); + var contentNodesField = typeof(ContentStore).GetField("_contentNodes", BindingFlags.Instance | BindingFlags.NonPublic); + var contentNodes = (ConcurrentDictionary>) contentNodesField.GetValue(contentStore); + + var parentNode = contentNodes[1].Value; + Assert.AreEqual(-1, parentNode.PreviousSiblingContentId); + Assert.AreEqual(-1, parentNode.NextSiblingContentId); + Assert.AreEqual(2, parentNode.FirstChildContentId); + Assert.AreEqual(2, parentNode.LastChildContentId); + + _snapshotService.Notify(new[] + { + new ContentCacheRefresher.JsonPayload(2, TreeChangeTypes.Remove) + }, out _, out _); + + parentNode = contentNodes[1].Value; + Assert.AreEqual(-1, parentNode.PreviousSiblingContentId); + Assert.AreEqual(-1, parentNode.NextSiblingContentId); + Assert.AreEqual(-1, parentNode.FirstChildContentId); + Assert.AreEqual(-1, parentNode.LastChildContentId); + } + private void AssertDocuments(IPublishedContent[] documents, params string[] names) { Assert.AreEqual(names.Length, documents.Length);