diff --git a/src/Umbraco.Examine/ContentValueSetValidator.cs b/src/Umbraco.Examine/ContentValueSetValidator.cs
index 9355d6d695..e12e20e224 100644
--- a/src/Umbraco.Examine/ContentValueSetValidator.cs
+++ b/src/Umbraco.Examine/ContentValueSetValidator.cs
@@ -85,7 +85,8 @@ namespace Umbraco.Examine
// return nothing if we're not supporting protected content and it is protected, and we're not supporting unpublished content
if (valueSet.Category == IndexTypes.Content
&& !SupportProtectedContent
- && _publicAccessService.IsProtected(path))
+ //if the service is null we can't look this up so we'll return false
+ && (_publicAccessService == null || _publicAccessService.IsProtected(path)))
{
return false;
}
diff --git a/src/Umbraco.Examine/ValueSetValidator.cs b/src/Umbraco.Examine/ValueSetValidator.cs
index 1bf7ec2d7a..a0e926fed0 100644
--- a/src/Umbraco.Examine/ValueSetValidator.cs
+++ b/src/Umbraco.Examine/ValueSetValidator.cs
@@ -10,9 +10,9 @@ namespace Umbraco.Examine
///
/// Performing basic validation of a value set
///
- public abstract class ValueSetValidator : IValueSetValidator
+ public class ValueSetValidator : IValueSetValidator
{
- protected ValueSetValidator(
+ public ValueSetValidator(
IEnumerable includeItemTypes,
IEnumerable excludeItemTypes,
IEnumerable includeFields,
@@ -22,9 +22,10 @@ namespace Umbraco.Examine
ExcludeItemTypes = excludeItemTypes;
IncludeFields = includeFields;
ExcludeFields = excludeFields;
+ ValidIndexCategories = null;
}
- protected abstract IEnumerable ValidIndexCategories { get; }
+ protected virtual IEnumerable ValidIndexCategories { get; }
///
/// Optional inclusion list of content types to index
@@ -60,7 +61,7 @@ namespace Umbraco.Examine
public virtual bool Validate(ValueSet valueSet)
{
- if (!ValidIndexCategories.InvariantContains(valueSet.Category))
+ if (ValidIndexCategories != null && !ValidIndexCategories.InvariantContains(valueSet.Category))
return false;
//check if this document is of a correct type of node type alias
diff --git a/src/Umbraco.Tests/UmbracoExamine/UmbracoContentValueSetValidatorTests.cs b/src/Umbraco.Tests/UmbracoExamine/UmbracoContentValueSetValidatorTests.cs
index daac5f5778..0df4750051 100644
--- a/src/Umbraco.Tests/UmbracoExamine/UmbracoContentValueSetValidatorTests.cs
+++ b/src/Umbraco.Tests/UmbracoExamine/UmbracoContentValueSetValidatorTests.cs
@@ -61,12 +61,60 @@ namespace Umbraco.Tests.UmbracoExamine
}
[Test]
- public void Inclusion_List()
+ public void Inclusion_Field_List()
+ {
+ var validator = new ValueSetValidator(null, null,
+ new[] { "hello", "world" },
+ null);
+
+ var valueSet = new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
+ var result = validator.Validate(valueSet);
+ Assert.IsTrue(result);
+
+ Assert.IsFalse(valueSet.Values.ContainsKey("path"));
+ Assert.IsTrue(valueSet.Values.ContainsKey("hello"));
+ Assert.IsTrue(valueSet.Values.ContainsKey("world"));
+ }
+
+ [Test]
+ public void Exclusion_Field_List()
+ {
+ var validator = new ValueSetValidator(null, null,
+ null,
+ new[] { "hello", "world" });
+
+ var valueSet = new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
+ var result = validator.Validate(valueSet);
+ Assert.IsTrue(result);
+
+ Assert.IsTrue(valueSet.Values.ContainsKey("path"));
+ Assert.IsFalse(valueSet.Values.ContainsKey("hello"));
+ Assert.IsFalse(valueSet.Values.ContainsKey("world"));
+ }
+
+ [Test]
+ public void Inclusion_Exclusion_Field_List()
+ {
+ var validator = new ValueSetValidator(null, null,
+ new[] { "hello", "world" },
+ new[] { "world" });
+
+ var valueSet = new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555", world = "your oyster" });
+ var result = validator.Validate(valueSet);
+ Assert.IsTrue(result);
+
+ Assert.IsFalse(valueSet.Values.ContainsKey("path"));
+ Assert.IsTrue(valueSet.Values.ContainsKey("hello"));
+ Assert.IsFalse(valueSet.Values.ContainsKey("world"));
+ }
+
+ [Test]
+ public void Inclusion_Type_List()
{
var validator = new ContentValueSetValidator(true, true, Mock.Of(),
includeItemTypes: new List { "include-content" });
- var result = validator.Validate(new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
+ var result = validator.Validate(new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Assert.IsFalse(result);
result = validator.Validate(new ValueSet("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
@@ -77,7 +125,7 @@ namespace Umbraco.Tests.UmbracoExamine
}
[Test]
- public void Exclusion_List()
+ public void Exclusion_Type_List()
{
var validator = new ContentValueSetValidator(true, true, Mock.Of(),
excludeItemTypes: new List { "exclude-content" });
@@ -93,12 +141,12 @@ namespace Umbraco.Tests.UmbracoExamine
}
[Test]
- public void Inclusion_Exclusion_List()
+ public void Inclusion_Exclusion_Type_List()
{
var validator = new ContentValueSetValidator(true, true, Mock.Of(),
includeItemTypes: new List { "include-content", "exclude-content" },
excludeItemTypes: new List { "exclude-content" });
-
+
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Assert.IsFalse(result);
@@ -113,9 +161,9 @@ namespace Umbraco.Tests.UmbracoExamine
}
[Test]
- public void Recycle_Bin()
+ public void Recycle_Bin_Content()
{
- var validator = new ContentValueSetValidator(false, true, Mock.Of());
+ var validator = new ContentValueSetValidator(false, false, Mock.Of());
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555" }));
Assert.IsFalse(result);
@@ -136,6 +184,22 @@ namespace Umbraco.Tests.UmbracoExamine
Assert.IsTrue(result);
}
+ [Test]
+ public void Recycle_Bin_Media()
+ {
+ var validator = new ContentValueSetValidator(false, false, Mock.Of());
+
+ var result = validator.Validate(new ValueSet("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555" }));
+ Assert.IsFalse(result);
+
+ result = validator.Validate(new ValueSet("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555,777" }));
+ Assert.IsFalse(result);
+
+ result = validator.Validate(new ValueSet("555", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
+ Assert.IsTrue(result);
+
+ }
+
[Test]
public void Published_Only()
{
@@ -202,7 +266,7 @@ namespace Umbraco.Tests.UmbracoExamine
["title_es-ES"] = "my title",
[UmbracoExamineIndexer.PublishedFieldName] = 1
});
- Assert.AreEqual(10, valueSet.Values.Count());
+ Assert.AreEqual(10, valueSet.Values.Count());
Assert.IsTrue(valueSet.Values.ContainsKey($"{UmbracoExamineIndexer.PublishedFieldName}_es-es"));
Assert.IsTrue(valueSet.Values.ContainsKey("hello_es-ES"));
Assert.IsTrue(valueSet.Values.ContainsKey("title_es-ES"));