Fixed failing test
This commit is contained in:
@@ -4,9 +4,9 @@ using System.Linq;
|
||||
using Examine;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
@@ -17,12 +17,14 @@ namespace Umbraco.Examine
|
||||
public class ContentIndexPopulator : IndexPopulator<IUmbracoContentIndex>
|
||||
{
|
||||
private readonly IContentService _contentService;
|
||||
private readonly IUmbracoDatabaseFactory _umbracoDatabaseFactory;
|
||||
private readonly IValueSetBuilder<IContent> _contentValueSetBuilder;
|
||||
|
||||
/// <summary>
|
||||
/// This is a static query, it's parameters don't change so store statically
|
||||
/// </summary>
|
||||
private static IQuery<IContent> _publishedQuery;
|
||||
private IQuery<IContent> _publishedQuery;
|
||||
private IQuery<IContent> PublishedQuery => _publishedQuery ??= _umbracoDatabaseFactory.SqlContext.Query<IContent>().Where(x => x.Published);
|
||||
|
||||
private readonly bool _publishedValuesOnly;
|
||||
private readonly int? _parentId;
|
||||
@@ -33,26 +35,20 @@ namespace Umbraco.Examine
|
||||
/// <param name="contentService"></param>
|
||||
/// <param name="sqlContext"></param>
|
||||
/// <param name="contentValueSetBuilder"></param>
|
||||
public ContentIndexPopulator(IContentService contentService, ISqlContext sqlContext, IContentValueSetBuilder contentValueSetBuilder)
|
||||
: this(false, null, contentService, sqlContext, contentValueSetBuilder)
|
||||
public ContentIndexPopulator(IContentService contentService, IUmbracoDatabaseFactory umbracoDatabaseFactory, IContentValueSetBuilder contentValueSetBuilder)
|
||||
: this(false, null, contentService, umbracoDatabaseFactory, contentValueSetBuilder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional constructor allowing specifying custom query parameters
|
||||
/// </summary>
|
||||
/// <param name="publishedValuesOnly"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <param name="contentService"></param>
|
||||
/// <param name="sqlContext"></param>
|
||||
/// <param name="contentValueSetBuilder"></param>
|
||||
public ContentIndexPopulator(bool publishedValuesOnly, int? parentId, IContentService contentService, ISqlContext sqlContext, IValueSetBuilder<IContent> contentValueSetBuilder)
|
||||
public ContentIndexPopulator(bool publishedValuesOnly, int? parentId, IContentService contentService, IUmbracoDatabaseFactory umbracoDatabaseFactory, IValueSetBuilder<IContent> contentValueSetBuilder)
|
||||
{
|
||||
if (sqlContext == null) throw new ArgumentNullException(nameof(sqlContext));
|
||||
if (umbracoDatabaseFactory == null) throw new ArgumentNullException(nameof(umbracoDatabaseFactory));
|
||||
_contentService = contentService ?? throw new ArgumentNullException(nameof(contentService));
|
||||
_umbracoDatabaseFactory = umbracoDatabaseFactory;
|
||||
_contentValueSetBuilder = contentValueSetBuilder ?? throw new ArgumentNullException(nameof(contentValueSetBuilder));
|
||||
if (_publishedQuery == null)
|
||||
_publishedQuery = sqlContext.Query<IContent>().Where(x => x.Published);
|
||||
_publishedValuesOnly = publishedValuesOnly;
|
||||
_parentId = parentId;
|
||||
}
|
||||
@@ -120,10 +116,10 @@ namespace Umbraco.Examine
|
||||
{
|
||||
//add the published filter
|
||||
//note: We will filter for published variants in the validator
|
||||
content = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out _, _publishedQuery,
|
||||
content = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out _, PublishedQuery,
|
||||
Ordering.By("Path", Direction.Ascending)).ToArray();
|
||||
|
||||
|
||||
|
||||
if (content.Length > 0)
|
||||
{
|
||||
var indexableContent = new List<IContent>();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Persistence;
|
||||
|
||||
namespace Umbraco.Examine
|
||||
{
|
||||
@@ -14,9 +13,9 @@ namespace Umbraco.Examine
|
||||
/// </remarks>
|
||||
public class PublishedContentIndexPopulator : ContentIndexPopulator
|
||||
{
|
||||
public PublishedContentIndexPopulator(IContentService contentService, ISqlContext sqlContext, IPublishedContentValueSetBuilder contentValueSetBuilder) :
|
||||
base(true, null, contentService, sqlContext, contentValueSetBuilder)
|
||||
{
|
||||
public PublishedContentIndexPopulator(IContentService contentService, IUmbracoDatabaseFactory umbracoDatabaseFactory, IPublishedContentValueSetBuilder contentValueSetBuilder) :
|
||||
base(true, null, contentService, umbracoDatabaseFactory, contentValueSetBuilder)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
protected IVariationContextAccessor VariationContextAccessor => new TestVariationContextAccessor();
|
||||
|
||||
internal ScopeProvider ScopeProvider => Current.ScopeProvider as ScopeProvider;
|
||||
internal IUmbracoDatabaseFactory UmbracoDatabaseFactory => Factory.GetRequiredService<IUmbracoDatabaseFactory>();
|
||||
|
||||
protected ISqlContext SqlContext => Factory.GetRequiredService<ISqlContext>();
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Examine;
|
||||
using Examine.LuceneEngine.Providers;
|
||||
using Lucene.Net.Analysis;
|
||||
using Lucene.Net.Analysis.Standard;
|
||||
using Lucene.Net.Store;
|
||||
@@ -10,12 +9,10 @@ using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Hosting;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Scoping;
|
||||
@@ -23,8 +20,6 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using IContentService = Umbraco.Core.Services.IContentService;
|
||||
using IMediaService = Umbraco.Core.Services.IMediaService;
|
||||
using Version = Lucene.Net.Util.Version;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
@@ -47,10 +42,10 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
return contentValueSetBuilder;
|
||||
}
|
||||
|
||||
public static ContentIndexPopulator GetContentIndexRebuilder(PropertyEditorCollection propertyEditors, IContentService contentService, IScopeProvider scopeProvider, bool publishedValuesOnly)
|
||||
public static ContentIndexPopulator GetContentIndexRebuilder(PropertyEditorCollection propertyEditors, IContentService contentService, IScopeProvider scopeProvider, IUmbracoDatabaseFactory umbracoDatabaseFactory, bool publishedValuesOnly)
|
||||
{
|
||||
var contentValueSetBuilder = GetContentValueSetBuilder(propertyEditors, scopeProvider, publishedValuesOnly);
|
||||
var contentIndexDataSource = new ContentIndexPopulator(publishedValuesOnly, null, contentService, scopeProvider.SqlContext, contentValueSetBuilder);
|
||||
var contentIndexDataSource = new ContentIndexPopulator(publishedValuesOnly, null, contentService, umbracoDatabaseFactory, contentValueSetBuilder);
|
||||
return contentIndexDataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Examine;
|
||||
using Examine.LuceneEngine.Providers;
|
||||
using Lucene.Net.Index;
|
||||
using Lucene.Net.Search;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Core.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Umbraco.Core;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
@@ -123,7 +121,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Rebuild_Index()
|
||||
{
|
||||
var contentRebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
var contentRebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, UmbracoDatabaseFactory,false);
|
||||
var mediaRebuilder = IndexInitializer.GetMediaIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockMediaService());
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
@@ -151,7 +149,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Index_Protected_Content_Not_Indexed()
|
||||
{
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, UmbracoDatabaseFactory,false);
|
||||
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
@@ -276,7 +274,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
[Test]
|
||||
public void Index_Reindex_Content()
|
||||
{
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, UmbracoDatabaseFactory,false);
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, HostingEnvironment, RuntimeState, luceneDir,
|
||||
validator: new ContentValueSetValidator(false)))
|
||||
@@ -317,7 +315,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
public void Index_Delete_Index_Item_Ensure_Heirarchy_Removed()
|
||||
{
|
||||
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, false);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(Factory.GetRequiredService<PropertyEditorCollection>(), IndexInitializer.GetMockContentService(), ScopeProvider, UmbracoDatabaseFactory,false);
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, HostingEnvironment, RuntimeState, luceneDir))
|
||||
|
||||
@@ -4,16 +4,14 @@ using System.Linq;
|
||||
using Examine;
|
||||
using Examine.Search;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Examine;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
@@ -56,7 +54,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
allRecs);
|
||||
|
||||
var propertyEditors = Factory.GetRequiredService<PropertyEditorCollection>();
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(propertyEditors, contentService, ScopeProvider, true);
|
||||
var rebuilder = IndexInitializer.GetContentIndexRebuilder(propertyEditors, contentService, ScopeProvider, UmbracoDatabaseFactory,true);
|
||||
|
||||
using (var luceneDir = new RandomIdRamDirectory())
|
||||
using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, HostingEnvironment, RuntimeState, luceneDir))
|
||||
|
||||
Reference in New Issue
Block a user