diff --git a/src/XperienceCommunity.DataRepository/Helpers/CacheDependencyHelper.cs b/src/XperienceCommunity.DataRepository/Helpers/CacheDependencyHelper.cs
index b52e308..eed7dee 100644
--- a/src/XperienceCommunity.DataRepository/Helpers/CacheDependencyHelper.cs
+++ b/src/XperienceCommunity.DataRepository/Helpers/CacheDependencyHelper.cs
@@ -2,201 +2,200 @@
using CMS.Helpers;
using CMS.Websites;
-namespace XperienceCommunity.DataRepository.Helpers
+namespace XperienceCommunity.DataRepository.Helpers;
+
+///
+/// Provides helper methods for creating cache dependencies for content and web page items.
+///
+public static class CacheDependencyHelper
{
///
- /// Provides helper methods for creating cache dependencies for content and web page items.
+ /// Creates cache keys for web page items by their GUIDs.
+ ///
+ /// The GUIDs of the web page items.
+ /// An array of cache keys.
+ public static string[] CreateContentItemGUIDKeys(IEnumerable? itemGuids) =>
+ itemGuids?.Select(x => CreateContentItemGUIDKey(x))?.ToArray() ?? [];
+
+ ///
+ /// Creates cache keys for web page items by their GUIDs.
+ ///
+ /// The GUIDs of the web page items.
+ /// An array of cache keys.
+ public static string[] CreateWebPageItemGUIDKeys(IEnumerable? itemGuids) =>
+ itemGuids?.Select(x => CreateWebPageItemGUIDKey(x))?.ToArray() ?? [];
+
+ ///
+ /// Creates a cache key for a web page item by its GUID.
+ ///
+ /// The GUID of the web page item.
+ /// A cache key.
+ public static string CreateWebPageItemGUIDKey(Guid? itemGuid) => $"webpageitem|byguid|{itemGuid}";
+
+ ///
+ /// Creates a cache key for a web page item by its ID.
+ ///
+ /// The ID of the web page item.
+ /// A cache key.
+ public static string CreateWebPageItemIdKey(int? itemId) => $"webpageitem|byid|{itemId}";
+
+ ///
+ /// Creates a cache key for a content item by its GUID.
+ ///
+ /// The GUID of the web page item.
+ /// A cache key.
+ public static string CreateContentItemGUIDKey(Guid? itemGuid) => $"contentitem|byguid|{itemGuid}";
+
+ ///
+ /// Creates a cache key for a content item by its ID.
+ ///
+ /// The ID of the web page item.
+ /// A cache key.
+ public static string CreateContentItemIdKey(int? itemId) => $"contentitem|byid|{itemId}";
+
+ ///
+ /// Creates cache keys for content items by their IDs.
+ ///
+ /// The IDs of the web page items.
+ /// An array of cache keys.
+ public static string[] CreateContentItemIdKeys(IEnumerable? itemIdList) =>
+ itemIdList?.Select(x => CreateContentItemIdKey(x))?.ToArray() ?? [];
+
+ ///
+ /// Creates cache keys for web page items by their IDs.
+ ///
+ /// The IDs of the web page items.
+ /// An array of cache keys.
+ public static string[] CreateWebPageItemIdKeys(IEnumerable? itemIdList) =>
+ itemIdList?.Select(x => CreateWebPageItemIdKey(x))?.ToArray() ?? [];
+
+ ///
+ /// Creates cache keys for web page items by content type and channel name.
+ ///
+ /// The content types.
+ /// The channel name.
+ /// An array of cache keys.
+ public static string[] CreateWebPageItemTypeKeys(IEnumerable? contentTypes, string channelName) =>
+ contentTypes?.Select(x => $"webpageitem|bychannel|{channelName}|bycontenttype|{x}")?.ToArray() ?? [];
+
+ ///
+ /// Creates cache keys for content items by content type.
+ ///
+ /// The content types.
+ /// An array of cache keys.
+ public static string[] CreateContentItemTypeKeys(IEnumerable? contentTypes) =>
+ contentTypes?.Select(x => $"contentitem|bycontenttype|{x}")?.ToArray() ?? [];
+
+ ///
+ /// Creates cache keys for content items by their GUIDs.
+ ///
+ /// The type of the content items.
+ /// The content items.
+ /// An array of cache keys.
+ public static string[] CreateContentItemKeys(IEnumerable? items) where T : IContentItemFieldsSource =>
+ items?.Select(x => $"contentitem|byid|{x.SystemFields.ContentItemGUID}")?.ToArray() ?? [];
+
+ ///
+ /// Creates cache keys for web page items by their IDs.
+ ///
+ /// The type of the web page items.
+ /// The web page items.
+ /// An array of cache keys.
+ public static string[] CreateWebPageItemKeys(IEnumerable? items) where T : IWebPageFieldsSource =>
+ items?.Select(x => $"webpageitem|byid|{x.SystemFields.WebPageItemID}")?.ToArray() ?? [];
+
+ ///
+ /// Creates a cache dependency for the specified content items.
+ ///
+ /// The type of the content items.
+ /// The content items.
+ /// A cache dependency for the specified content items.
+ public static CMSCacheDependency CreateContentItemCacheDependency(IEnumerable? items)
+ where T : IContentItemFieldsSource
+ {
+ string[] contentItemKeys = CreateContentItemKeys(items);
+
+ return CacheHelper.GetCacheDependency(contentItemKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for the specified web page items.
+ ///
+ /// The type of the web page items.
+ /// The web page items.
+ /// A cache dependency for the specified web page items.
+ public static CMSCacheDependency CreateWebPageItemCacheDependency(IEnumerable? items)
+ where T : IWebPageFieldsSource
+ {
+ string[] webPageItemKeys = CreateWebPageItemKeys(items);
+ return CacheHelper.GetCacheDependency(webPageItemKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for web page items by content type and channel name.
+ ///
+ /// The content types.
+ /// The channel name.
+ /// A cache dependency for the specified web page items.
+ public static CMSCacheDependency CreateWebPageItemTypeCacheDependency(IEnumerable? contentTypes,
+ string channelName)
+ {
+ string[] webPageItemTypeKeys = CreateWebPageItemTypeKeys(contentTypes, channelName);
+ return CacheHelper.GetCacheDependency(webPageItemTypeKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for content items by content type.
+ ///
+ /// The content types.
+ /// A cache dependency for the specified content items.
+ public static CMSCacheDependency CreateContentItemTypeCacheDependency(IEnumerable? contentTypes)
+ {
+ string[] contentItemTypeKeys = CreateContentItemTypeKeys(contentTypes);
+ return CacheHelper.GetCacheDependency(contentItemTypeKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for web page items by their GUIDs.
+ ///
+ /// The GUIDs of the web page items.
+ /// A cache dependency for the specified web page items.
+ public static CMSCacheDependency CreateWebPageItemGUIDCacheDependency(IEnumerable? itemGuids)
+ {
+ string[] webPageItemGUIDKeys = CreateWebPageItemGUIDKeys(itemGuids);
+ return CacheHelper.GetCacheDependency(webPageItemGUIDKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for web page items by their IDs.
+ ///
+ ///
+ ///
+ public static CMSCacheDependency CreateWebPageItemIDCacheDependency(IEnumerable? itemIdList)
+ {
+ string[] webPageItemIdKeys = CreateWebPageItemIdKeys(itemIdList);
+ return CacheHelper.GetCacheDependency(webPageItemIdKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for content items by their GUIDs.
+ ///
+ /// The GUIDs of the web page items.
+ /// A cache dependency for the specified web page items.
+ public static CMSCacheDependency CreateContentItemGUIDCacheDependency(IEnumerable? itemGuids)
+ {
+ string[] webPageItemGUIDKeys = CreateContentItemGUIDKeys(itemGuids);
+ return CacheHelper.GetCacheDependency(webPageItemGUIDKeys);
+ }
+
+ ///
+ /// Creates a cache dependency for content items by their IDs.
///
- public static class CacheDependencyHelper
+ ///
+ ///
+ public static CMSCacheDependency CreateContentItemIDCacheDependency(IEnumerable? itemIdList)
{
- ///
- /// Creates cache keys for web page items by their GUIDs.
- ///
- /// The GUIDs of the web page items.
- /// An array of cache keys.
- public static string[] CreateContentItemGUIDKeys(IEnumerable? itemGuids) =>
- itemGuids?.Select(x => CreateContentItemGUIDKey(x))?.ToArray() ?? [];
-
- ///
- /// Creates cache keys for web page items by their GUIDs.
- ///
- /// The GUIDs of the web page items.
- /// An array of cache keys.
- public static string[] CreateWebPageItemGUIDKeys(IEnumerable? itemGuids) =>
- itemGuids?.Select(x => CreateWebPageItemGUIDKey(x))?.ToArray() ?? [];
-
- ///
- /// Creates a cache key for a web page item by its GUID.
- ///
- /// The GUID of the web page item.
- /// A cache key.
- public static string CreateWebPageItemGUIDKey(Guid? itemGuid) => $"webpageitem|byguid|{itemGuid}";
-
- ///
- /// Creates a cache key for a web page item by its ID.
- ///
- /// The ID of the web page item.
- /// A cache key.
- public static string CreateWebPageItemIdKey(int? itemId) => $"webpageitem|byid|{itemId}";
-
- ///
- /// Creates a cache key for a content item by its GUID.
- ///
- /// The GUID of the web page item.
- /// A cache key.
- public static string CreateContentItemGUIDKey(Guid? itemGuid) => $"contentitem|byguid|{itemGuid}";
-
- ///
- /// Creates a cache key for a content item by its ID.
- ///
- /// The ID of the web page item.
- /// A cache key.
- public static string CreateContentItemIdKey(int? itemId) => $"contentitem|byid|{itemId}";
-
- ///
- /// Creates cache keys for content items by their IDs.
- ///
- /// The IDs of the web page items.
- /// An array of cache keys.
- public static string[] CreateContentItemIdKeys(IEnumerable? itemIdList) =>
- itemIdList?.Select(x => CreateContentItemIdKey(x))?.ToArray() ?? [];
-
- ///
- /// Creates cache keys for web page items by their IDs.
- ///
- /// The IDs of the web page items.
- /// An array of cache keys.
- public static string[] CreateWebPageItemIdKeys(IEnumerable? itemIdList) =>
- itemIdList?.Select(x => CreateWebPageItemIdKey(x))?.ToArray() ?? [];
-
- ///
- /// Creates cache keys for web page items by content type and channel name.
- ///
- /// The content types.
- /// The channel name.
- /// An array of cache keys.
- public static string[] CreateWebPageItemTypeKeys(IEnumerable? contentTypes, string channelName) =>
- contentTypes?.Select(x => $"webpageitem|bychannel|{channelName}|bycontenttype|{x}")?.ToArray() ?? [];
-
- ///
- /// Creates cache keys for content items by content type.
- ///
- /// The content types.
- /// An array of cache keys.
- public static string[] CreateContentItemTypeKeys(IEnumerable? contentTypes) =>
- contentTypes?.Select(x => $"contentitem|bycontenttype|{x}")?.ToArray() ?? [];
-
- ///
- /// Creates cache keys for content items by their GUIDs.
- ///
- /// The type of the content items.
- /// The content items.
- /// An array of cache keys.
- public static string[] CreateContentItemKeys(IEnumerable? items) where T : IContentItemFieldsSource =>
- items?.Select(x => $"contentitem|byid|{x.SystemFields.ContentItemGUID}")?.ToArray() ?? [];
-
- ///
- /// Creates cache keys for web page items by their IDs.
- ///
- /// The type of the web page items.
- /// The web page items.
- /// An array of cache keys.
- public static string[] CreateWebPageItemKeys(IEnumerable? items) where T : IWebPageFieldsSource =>
- items?.Select(x => $"webpageitem|byid|{x.SystemFields.WebPageItemID}")?.ToArray() ?? [];
-
- ///
- /// Creates a cache dependency for the specified content items.
- ///
- /// The type of the content items.
- /// The content items.
- /// A cache dependency for the specified content items.
- public static CMSCacheDependency CreateContentItemCacheDependency(IEnumerable? items)
- where T : IContentItemFieldsSource
- {
- string[] contentItemKeys = CreateContentItemKeys(items);
-
- return CacheHelper.GetCacheDependency(contentItemKeys);
- }
-
- ///
- /// Creates a cache dependency for the specified web page items.
- ///
- /// The type of the web page items.
- /// The web page items.
- /// A cache dependency for the specified web page items.
- public static CMSCacheDependency CreateWebPageItemCacheDependency(IEnumerable? items)
- where T : IWebPageFieldsSource
- {
- string[] webPageItemKeys = CreateWebPageItemKeys(items);
- return CacheHelper.GetCacheDependency(webPageItemKeys);
- }
-
- ///
- /// Creates a cache dependency for web page items by content type and channel name.
- ///
- /// The content types.
- /// The channel name.
- /// A cache dependency for the specified web page items.
- public static CMSCacheDependency CreateWebPageItemTypeCacheDependency(IEnumerable? contentTypes,
- string channelName)
- {
- string[] webPageItemTypeKeys = CreateWebPageItemTypeKeys(contentTypes, channelName);
- return CacheHelper.GetCacheDependency(webPageItemTypeKeys);
- }
-
- ///
- /// Creates a cache dependency for content items by content type.
- ///
- /// The content types.
- /// A cache dependency for the specified content items.
- public static CMSCacheDependency CreateContentItemTypeCacheDependency(IEnumerable? contentTypes)
- {
- string[] contentItemTypeKeys = CreateContentItemTypeKeys(contentTypes);
- return CacheHelper.GetCacheDependency(contentItemTypeKeys);
- }
-
- ///
- /// Creates a cache dependency for web page items by their GUIDs.
- ///
- /// The GUIDs of the web page items.
- /// A cache dependency for the specified web page items.
- public static CMSCacheDependency CreateWebPageItemGUIDCacheDependency(IEnumerable? itemGuids)
- {
- string[] webPageItemGUIDKeys = CreateWebPageItemGUIDKeys(itemGuids);
- return CacheHelper.GetCacheDependency(webPageItemGUIDKeys);
- }
-
- ///
- /// Creates a cache dependency for web page items by their IDs.
- ///
- ///
- ///
- public static CMSCacheDependency CreateWebPageItemIDCacheDependency(IEnumerable? itemIdList)
- {
- string[] webPageItemIdKeys = CreateWebPageItemIdKeys(itemIdList);
- return CacheHelper.GetCacheDependency(webPageItemIdKeys);
- }
-
- ///
- /// Creates a cache dependency for content items by their GUIDs.
- ///
- /// The GUIDs of the web page items.
- /// A cache dependency for the specified web page items.
- public static CMSCacheDependency CreateContentItemGUIDCacheDependency(IEnumerable? itemGuids)
- {
- string[] webPageItemGUIDKeys = CreateContentItemGUIDKeys(itemGuids);
- return CacheHelper.GetCacheDependency(webPageItemGUIDKeys);
- }
-
- ///
- /// Creates a cache dependency for content items by their IDs.
- ///
- ///
- ///
- public static CMSCacheDependency CreateContentItemIDCacheDependency(IEnumerable? itemIdList)
- {
- string[] webPageItemIdKeys = CreateContentItemIdKeys(itemIdList);
- return CacheHelper.GetCacheDependency(webPageItemIdKeys);
- }
+ string[] webPageItemIdKeys = CreateContentItemIdKeys(itemIdList);
+ return CacheHelper.GetCacheDependency(webPageItemIdKeys);
}
}
diff --git a/tests/XperienceCommunity.DataRepository.Tests/Extensions/IContentItemFieldsSourceExtensionsTests.cs b/tests/XperienceCommunity.DataRepository.Tests/Extensions/IContentItemFieldsSourceExtensionsTests.cs
index a80e160..8854402 100644
--- a/tests/XperienceCommunity.DataRepository.Tests/Extensions/IContentItemFieldsSourceExtensionsTests.cs
+++ b/tests/XperienceCommunity.DataRepository.Tests/Extensions/IContentItemFieldsSourceExtensionsTests.cs
@@ -168,7 +168,7 @@ public void GetContentItemGUIDs_ReturnsCorrectGUIDs()
public class TestContentItemFieldsSource : IContentItemFieldsSource
{
- public static string CONTENT_TYPE_NAME = "TestContentItemFieldsSource";
+ public const string CONTENT_TYPE_NAME = "TestContentItemFieldsSource";
public ContentItemFields SystemFields => new ContentItemFields();
}
}
diff --git a/tests/XperienceCommunity.DataRepository.Tests/Extensions/IWebPageFieldsSourceExtensionsTests.cs b/tests/XperienceCommunity.DataRepository.Tests/Extensions/IWebPageFieldsSourceExtensionsTests.cs
index b214789..cabc454 100644
--- a/tests/XperienceCommunity.DataRepository.Tests/Extensions/IWebPageFieldsSourceExtensionsTests.cs
+++ b/tests/XperienceCommunity.DataRepository.Tests/Extensions/IWebPageFieldsSourceExtensionsTests.cs
@@ -11,7 +11,7 @@ public class IWebPageFieldsSourceExtensionsTests
{
public class TestWebPageFieldsSource : IWebPageFieldsSource
{
- public static string CONTENT_TYPE_NAME = "TestWebPageFieldsSource";
+ public const string CONTENT_TYPE_NAME = "TestWebPageFieldsSource";
public WebPageFields SystemFields => new();
}
diff --git a/tests/XperienceCommunity.DataRepository.Tests/Extensions/TypeExtensionsTests.cs b/tests/XperienceCommunity.DataRepository.Tests/Extensions/TypeExtensionsTests.cs
index ca68809..7bc026a 100644
--- a/tests/XperienceCommunity.DataRepository.Tests/Extensions/TypeExtensionsTests.cs
+++ b/tests/XperienceCommunity.DataRepository.Tests/Extensions/TypeExtensionsTests.cs
@@ -188,7 +188,7 @@ public void GetRelatedWebPageGuids_MultipleItems_ReturnsGuids()
var result = source.GetRelatedWebPageGuids(x => x.RelatedItems);
// Assert
- Assert.That(result, Is.EquivalentTo(new[] { guid1, guid2 }));
+ Assert.That(result, Is.EquivalentTo([guid1, guid2]));
}
[Test]
@@ -302,7 +302,7 @@ public void GetRelatedAssetItemGuids_NoItems_ReturnsEmpty()
public class TestContentItemFieldsSource : IContentItemFieldsSource
{
- public static string CONTENT_TYPE_NAME = "TestContentItemFieldsSource";
+ public const string CONTENT_TYPE_NAME = "TestContentItemFieldsSource";
public AssetRelatedItem RelatedAssetItem { get; set; } = new AssetRelatedItem();
@@ -314,7 +314,7 @@ public class TestContentItemFieldsSource : IContentItemFieldsSource
public class TestWebPageFieldsSource : IWebPageFieldsSource
{
- public static string CONTENT_TYPE_NAME = "TestWebPageFieldsSource";
+ public const string CONTENT_TYPE_NAME = "TestWebPageFieldsSource";
public WebPageRelatedItem RelatedItem { get; set; } = new WebPageRelatedItem();
diff --git a/tests/XperienceCommunity.DataRepository.Tests/Helpers/CacheDependencyHelperTests.cs b/tests/XperienceCommunity.DataRepository.Tests/Helpers/CacheDependencyHelperTests.cs
new file mode 100644
index 0000000..c25aeef
--- /dev/null
+++ b/tests/XperienceCommunity.DataRepository.Tests/Helpers/CacheDependencyHelperTests.cs
@@ -0,0 +1,229 @@
+using CMS.ContentEngine;
+using CMS.Websites;
+
+using XperienceCommunity.DataRepository.Helpers;
+
+namespace XperienceCommunity.DataRepository.Tests.Helpers
+{
+ [TestFixture]
+ public class CacheDependencyHelperTests
+ {
+ [Test]
+ public void CreateContentItemGUIDKeys_ShouldReturnEmptyArray_WhenItemGuidsIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemGUIDKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateContentItemGUIDKeys_ShouldReturnCacheKeys_WhenItemGuidsIsNotNull()
+ {
+ // Arrange
+ var guids = new List { Guid.NewGuid(), Guid.NewGuid() };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemGUIDKeys(guids);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(guids.Count));
+ Assert.That(result[0], Is.EqualTo($"contentitem|byguid|{guids[0]}"));
+ Assert.That(result[1], Is.EqualTo($"contentitem|byguid|{guids[1]}"));
+ }
+
+ [Test]
+ public void CreateWebPageItemGUIDKeys_ShouldReturnEmptyArray_WhenItemGuidsIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemGUIDKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateWebPageItemGUIDKeys_ShouldReturnCacheKeys_WhenItemGuidsIsNotNull()
+ {
+ // Arrange
+ var guids = new List { Guid.NewGuid(), Guid.NewGuid() };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemGUIDKeys(guids);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(guids.Count));
+ Assert.That(result[0], Is.EqualTo($"webpageitem|byguid|{guids[0]}"));
+ Assert.That(result[1], Is.EqualTo($"webpageitem|byguid|{guids[1]}"));
+ }
+
+ [Test]
+ public void CreateContentItemIdKeys_ShouldReturnEmptyArray_WhenItemIdListIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemIdKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateContentItemIdKeys_ShouldReturnCacheKeys_WhenItemIdListIsNotNull()
+ {
+ // Arrange
+ var ids = new List { 1, 2 };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemIdKeys(ids);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(ids.Count));
+ Assert.That(result[0], Is.EqualTo("contentitem|byid|1"));
+ Assert.That(result[1], Is.EqualTo("contentitem|byid|2"));
+ }
+
+ [Test]
+ public void CreateWebPageItemIdKeys_ShouldReturnEmptyArray_WhenItemIdListIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemIdKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateWebPageItemIdKeys_ShouldReturnCacheKeys_WhenItemIdListIsNotNull()
+ {
+ // Arrange
+ var ids = new List { 1, 2 };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemIdKeys(ids);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(ids.Count));
+ Assert.That(result[0], Is.EqualTo("webpageitem|byid|1"));
+ Assert.That(result[1], Is.EqualTo("webpageitem|byid|2"));
+ }
+
+ [Test]
+ public void CreateWebPageItemTypeKeys_ShouldReturnEmptyArray_WhenContentTypesIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemTypeKeys(null, "channel");
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateWebPageItemTypeKeys_ShouldReturnCacheKeys_WhenContentTypesIsNotNull()
+ {
+ // Arrange
+ var contentTypes = new List { "type1", "type2" };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemTypeKeys(contentTypes, "channel");
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(contentTypes.Count));
+ Assert.That(result[0], Is.EqualTo("webpageitem|bychannel|channel|bycontenttype|type1"));
+ Assert.That(result[1], Is.EqualTo("webpageitem|bychannel|channel|bycontenttype|type2"));
+ }
+
+ [Test]
+ public void CreateContentItemTypeKeys_ShouldReturnEmptyArray_WhenContentTypesIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemTypeKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateContentItemTypeKeys_ShouldReturnCacheKeys_WhenContentTypesIsNotNull()
+ {
+ // Arrange
+ var contentTypes = new List { "type1", "type2" };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemTypeKeys(contentTypes);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(contentTypes.Count));
+ Assert.That(result[0], Is.EqualTo("contentitem|bycontenttype|type1"));
+ Assert.That(result[1], Is.EqualTo("contentitem|bycontenttype|type2"));
+ }
+
+ [Test]
+ public void CreateContentItemKeys_ShouldReturnEmptyArray_WhenItemsIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateContentItemKeys_ShouldReturnCacheKeys_WhenItemsIsNotNull()
+ {
+ // Arrange
+ var items = new List
+ {
+ new MockContentItemFieldsSource { SystemFields = new ContentItemFields { ContentItemGUID = Guid.NewGuid() } },
+ new MockContentItemFieldsSource { SystemFields = new ContentItemFields { ContentItemGUID = Guid.NewGuid() } }
+ };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateContentItemKeys(items);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(items.Count));
+ Assert.That(result[0], Is.EqualTo($"contentitem|byid|{items[0].SystemFields.ContentItemGUID}"));
+ Assert.That(result[1], Is.EqualTo($"contentitem|byid|{items[1].SystemFields.ContentItemGUID}"));
+ }
+
+ [Test]
+ public void CreateWebPageItemKeys_ShouldReturnEmptyArray_WhenItemsIsNull()
+ {
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemKeys(null);
+
+ // Assert
+ Assert.That(result, Is.Empty);
+ }
+
+ [Test]
+ public void CreateWebPageItemKeys_ShouldReturnCacheKeys_WhenItemsIsNotNull()
+ {
+ // Arrange
+ var items = new List
+ {
+ new MockWebPageFieldsSource { SystemFields = new WebPageFields { WebPageItemID = 1 } },
+ new MockWebPageFieldsSource { SystemFields = new WebPageFields { WebPageItemID = 2 } }
+ };
+
+ // Act
+ string[] result = CacheDependencyHelper.CreateWebPageItemKeys(items);
+
+ // Assert
+ Assert.That(result.Length, Is.EqualTo(items.Count));
+ Assert.That(result[0], Is.EqualTo("webpageitem|byid|1"));
+ Assert.That(result[1], Is.EqualTo("webpageitem|byid|2"));
+ }
+
+ public class MockContentItemFieldsSource : IContentItemFieldsSource
+ {
+ public ContentItemFields SystemFields { get; set; } = new ContentItemFields();
+ }
+
+ public class MockWebPageFieldsSource : IWebPageFieldsSource
+ {
+ public WebPageFields SystemFields { get; set; } = new WebPageFields();
+ }
+ }
+}