Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Examine/UmbracoContentValueSetValidatorTests.cs

365 lines
16 KiB
C#
Raw Normal View History

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using System.Collections.Generic;
using System.Linq;
using Examine;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
Merge remote-tracking branch 'origin/v8/dev' into netcore/dev # Conflicts: # build/NuSpecs/UmbracoCms.Core.nuspec # build/NuSpecs/UmbracoCms.Web.nuspec # src/SolutionInfo.cs # src/Umbraco.Core/Cache/CacheKeys.cs # src/Umbraco.Core/Composing/TypeFinder.cs # src/Umbraco.Core/Configuration/GlobalSettings.cs # src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs # src/Umbraco.Core/Configuration/IGlobalSettings.cs # src/Umbraco.Core/Configuration/UmbracoSettings/ContentElement.cs # src/Umbraco.Core/Configuration/UmbracoSettings/ContentSectionExtensions.cs # src/Umbraco.Core/Constants-AppSettings.cs # src/Umbraco.Core/Editors/UserEditorAuthorizationHelper.cs # src/Umbraco.Core/Extensions/StringExtensions.cs # src/Umbraco.Core/Extensions/UriExtensions.cs # src/Umbraco.Core/IO/IOHelper.cs # src/Umbraco.Core/IO/PhysicalFileSystem.cs # src/Umbraco.Core/Media/Exif/MathEx.cs # src/Umbraco.Core/Media/UploadAutoFillProperties.cs # src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs # src/Umbraco.Core/Models/Membership/User.cs # src/Umbraco.Core/Models/UserExtensions.cs # src/Umbraco.Core/Packaging/PackageDefinitionXmlParser.cs # src/Umbraco.Core/PropertyEditors/ListViewConfiguration.cs # src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs # src/Umbraco.Core/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs # src/Umbraco.Core/Routing/AliasUrlProvider.cs # src/Umbraco.Core/Routing/DefaultUrlProvider.cs # src/Umbraco.Core/Routing/UriUtility.cs # src/Umbraco.Core/Routing/UrlProviderExtensions.cs # src/Umbraco.Core/Runtime/CoreRuntime.cs # src/Umbraco.Core/RuntimeOptions.cs # src/Umbraco.Core/RuntimeState.cs # src/Umbraco.Core/Security/BackOfficeUserStore.cs # src/Umbraco.Core/Security/ContentPermissions.cs # src/Umbraco.Core/Sync/ApplicationUrlHelper.cs # src/Umbraco.Core/Trees/TreeNode.cs # src/Umbraco.Core/Udi.cs # src/Umbraco.Examine.Lucene/BackOfficeExamineSearcher.cs # src/Umbraco.Examine/Umbraco.Examine.csproj # src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs # src/Umbraco.Infrastructure/Migrations/Install/DatabaseBuilder.cs # src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs # src/Umbraco.Infrastructure/Persistence/SqlSyntax/SqlServerSyntaxProvider.cs # src/Umbraco.Infrastructure/Scoping/Scope.cs # src/Umbraco.Infrastructure/Search/ExamineComponent.cs # src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs # src/Umbraco.Infrastructure/Services/Implement/ContentService.cs # src/Umbraco.Infrastructure/Services/Implement/MediaService.cs # src/Umbraco.Infrastructure/Services/Implement/NotificationService.cs # src/Umbraco.Persistence.SqlCe/SqlCeSyntaxProvider.cs # src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/LocksTests.cs # src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/UserExtensionsTests.cs # src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs # src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Examine/UmbracoContentValueSetValidatorTests.cs # src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs # src/Umbraco.Tests/Configurations/UmbracoSettings/umbracoSettings.config # src/Umbraco.Tests/TestHelpers/SettingsForTests.cs # src/Umbraco.Tests/Testing/TestDatabase.cs # src/Umbraco.Tests/Web/Controllers/ContentControllerUnitTests.cs # src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs # src/Umbraco.Tests/Web/Controllers/MediaControllerUnitTests.cs # src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs # src/Umbraco.Web.BackOffice/Controllers/CodeFileController.cs # src/Umbraco.Web.BackOffice/Controllers/ContentController.cs # src/Umbraco.Web.BackOffice/Controllers/EntityController.cs # src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs # src/Umbraco.Web.BackOffice/Controllers/MediaController.cs # src/Umbraco.Web.BackOffice/Controllers/PackageInstallController.cs # src/Umbraco.Web.BackOffice/Controllers/TourController.cs # src/Umbraco.Web.BackOffice/Controllers/UserGroupEditorAuthorizationHelper.cs # src/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttribute.cs # src/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingMediaAttribute.cs # src/Umbraco.Web.BackOffice/Mapping/ContentMapDefinition.cs # src/Umbraco.Web.BackOffice/Services/IconService.cs # src/Umbraco.Web.BackOffice/Trees/ContentTreeController.cs # src/Umbraco.Web.BackOffice/Trees/ContentTreeControllerBase.cs # src/Umbraco.Web.BackOffice/Trees/FileSystemTreeController.cs # src/Umbraco.Web.BackOffice/Trees/MediaTreeController.cs # src/Umbraco.Web.Common/Extensions/FormCollectionExtensions.cs # src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js # src/Umbraco.Web.UI.Client/src/views/content/overlays/publish.html # src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/editors/media.controller.js # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/da.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en.xml # src/Umbraco.Web.UI.NetCore/umbraco/config/lang/en_us.xml # src/Umbraco.Web.UI/config/umbracoSettings.Release.config # src/Umbraco.Web/Cache/MemberCacheRefresher.cs # src/Umbraco.Web/Composing/ModuleInjector.cs # src/Umbraco.Web/Editors/BackOfficeController.cs # src/Umbraco.Web/Editors/Binders/ContentModelBinderHelper.cs # src/Umbraco.Web/Editors/ContentTypeController.cs # src/Umbraco.Web/Editors/Filters/ContentSaveValidationAttribute.cs # src/Umbraco.Web/Editors/Filters/MediaItemSaveValidationAttribute.cs # src/Umbraco.Web/Editors/Filters/UserGroupAuthorizationAttribute.cs # src/Umbraco.Web/Editors/TinyMceController.cs # src/Umbraco.Web/Editors/UserGroupsController.cs # src/Umbraco.Web/Editors/UsersController.cs # src/Umbraco.Web/ImageCropperTemplateExtensions.cs # src/Umbraco.Web/Logging/WebProfiler.cs # src/Umbraco.Web/Logging/WebProfilerProvider.cs # src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs # src/Umbraco.Web/Mvc/EnsurePublishedContentRequestAttribute.cs # src/Umbraco.Web/Mvc/JsonNetResult.cs # src/Umbraco.Web/Mvc/MemberAuthorizeAttribute.cs # src/Umbraco.Web/Mvc/RenderRouteHandler.cs # src/Umbraco.Web/PropertyEditors/MediaPickerPropertyEditor.cs # src/Umbraco.Web/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs # src/Umbraco.Web/PublishedCache/NuCache/DataSource/DatabaseDataSource.cs # src/Umbraco.Web/RoutableDocumentFilter.cs # src/Umbraco.Web/Routing/ContentFinderByUrlAlias.cs # src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs # src/Umbraco.Web/Routing/PublishedRouter.cs # src/Umbraco.Web/Runtime/WebInitialComposer.cs # src/Umbraco.Web/Scheduling/KeepAlive.cs # src/Umbraco.Web/Security/AppBuilderExtensions.cs # src/Umbraco.Web/Security/BackOfficeClaimsIdentityFactory.cs # src/Umbraco.Web/Security/Providers/UmbracoMembershipProvider.cs # src/Umbraco.Web/Trees/DictionaryTreeController.cs # src/Umbraco.Web/Trees/LanguageTreeController.cs # src/Umbraco.Web/Trees/LogViewerTreeController.cs # src/Umbraco.Web/Trees/PackagesTreeController.cs # src/Umbraco.Web/UmbracoApplication.cs # src/Umbraco.Web/UmbracoApplicationBase.cs # src/Umbraco.Web/UmbracoInjectedModule.cs # src/Umbraco.Web/WebApi/Filters/AdminUsersAuthorizeAttribute.cs # src/Umbraco.Web/WebApi/Filters/CheckIfUserTicketDataIsStaleAttribute.cs # src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForContentAttribute.cs # src/Umbraco.Web/WebApi/Filters/EnsureUserPermissionForMediaAttribute.cs # src/Umbraco.Web/WebApi/MemberAuthorizeAttribute.cs
2021-03-05 15:36:27 +01:00
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
2021-02-12 10:57:50 +01:00
using Umbraco.Cms.Infrastructure.Examine;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Examine
{
[TestFixture]
public class UmbracoContentValueSetValidatorTests
{
2018-11-28 14:55:05 +11:00
[Test]
public void Invalid_Category()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
2018-11-28 14:55:05 +11:00
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
2018-11-28 14:55:05 +11:00
result = validator.Validate(ValueSet.FromObject("777", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
2018-11-28 14:55:05 +11:00
result = validator.Validate(ValueSet.FromObject("555", "invalid-category", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
2018-11-28 14:55:05 +11:00
}
[Test]
public void Must_Have_Path()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
[Test]
public void Parent_Id()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
555);
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,444" }));
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555,777" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555,777,999" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
[Test]
2018-11-28 19:10:43 +11:00
public void Inclusion_Field_List()
{
var validator = new ValueSetValidator(
null,
null,
2018-11-28 19:10:43 +11:00
new[] { "hello", "world" },
null);
var valueSet = ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
ValueSetValidationResult result = validator.Validate(valueSet);
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
2018-11-28 19:10:43 +11:00
Assert.IsFalse(result.ValueSet.Values.ContainsKey("path"));
Assert.IsTrue(result.ValueSet.Values.ContainsKey("hello"));
Assert.IsTrue(result.ValueSet.Values.ContainsKey("world"));
2018-11-28 19:10:43 +11:00
}
[Test]
public void Exclusion_Field_List()
{
var validator = new ValueSetValidator(
null,
null,
2018-11-28 19:10:43 +11:00
null,
new[] { "hello", "world" });
var valueSet = ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
ValueSetValidationResult result = validator.Validate(valueSet);
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
2018-11-28 19:10:43 +11:00
Assert.IsTrue(result.ValueSet.Values.ContainsKey("path"));
Assert.IsFalse(result.ValueSet.Values.ContainsKey("hello"));
Assert.IsFalse(result.ValueSet.Values.ContainsKey("world"));
2018-11-28 19:10:43 +11:00
}
[Test]
public void Inclusion_Exclusion_Field_List()
{
var validator = new ValueSetValidator(
null,
null,
2018-11-28 19:10:43 +11:00
new[] { "hello", "world" },
new[] { "world" });
var valueSet = ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
ValueSetValidationResult result = validator.Validate(valueSet);
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
2018-11-28 19:10:43 +11:00
Assert.IsFalse(result.ValueSet.Values.ContainsKey("path"));
Assert.IsTrue(result.ValueSet.Values.ContainsKey("hello"));
Assert.IsFalse(result.ValueSet.Values.ContainsKey("world"));
2018-11-28 19:10:43 +11:00
}
[Test]
public void Inclusion_Type_List()
{
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
2020-12-14 12:37:30 +11:00
Mock.Of<IScopeProvider>(),
includeItemTypes: new List<string> { "include-content" });
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "include-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
[Test]
2018-11-28 19:10:43 +11:00
public void Exclusion_Type_List()
{
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
2020-12-14 12:37:30 +11:00
Mock.Of<IScopeProvider>(),
excludeItemTypes: new List<string> { "exclude-content" });
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "exclude-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
}
[Test]
2018-11-28 19:10:43 +11:00
public void Inclusion_Exclusion_Type_List()
{
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
2020-12-14 12:37:30 +11:00
Mock.Of<IScopeProvider>(),
includeItemTypes: new List<string> { "include-content", "exclude-content" },
excludeItemTypes: new List<string> { "exclude-content" });
2018-11-28 19:10:43 +11:00
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "exclude-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "include-content", new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
[Test]
2018-11-28 19:10:43 +11:00
public void Recycle_Bin_Content()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
true,
false,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555,777" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(new ValueSet(
"555",
IndexTypes.Content,
new Dictionary<string, object>
{
["hello"] = "world",
["path"] = "-1,555",
[UmbracoExamineFieldNames.PublishedFieldName] = "y"
}));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
2018-11-28 19:10:43 +11:00
[Test]
public void Recycle_Bin_Media()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
true,
false,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
2018-11-28 19:10:43 +11:00
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555" }));
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
2018-11-28 19:10:43 +11:00
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555,777" }));
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
2018-11-28 19:10:43 +11:00
}
[Test]
public void Published_Only()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
true,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(new ValueSet(
"555",
IndexTypes.Content,
new Dictionary<string, object>
{
["hello"] = "world",
["path"] = "-1,555",
[UmbracoExamineFieldNames.PublishedFieldName] = "n"
}));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(new ValueSet(
"555",
IndexTypes.Content,
new Dictionary<string, object>
{
["hello"] = "world",
["path"] = "-1,555",
[UmbracoExamineFieldNames.PublishedFieldName] = "y"
}));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
[Test]
public void Published_Only_With_Variants()
{
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(true,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
ValueSetValidationResult result = validator.Validate(new ValueSet(
"555",
IndexTypes.Content,
new Dictionary<string, object>
{
["hello"] = "world",
["path"] = "-1,555",
[UmbracoExamineFieldNames.VariesByCultureFieldName] = "y",
[UmbracoExamineFieldNames.PublishedFieldName] = "n"
}));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
result = validator.Validate(new ValueSet(
"555",
IndexTypes.Content,
new Dictionary<string, object>
{
["hello"] = "world",
["path"] = "-1,555",
[UmbracoExamineFieldNames.VariesByCultureFieldName] = "y",
[UmbracoExamineFieldNames.PublishedFieldName] = "y"
}));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
var valueSet = new ValueSet(
"555",
IndexTypes.Content,
new Dictionary<string, object>
{
["hello"] = "world",
["path"] = "-1,555",
[UmbracoExamineFieldNames.VariesByCultureFieldName] = "y",
[$"{UmbracoExamineFieldNames.PublishedFieldName}_en-us"] = "y",
["hello_en-us"] = "world",
["title_en-us"] = "my title",
[$"{UmbracoExamineFieldNames.PublishedFieldName}_es-es"] = "n",
["hello_es-ES"] = "world",
["title_es-ES"] = "my title",
[UmbracoExamineFieldNames.PublishedFieldName] = "y"
});
2018-11-28 19:10:43 +11:00
Assert.AreEqual(10, valueSet.Values.Count());
Assert.IsTrue(valueSet.Values.ContainsKey($"{UmbracoExamineFieldNames.PublishedFieldName}_es-es"));
Assert.IsTrue(valueSet.Values.ContainsKey("hello_es-ES"));
Assert.IsTrue(valueSet.Values.ContainsKey("title_es-ES"));
result = validator.Validate(valueSet);
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
Assert.AreEqual(7, result.ValueSet.Values.Count()); // filtered to 7 values (removes es-es values)
Assert.IsFalse(result.ValueSet.Values.ContainsKey($"{UmbracoExamineFieldNames.PublishedFieldName}_es-es"));
Assert.IsFalse(result.ValueSet.Values.ContainsKey("hello_es-ES"));
Assert.IsFalse(result.ValueSet.Values.ContainsKey("title_es-ES"));
}
[Test]
public void Non_Protected()
{
var publicAccessService = new Mock<IPublicAccessService>();
publicAccessService.Setup(x => x.IsProtected("-1,555"))
.Returns(Attempt.Succeed(new PublicAccessEntry(Guid.NewGuid(), 555, 444, 333, Enumerable.Empty<PublicAccessRule>())));
publicAccessService.Setup(x => x.IsProtected("-1,777"))
.Returns(Attempt.Fail<PublicAccessEntry>());
2020-12-14 12:37:30 +11:00
var validator = new ContentValueSetValidator(
false,
false,
publicAccessService.Object,
Mock.Of<IScopeProvider>());
ValueSetValidationResult result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status);
result = validator.Validate(ValueSet.FromObject("777", IndexTypes.Content, new { hello = "world", path = "-1,777" }));
Assert.AreEqual(ValueSetValidationStatus.Valid, result.Status);
}
}
}