From 822a8cc2f100884d30f2fe88c084da845e2884c5 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Wed, 22 Jan 2025 21:19:12 +0100 Subject: [PATCH] v16: Start removing scope references (#18074) * Start removing scope references * Update src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs Co-authored-by: Andy Butland * Make test-only ctor internal * Fix tests * Dont treat warnings as errors * Disable package validation, as this is a major --------- Co-authored-by: Andy Butland --- Directory.Build.props | 4 +- .../Examine/ContentValueSetValidator.cs | 29 ++-------- .../Examine/UmbracoIndexConfig.cs | 6 +- .../UmbracoExamine/ExamineBaseTest.cs | 5 +- .../UmbracoContentValueSetValidatorTests.cs | 56 ++++++++++++++----- 5 files changed, 54 insertions(+), 46 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 2b792bce49..4dda16251e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ en-US enable nullable - true + false enable true false @@ -40,7 +40,7 @@ false - true + false 15.0.0 true true diff --git a/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs b/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs index c6e1de7ff2..259a1984ff 100644 --- a/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs +++ b/src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs @@ -15,20 +15,19 @@ public class ContentValueSetValidator : ValueSetValidator, IContentValueSetValid private const string PathKey = "path"; private static readonly IEnumerable ValidCategories = new[] { IndexTypes.Content, IndexTypes.Media }; private readonly IPublicAccessService? _publicAccessService; - private readonly IScopeProvider? _scopeProvider; + private readonly Scoping.IScopeProvider? _scopeProvider; // used for tests - public ContentValueSetValidator(bool publishedValuesOnly, int? parentId = null, IEnumerable? includeItemTypes = null, IEnumerable? excludeItemTypes = null) - : this(publishedValuesOnly, true, null, null, parentId, includeItemTypes, excludeItemTypes, null, null) + internal ContentValueSetValidator(bool publishedValuesOnly, int? parentId = null, IEnumerable? includeItemTypes = null, IEnumerable? excludeItemTypes = null) + : this(publishedValuesOnly, true, null, null, parentId, includeItemTypes, excludeItemTypes) { } - [Obsolete("Use the overload accepting includeFields and excludeFields instead. This overload will be removed in Umbraco 14.")] public ContentValueSetValidator( bool publishedValuesOnly, bool supportProtectedContent, IPublicAccessService? publicAccessService, - IScopeProvider? scopeProvider, + Scoping.IScopeProvider? scopeProvider, int? parentId, IEnumerable? includeItemTypes, IEnumerable? excludeItemTypes) @@ -41,26 +40,6 @@ public class ContentValueSetValidator : ValueSetValidator, IContentValueSetValid _scopeProvider = scopeProvider; } - [Obsolete("This constructor is obsolete, the IScopeProvider will change to Infrastructure.Scoping.ScopeProvider instead, this will be removed in Umbraco 14.")] - public ContentValueSetValidator( - bool publishedValuesOnly, - bool supportProtectedContent, - IPublicAccessService? publicAccessService, - IScopeProvider? scopeProvider, - int? parentId = null, - IEnumerable? includeItemTypes = null, - IEnumerable? excludeItemTypes = null, - IEnumerable? includeFields = null, - IEnumerable? excludeFields = null) - : base(includeItemTypes, excludeItemTypes, includeFields, excludeFields) - { - PublishedValuesOnly = publishedValuesOnly; - SupportProtectedContent = supportProtectedContent; - ParentId = parentId; - _publicAccessService = publicAccessService; - _scopeProvider = scopeProvider; - } - protected override IEnumerable ValidIndexCategories => ValidCategories; public bool PublishedValuesOnly { get; } diff --git a/src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs b/src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs index 2c6377768a..9688d56721 100644 --- a/src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs +++ b/src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs @@ -1,6 +1,6 @@ using Examine; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; namespace Umbraco.Cms.Infrastructure.Examine; @@ -17,10 +17,10 @@ public class UmbracoIndexConfig : IUmbracoIndexConfig protected IScopeProvider ScopeProvider { get; } public IContentValueSetValidator GetContentValueSetValidator() => - new ContentValueSetValidator(false, true, PublicAccessService, ScopeProvider); + new ContentValueSetValidator(false, true, PublicAccessService, ScopeProvider, null, null, null); public IContentValueSetValidator GetPublishedContentValueSetValidator() => - new ContentValueSetValidator(true, false, PublicAccessService, ScopeProvider); + new ContentValueSetValidator(true, false, PublicAccessService, ScopeProvider, null, null, null); /// /// Returns the for the member indexer diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs index 4d2fb1530b..fe5c459c7c 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/ExamineBaseTest.cs @@ -18,6 +18,7 @@ using Umbraco.Cms.Infrastructure.Examine; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Tests.Integration.Testing; using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services; +using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider; namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine; @@ -113,7 +114,9 @@ public abstract class ExamineBaseTest : UmbracoIntegrationTest false, publicAccessServiceMock.Object, scopeProviderMock.Object, - parentId); + parentId, + null, + null); } else { diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Examine/UmbracoContentValueSetValidatorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Examine/UmbracoContentValueSetValidatorTests.cs index 9bfa092180..97c866a604 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Examine/UmbracoContentValueSetValidatorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Examine/UmbracoContentValueSetValidatorTests.cs @@ -1,16 +1,14 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Collections.Generic; -using System.Linq; using Examine; using Moq; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.Examine; +using Umbraco.Cms.Infrastructure.Scoping; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Examine; @@ -24,7 +22,10 @@ public class UmbracoContentValueSetValidatorTests false, true, Mock.Of(), - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" })); @@ -48,7 +49,10 @@ public class UmbracoContentValueSetValidatorTests false, true, Mock.Of(), - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world" })); Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status); @@ -68,7 +72,9 @@ public class UmbracoContentValueSetValidatorTests true, Mock.Of(), Mock.Of(), - 555); + 555, + null, + null); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" })); @@ -170,7 +176,9 @@ public class UmbracoContentValueSetValidatorTests true, Mock.Of(), Mock.Of(), - includeItemTypes: new List { "include-content" }); + null, + new List { "include-content" }, + null); var result = validator.Validate(ValueSet.FromObject( "555", @@ -201,7 +209,9 @@ public class UmbracoContentValueSetValidatorTests true, Mock.Of(), Mock.Of(), - excludeItemTypes: new List { "exclude-content" }); + null, + null, + new List { "exclude-content" }); var result = validator.Validate(ValueSet.FromObject( "555", @@ -232,8 +242,9 @@ public class UmbracoContentValueSetValidatorTests true, Mock.Of(), Mock.Of(), - includeItemTypes: new List { "include-content", "exclude-content" }, - excludeItemTypes: new List { "exclude-content" }); + null, + new List { "include-content", "exclude-content" }, + new List { "exclude-content" }); var result = validator.Validate(ValueSet.FromObject( "555", @@ -270,7 +281,10 @@ public class UmbracoContentValueSetValidatorTests true, false, Mock.Of(), - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(ValueSet.FromObject( @@ -310,7 +324,10 @@ public class UmbracoContentValueSetValidatorTests true, false, Mock.Of(), - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(ValueSet.FromObject( @@ -337,7 +354,10 @@ public class UmbracoContentValueSetValidatorTests true, true, Mock.Of(), - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" })); @@ -373,7 +393,10 @@ public class UmbracoContentValueSetValidatorTests true, true, Mock.Of(), - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(new ValueSet( "555", @@ -443,7 +466,10 @@ public class UmbracoContentValueSetValidatorTests false, false, publicAccessService.Object, - Mock.Of()); + Mock.Of(), + null, + null, + null); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));