From 8c1667d2ba8d94284d409f79050bdcac69791faf Mon Sep 17 00:00:00 2001 From: Alistair Deneys Date: Wed, 19 Feb 2020 22:07:18 +1100 Subject: [PATCH] Fix builds and tests for all Sitecore versions --- .../Caching/ProfanityFilterCacheFixture.cs | 7 +++- .../CreateComment/AkismetSpamCheckFixture.cs | 8 ++-- .../GetProfanityListFromItemFixture.cs | 3 +- data/packages/WeBlog sc8.x.xml | 2 +- data/packages/WeBlog.xml | 2 +- sc version properties.targets | 2 +- .../WeBlog.ContentSearch.Solr.config.9.1.xslt | 13 ++++++ .../Caching/ProfanityFilterCache.cs | 2 + .../Caching/SimpleCache.cs | 2 + .../CreateComment/AkismetSpamCheck.cs | 41 +++++++++++++++---- .../Sitecore.Modules.WeBlog.csproj | 3 ++ src/SolutionInfo.cs | 2 +- 12 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 src/Sitecore.Modules.WeBlog/App_Config/Include/WeBlog.ContentSearch.Solr.config.9.1.xslt diff --git a/Test/UnitTest/Caching/ProfanityFilterCacheFixture.cs b/Test/UnitTest/Caching/ProfanityFilterCacheFixture.cs index 2a967f86..12b759d1 100644 --- a/Test/UnitTest/Caching/ProfanityFilterCacheFixture.cs +++ b/Test/UnitTest/Caching/ProfanityFilterCacheFixture.cs @@ -6,6 +6,7 @@ namespace Sitecore.Modules.WeBlog.UnitTest.Caching { +#if FEATURE_ABSTRACTIONS [TestFixture] public class ProfanityFilterCacheFixture { @@ -43,7 +44,10 @@ public void WordListGet_InnerCacheHasEntries_ReturnsWords() { // arrange #pragma warning disable CS0252 // Possible unintended reference comparison; left hand side needs cast - var innerCache = Mock.Of(x => x.GetValue("wordlist_database") == "lorem|ipsum"); + var innerCache = Mock.Of(x => + x.GetValue("wordlist_database") == "lorem|ipsum" && + x["wordlist_database"] == "lorem|ipsum" + ); #pragma warning restore CS0252 // Possible unintended reference comparison; left hand side needs cast var database = Mock.Of(x => x.Name == "database"); var sut = new ProfanityFilterCache(innerCache, database); @@ -88,4 +92,5 @@ public void WordListSet_DatabaseIsNullAndWordsSet_SavesWordsToInnerCache() innerCache.Verify(x => x.Add("wordlist_master", "lorem|ipsum")); } } +#endif } diff --git a/Test/UnitTest/Pipelines/CreateComment/AkismetSpamCheckFixture.cs b/Test/UnitTest/Pipelines/CreateComment/AkismetSpamCheckFixture.cs index c5295fda..fd81afa2 100644 --- a/Test/UnitTest/Pipelines/CreateComment/AkismetSpamCheckFixture.cs +++ b/Test/UnitTest/Pipelines/CreateComment/AkismetSpamCheckFixture.cs @@ -1,4 +1,5 @@ -using Joel.Net; +#if FEATURE_ABSTRACTIONS +using Joel.Net; using Moq; using NUnit.Framework; using Sitecore.Abstractions; @@ -78,7 +79,7 @@ public void Process_WhenCalled_InitializesAkismetApi() sut.Process(args); // assert - akismetApiMock.Verify(x => x.Init("apikey", "link", "WeBlog/4.0.0.0")); + akismetApiMock.Verify(x => x.Init("apikey", "link", "WeBlog/4.0.1.0")); } [Test] @@ -152,7 +153,7 @@ public void Process_CommentIsSpam_AbortsPipeline() var akismetApiMock = new Mock(); - var processor = new AkismetSpamCheck(settings, linkManager, blogManager, akismetApiMock.Object); + var processor = new AkismetSpamCheck(settings, blogManager, akismetApiMock.Object, linkManager); var item = CreateCommentItem(); var database = Mock.Of(x => @@ -198,3 +199,4 @@ private CommentItem CreateCommentItem() } } } +#endif \ No newline at end of file diff --git a/Test/UnitTest/Pipelines/ProfanityFilter/GetProfanityListFromItemFixture.cs b/Test/UnitTest/Pipelines/ProfanityFilter/GetProfanityListFromItemFixture.cs index 014aed3d..b8328eea 100644 --- a/Test/UnitTest/Pipelines/ProfanityFilter/GetProfanityListFromItemFixture.cs +++ b/Test/UnitTest/Pipelines/ProfanityFilter/GetProfanityListFromItemFixture.cs @@ -6,6 +6,7 @@ namespace Sitecore.Modules.WeBlog.UnitTest.Pipelines.ProfanityFilter { +#if FEATURE_ABSTRACTIONS [TestFixture] public class GetProfanityListFromItemFixture { @@ -24,7 +25,6 @@ public void Process_UnknownItem_DoesNotPopulateWords() Assert.That(args.WordList, Is.Empty); } - [Test] public void Process_ValidItem_PopulatesWords() { @@ -72,4 +72,5 @@ public void Process_WordsAlreadyPopulated_DoesNothing() Assert.That(args.WordList, Is.EquivalentTo(new[] { "dolor" })); } } +#endif } diff --git a/data/packages/WeBlog sc8.x.xml b/data/packages/WeBlog sc8.x.xml index 735c7a2a..0f3030c6 100644 --- a/data/packages/WeBlog sc8.x.xml +++ b/data/packages/WeBlog sc8.x.xml @@ -3,7 +3,7 @@ WeBlog WeTeam Community - 4.0.0 + 4.0.1 <p><strong>The MIT License (MIT)</strong><br/> Copyright (c) 2011 - 2020 WeTeam Community diff --git a/data/packages/WeBlog.xml b/data/packages/WeBlog.xml index 2787e3e9..eb26043a 100644 --- a/data/packages/WeBlog.xml +++ b/data/packages/WeBlog.xml @@ -3,7 +3,7 @@ WeBlog WeTeam Community - 4.0.0 + 4.0.1 <p><strong>The MIT License (MIT)</strong><br/> Copyright (c) 2011 - 2020 WeTeam Community diff --git a/sc version properties.targets b/sc version properties.targets index 54ea2683..f02536b5 100644 --- a/sc version properties.targets +++ b/sc version properties.targets @@ -28,7 +28,7 @@ v4.7.1 - $(DefineConstants);FEATURE_ABSTRACTIONS;FEATURE_XCONNECT;FEATURE_NVELOCITY;SOLR + $(DefineConstants);FEATURE_ABSTRACTIONS;FEATURE_XCONNECT;FEATURE_NVELOCITY;SOLR;SC91 bin\sc91\ diff --git a/src/Sitecore.Modules.WeBlog/App_Config/Include/WeBlog.ContentSearch.Solr.config.9.1.xslt b/src/Sitecore.Modules.WeBlog/App_Config/Include/WeBlog.ContentSearch.Solr.config.9.1.xslt new file mode 100644 index 00000000..439a5bc5 --- /dev/null +++ b/src/Sitecore.Modules.WeBlog/App_Config/Include/WeBlog.ContentSearch.Solr.config.9.1.xslt @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/Sitecore.Modules.WeBlog/Caching/ProfanityFilterCache.cs b/src/Sitecore.Modules.WeBlog/Caching/ProfanityFilterCache.cs index 946cc3e3..a9f1f452 100644 --- a/src/Sitecore.Modules.WeBlog/Caching/ProfanityFilterCache.cs +++ b/src/Sitecore.Modules.WeBlog/Caching/ProfanityFilterCache.cs @@ -15,10 +15,12 @@ public ProfanityFilterCache(string name, long maxSize) : base(name, maxSize) _database = ContentHelper.GetContentDatabase(); } +#if FEATURE_ABSTRACTIONS public ProfanityFilterCache(ICache innerCache, Database database) : base(innerCache) { _database = database ?? ContentHelper.GetContentDatabase(); } +#endif protected string CacheName { diff --git a/src/Sitecore.Modules.WeBlog/Caching/SimpleCache.cs b/src/Sitecore.Modules.WeBlog/Caching/SimpleCache.cs index 0c2fdc67..0232c3a3 100644 --- a/src/Sitecore.Modules.WeBlog/Caching/SimpleCache.cs +++ b/src/Sitecore.Modules.WeBlog/Caching/SimpleCache.cs @@ -6,7 +6,9 @@ public class SimpleCache : CustomCache { public SimpleCache(string name, long maxSize) : base(name, maxSize) { } +#if FEATURE_ABSTRACTIONS public SimpleCache(ICache innerCache) : base(innerCache) { } +#endif public string Get(string cacheKey) { diff --git a/src/Sitecore.Modules.WeBlog/Pipelines/CreateComment/AkismetSpamCheck.cs b/src/Sitecore.Modules.WeBlog/Pipelines/CreateComment/AkismetSpamCheck.cs index 0395b93c..fb952ff2 100644 --- a/src/Sitecore.Modules.WeBlog/Pipelines/CreateComment/AkismetSpamCheck.cs +++ b/src/Sitecore.Modules.WeBlog/Pipelines/CreateComment/AkismetSpamCheck.cs @@ -2,8 +2,6 @@ using System.Diagnostics; using System.Reflection; using Joel.Net; -using Sitecore.Abstractions; -using Sitecore.DependencyInjection; using Sitecore.Diagnostics; using Sitecore.Links; using Sitecore.Modules.WeBlog.Configuration; @@ -11,32 +9,56 @@ using Sitecore.Modules.WeBlog.Managers; using Sitecore.Sites; +#if FEATURE_ABSTRACTIONS +using Sitecore.Abstractions; +using Sitecore.DependencyInjection; +#endif + namespace Sitecore.Modules.WeBlog.Pipelines.CreateComment { public class AkismetSpamCheck : ICreateCommentProcessor { private IWeBlogSettings _settings = null; - private BaseLinkManager _linkManager = null; private IAkismet _akismetApi = null; private IBlogManager _blogManager = null; +#if FEATURE_ABSTRACTIONS + private BaseLinkManager _linkManager = null; +#endif + public AkismetSpamCheck() - : this(null, null, null, null) + : this(null, null, null +#if FEATURE_ABSTRACTIONS + , null +#endif + ) { } [Obsolete("Use ctor(IWeBlogSettings, BaseLinkManager, IBlogManager, IAkismet) instead.")] public AkismetSpamCheck(IWeBlogSettings settings) - : this(settings, null, null, null) + : this(settings, null, null +#if FEATURE_ABSTRACTIONS + , null +#endif + ) { } - public AkismetSpamCheck(IWeBlogSettings settings, BaseLinkManager linkManager, IBlogManager blogManager, IAkismet akismetApi) + public AkismetSpamCheck(IWeBlogSettings settings, IBlogManager blogManager, IAkismet akismetApi +#if FEATURE_ABSTRACTIONS + , BaseLinkManager linkManager +#endif + + ) { _settings = settings ?? WeBlogSettings.Instance; - _linkManager = linkManager ?? ServiceLocator.ServiceProvider.GetService(typeof(BaseLinkManager)) as BaseLinkManager; _blogManager = blogManager ?? ManagerFactory.BlogManagerInstance; _akismetApi = akismetApi; + +#if FEATURE_ABSTRACTIONS + _linkManager = linkManager ?? ServiceLocator.ServiceProvider.GetService(typeof(BaseLinkManager)) as BaseLinkManager; +#endif } public void Process(CreateCommentArgs args) @@ -57,7 +79,12 @@ public void Process(CreateCommentArgs args) var urlOptions = UrlOptions.DefaultOptions; urlOptions.AlwaysIncludeServerUrl = true; + +#if FEATURE_ABSTRACTIONS var url = _linkManager.GetItemUrl(_blogManager.GetCurrentBlog(), urlOptions); +#else + var url = LinkManager.GetItemUrl(_blogManager.GetCurrentBlog(), urlOptions); +#endif api.Init(_settings.AkismetAPIKey, url, "WeBlog/" + version); diff --git a/src/Sitecore.Modules.WeBlog/Sitecore.Modules.WeBlog.csproj b/src/Sitecore.Modules.WeBlog/Sitecore.Modules.WeBlog.csproj index 71f28701..0d3d8b22 100644 --- a/src/Sitecore.Modules.WeBlog/Sitecore.Modules.WeBlog.csproj +++ b/src/Sitecore.Modules.WeBlog/Sitecore.Modules.WeBlog.csproj @@ -353,6 +353,7 @@ + @@ -477,6 +478,8 @@ + + diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index 742a89e3..2b8e80f9 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -22,4 +22,4 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.0.1.*")] -[assembly: AssemblyFileVersion("4.0.0.0")] +[assembly: AssemblyFileVersion("4.0.1.0")]