Fixes tests, adds test, renames class
This commit is contained in:
@@ -11,16 +11,17 @@ namespace Umbraco.Examine
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Used to validate a ValueSet for content - based on permissions, parent id, etc....
|
||||
/// Used to validate a ValueSet for content/media - based on permissions, parent id, etc....
|
||||
/// </summary>
|
||||
public class UmbracoContentValueSetValidator : IValueSetValidator
|
||||
public class ContentValueSetValidator : IValueSetValidator
|
||||
{
|
||||
private readonly UmbracoContentIndexerOptions _options;
|
||||
private readonly IPublicAccessService _publicAccessService;
|
||||
|
||||
private const string PathKey = "path";
|
||||
private static readonly IEnumerable<string> ValidIndexTypes = new[] {IndexTypes.Content, IndexTypes.Media};
|
||||
|
||||
public UmbracoContentValueSetValidator(UmbracoContentIndexerOptions options, IPublicAccessService publicAccessService)
|
||||
public ContentValueSetValidator(UmbracoContentIndexerOptions options, IPublicAccessService publicAccessService)
|
||||
{
|
||||
_options = options;
|
||||
_publicAccessService = publicAccessService;
|
||||
@@ -28,6 +29,9 @@ namespace Umbraco.Examine
|
||||
|
||||
public bool Validate(ValueSet valueSet)
|
||||
{
|
||||
if (!ValidIndexTypes.Contains(valueSet.Category))
|
||||
return false;
|
||||
|
||||
//check for published content
|
||||
if (valueSet.Category == IndexTypes.Content && !_options.SupportUnpublishedContent)
|
||||
{
|
||||
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Lucene.Net.Store;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
/// <summary>
|
||||
/// The index types stored in the Lucene Index
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UmbracoContentIndexer.cs" />
|
||||
<Compile Include="UmbracoContentIndexerOptions.cs" />
|
||||
<Compile Include="UmbracoContentValueSetValidator.cs" />
|
||||
<Compile Include="ContentValueSetValidator.cs" />
|
||||
<Compile Include="UmbracoExamineIndexer.cs" />
|
||||
<Compile Include="UmbracoExamineSearcher.cs" />
|
||||
<Compile Include="UmbracoMemberIndexer.cs" />
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Umbraco.Examine
|
||||
parentId = indexSet.IndexParentId;
|
||||
}
|
||||
|
||||
ValueSetValidator = new UmbracoContentValueSetValidator(
|
||||
ValueSetValidator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(
|
||||
SupportUnpublishedContent, SupportProtectedContent, parentId,
|
||||
ConfigIndexCriteria.IncludeItemTypes, ConfigIndexCriteria.ExcludeItemTypes),
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
analyzer,
|
||||
profilingLogger,
|
||||
languageService,
|
||||
new UmbracoContentValueSetValidator(options, Mock.Of<IPublicAccessService>()),
|
||||
new ContentValueSetValidator(options, Mock.Of<IPublicAccessService>()),
|
||||
options);
|
||||
|
||||
i.IndexingError += IndexingError;
|
||||
|
||||
@@ -130,6 +130,9 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
options: new UmbracoContentIndexerOptions(true, false, null)))
|
||||
using (indexer.ProcessNonAsync())
|
||||
{
|
||||
contentRebuilder.RegisterIndex(indexer.Name);
|
||||
mediaRebuilder.RegisterIndex(indexer.Name);
|
||||
|
||||
var searcher = indexer.GetSearcher();
|
||||
|
||||
//create the whole thing
|
||||
@@ -278,12 +281,13 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
public void Index_Reindex_Content()
|
||||
{
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Container.GetInstance<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider.SqlContext);
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir,
|
||||
options: new UmbracoContentIndexerOptions(true, false, null)))
|
||||
using (indexer.ProcessNonAsync())
|
||||
{
|
||||
rebuilder.RegisterIndex(indexer.Name);
|
||||
|
||||
var searcher = indexer.GetSearcher();
|
||||
|
||||
//create the whole thing
|
||||
|
||||
@@ -62,6 +62,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir))
|
||||
using (indexer.ProcessNonAsync())
|
||||
{
|
||||
rebuilder.RegisterIndex(indexer.Name);
|
||||
indexer.CreateIndex();
|
||||
rebuilder.Populate(indexer);
|
||||
|
||||
|
||||
@@ -14,10 +14,28 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[TestFixture]
|
||||
public class UmbracoContentValueSetValidatorTests
|
||||
{
|
||||
[Test]
|
||||
public void Invalid_Category()
|
||||
{
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, true, null),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
var result = validator.Validate(new ValueSet("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
|
||||
Assert.IsTrue(result);
|
||||
|
||||
result = validator.Validate(new ValueSet("777", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
|
||||
Assert.IsTrue(result);
|
||||
|
||||
result = validator.Validate(new ValueSet("555", "invalid-category", new { hello = "world", path = "-1,555" }));
|
||||
Assert.IsFalse(result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Must_Have_Path()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, true, null),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -31,7 +49,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Parent_Id()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, true, 555),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -51,7 +69,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Inclusion_List()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, true, includeContentTypes: new List<string> { "include-content" }),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -68,7 +86,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Exclusion_List()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, true, excludeContentTypes: new List<string> { "exclude-content" }),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -85,7 +103,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Inclusion_Exclusion_List()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, true,
|
||||
includeContentTypes: new List<string> { "include-content", "exclude-content" },
|
||||
excludeContentTypes: new List<string> { "exclude-content" }),
|
||||
@@ -107,7 +125,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Recycle_Bin()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(false, true, null),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -133,7 +151,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Published_Only()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(false, true, null),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -162,7 +180,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Published_Only_With_Variants()
|
||||
{
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(false, true, null),
|
||||
Mock.Of<IPublicAccessService>());
|
||||
|
||||
@@ -222,7 +240,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
.Returns(Attempt.Succeed(new PublicAccessEntry(Guid.NewGuid(), 555, 444, 333, Enumerable.Empty<PublicAccessRule>())));
|
||||
publicAccessService.Setup(x => x.IsProtected("-1,777"))
|
||||
.Returns(Attempt.Fail<PublicAccessEntry>());
|
||||
var validator = new UmbracoContentValueSetValidator(
|
||||
var validator = new ContentValueSetValidator(
|
||||
new UmbracoContentIndexerOptions(true, false, null),
|
||||
publicAccessService.Object);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Web.Search
|
||||
|
||||
public virtual IValueSetValidator GetContentValueSetValidator(UmbracoContentIndexerOptions options)
|
||||
{
|
||||
return new UmbracoContentValueSetValidator(options, PublicAccessService);
|
||||
return new ContentValueSetValidator(options, PublicAccessService);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user