From aa9751afff5cbd6d710a2431511442c60bfb2fbc Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 26 Jun 2015 09:58:44 +0200 Subject: [PATCH] adds tests for U4-6696 --- .../DataTypeDefinitionRepository.cs | 10 +++++++--- .../DataTypeDefinitionRepositoryTest.cs | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs index 78b69f30b3..859c4e7ae7 100644 --- a/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/DataTypeDefinitionRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Globalization; using System.Linq; +using System.Text.RegularExpressions; using System.Threading; using Umbraco.Core.Cache; using Umbraco.Core.Logging; @@ -279,13 +280,16 @@ AND umbracoNode.id <> @id", return GetAndCachePreValueCollection(dataTypeId); } + internal static string GetCacheKeyRegex(int preValueId) + { + return CacheKeys.DataTypePreValuesCacheKey + @"[-\d]+-([\d]*,)*" + preValueId + @"(?!\d)[,\d$]*"; + } + public string GetPreValueAsString(int preValueId) { //We need to see if we can find the cached PreValueCollection based on the cache key above - var regex = CacheKeys.DataTypePreValuesCacheKey + @"[-\d]+-([\d]*,)*" + preValueId + @"(?!\d)[,\d$]*"; - - var cached = _cacheHelper.RuntimeCache.GetCacheItemsByKeyExpression(regex); + var cached = _cacheHelper.RuntimeCache.GetCacheItemsByKeyExpression(GetCacheKeyRegex(preValueId)); if (cached != null && cached.Any()) { //return from the cache diff --git a/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs index f3d7aaa0f1..289bd628ee 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Linq; +using System.Text.RegularExpressions; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -40,6 +41,23 @@ namespace Umbraco.Tests.Persistence.Repositories return dataTypeDefinitionRepository; } + [TestCase("UmbracoPreVal87-21,3,48", 3, true)] + [TestCase("UmbracoPreVal87-21,33,48", 3, false)] + [TestCase("UmbracoPreVal87-21,33,48", 33, true)] + [TestCase("UmbracoPreVal87-21,3,48", 33, false)] + [TestCase("UmbracoPreVal87-21,3,48", 21, true)] + [TestCase("UmbracoPreVal87-21,3,48", 48, true)] + [TestCase("UmbracoPreVal87-22,33,48", 2, false)] + [TestCase("UmbracoPreVal87-22,33,48", 22, true)] + [TestCase("UmbracoPreVal87-22,33,44", 4, false)] + [TestCase("UmbracoPreVal87-22,33,44", 44, true)] + [TestCase("UmbracoPreVal87-22,333,44", 33, false)] + [TestCase("UmbracoPreVal87-22,333,44", 333, true)] + public void Pre_Value_Cache_Key_Tests(string cacheKey, int preValueId, bool outcome) + { + Assert.AreEqual(outcome, Regex.IsMatch(cacheKey, DataTypeDefinitionRepository.GetCacheKeyRegex(preValueId))); + } + [Test] public void Can_Create() {