public void Inclusion_Exclusion_Type_List() { var validator = new ContentValueSetValidator( false, true, Mock.Of <IPublicAccessService>(), Mock.Of <IScopeProvider>(), includeItemTypes: new List <string> { "include-content", "exclude-content" }, 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.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); }
public void Published_Only() { 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); }
public void Recycle_Bin_Content() { var validator = new ContentValueSetValidator( true, false, Mock.Of <IPublicAccessService>(), Mock.Of <IScopeProvider>()); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555" })); Assert.AreEqual(ValueSetValidationResult.Failed, result); result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555,777" })); Assert.AreEqual(ValueSetValidationResult.Failed, result); result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" })); Assert.AreEqual(ValueSetValidationResult.Failed, result); result = validator.Validate(new ValueSet("555", IndexTypes.Content, new Dictionary <string, object> { ["hello"] = "world", ["path"] = "-1,555", [UmbracoExamineIndex.PublishedFieldName] = "y" })); Assert.AreEqual(ValueSetValidationResult.Valid, result); }
public static UmbracoContentIndex GetUmbracoIndexer( IProfilingLogger profilingLogger, Directory luceneDir, Analyzer analyzer = null, ILocalizationService languageService = null, IContentValueSetValidator validator = null) { if (languageService == null) { languageService = GetMockLocalizationService(); } if (analyzer == null) { analyzer = new StandardAnalyzer(Version.LUCENE_30); } if (validator == null) { validator = new ContentValueSetValidator(true); } var i = new UmbracoContentIndex( "testIndexer", luceneDir, new UmbracoFieldDefinitionCollection(), analyzer, profilingLogger, languageService, validator); i.IndexingError += IndexingError; return(i); }
public void Parent_Id() { var validator = new ContentValueSetValidator( false, true, Mock.Of <IPublicAccessService>(), Mock.Of <IScopeProvider>(), 555); var 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); }
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>()); var validator = new ContentValueSetValidator( false, false, publicAccessService.Object, Mock.Of <IScopeProvider>()); var 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); }
public void Recycle_Bin_Media() { var validator = new ContentValueSetValidator( true, false, Mock.Of <IPublicAccessService>(), Mock.Of <IScopeProvider>()); var result = validator.Validate(ValueSet.FromObject( "555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555" })); Assert.AreEqual(ValueSetValidationStatus.Filtered, result.Status); 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); }
public void Published_Only_With_Variants() { var validator = new ContentValueSetValidator(true, true, Mock.Of <IPublicAccessService>(), Mock.Of <IScopeProvider>()); var result = validator.Validate(new ValueSet("555", IndexTypes.Content, new Dictionary <string, object> { ["hello"] = "world", ["path"] = "-1,555", [UmbracoContentIndex.VariesByCultureFieldName] = "y", [UmbracoExamineIndex.PublishedFieldName] = "n" })); Assert.AreEqual(ValueSetValidationResult.Failed, result); result = validator.Validate(new ValueSet("555", IndexTypes.Content, new Dictionary <string, object> { ["hello"] = "world", ["path"] = "-1,555", [UmbracoContentIndex.VariesByCultureFieldName] = "y", [UmbracoExamineIndex.PublishedFieldName] = "y" })); Assert.AreEqual(ValueSetValidationResult.Valid, result); var valueSet = new ValueSet("555", IndexTypes.Content, new Dictionary <string, object> { ["hello"] = "world", ["path"] = "-1,555", [UmbracoContentIndex.VariesByCultureFieldName] = "y", [$"{UmbracoExamineIndex.PublishedFieldName}_en-us"] = "y", ["hello_en-us"] = "world", ["title_en-us"] = "my title", [$"{UmbracoExamineIndex.PublishedFieldName}_es-es"] = "n", ["hello_es-ES"] = "world", ["title_es-ES"] = "my title", [UmbracoExamineIndex.PublishedFieldName] = "y" }); Assert.AreEqual(10, valueSet.Values.Count()); Assert.IsTrue(valueSet.Values.ContainsKey($"{UmbracoExamineIndex.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(ValueSetValidationResult.Filtered, result); Assert.AreEqual(7, valueSet.Values.Count()); //filtered to 7 values (removes es-es values) Assert.IsFalse(valueSet.Values.ContainsKey($"{UmbracoExamineIndex.PublishedFieldName}_es-es")); Assert.IsFalse(valueSet.Values.ContainsKey("hello_es-ES")); Assert.IsFalse(valueSet.Values.ContainsKey("title_es-ES")); }
public void Must_Have_Path() { var validator = new ContentValueSetValidator(false, true, Mock.Of <IPublicAccessService>()); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world" })); Assert.AreEqual(ValueSetValidationResult.Failed, result); result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" })); Assert.AreEqual(ValueSetValidationResult.Valid, result); }
public void Invalid_Category() { var validator = new ContentValueSetValidator(false, true, Mock.Of <IPublicAccessService>()); var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" })); Assert.AreEqual(ValueSetValidationResult.Valid, result); result = validator.Validate(ValueSet.FromObject("777", IndexTypes.Media, new { hello = "world", path = "-1,555" })); Assert.AreEqual(ValueSetValidationResult.Valid, result); result = validator.Validate(ValueSet.FromObject("555", "invalid-category", new { hello = "world", path = "-1,555" })); Assert.AreEqual(ValueSetValidationResult.Failed, result); }
public UmbracoContentIndex GetUmbracoIndexer( IHostingEnvironment hostingEnvironment, IRuntimeState runtimeState, Directory luceneDir, Analyzer analyzer = null, ILocalizationService languageService = null, IContentValueSetValidator validator = null) { if (languageService == null) { languageService = GetMockLocalizationService(); } if (analyzer == null) { analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion); } if (validator == null) { validator = new ContentValueSetValidator(true); } var options = GetOptions( "testIndexer", new LuceneDirectoryIndexOptions { Analyzer = analyzer, Validator = validator, DirectoryFactory = new GenericDirectoryFactory(s => luceneDir), FieldDefinitions = new UmbracoFieldDefinitionCollection() }); var i = new UmbracoContentIndex( _loggerFactory, "testIndexer", options, hostingEnvironment, runtimeState, languageService); i.IndexingError += IndexingError; i.IndexOperationComplete += I_IndexOperationComplete; return(i); }
public void Index_Move_Media_From_Non_Indexable_To_Indexable_ParentID() { // create a validator with // publishedValuesOnly false // parentId 1116 (only content under that parent will be indexed) var validator = new ContentValueSetValidator(false, 1116); using (var luceneDir = new RandomIdRamDirectory()) using (var indexer = IndexInitializer.GetUmbracoIndexer(ProfilingLogger, luceneDir, validator: validator)) using (indexer.ProcessNonAsync()) { var searcher = indexer.GetSearcher(); //get a node from the data repo (this one exists underneath 2222) var node = _mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]") .Root.Elements() .First(x => (int)x.Attribute("id") == 2112); var currPath = (string)node.Attribute("path"); //should be : -1,1111,2222,2112 Assert.AreEqual("-1,1111,2222,2112", currPath); //ensure it's indexed indexer.IndexItem(node.ConvertToValueSet(IndexTypes.Media)); //it will not exist because it exists under 2222 var results = searcher.CreateQuery().Id(2112).Execute(); Assert.AreEqual(0, results.Count()); //now mimic moving 2112 to 1116 //node.SetAttributeValue("path", currPath.Replace("2222", "1116")); node.SetAttributeValue("path", "-1,1116,2112"); node.SetAttributeValue("parentID", "1116"); //now reindex the node, this should first delete it and then WILL add it because of the parent id constraint indexer.IndexItems(new[] { node.ConvertToValueSet(IndexTypes.Media) }); //now ensure it exists results = searcher.CreateQuery().Id(2112).Execute(); Assert.AreEqual(1, results.Count()); } }
/// <summary> /// Used to create and manage a testable index /// </summary> /// <param name="publishedValuesOnly"></param> /// <param name="index"></param> /// <param name="contentRebuilder"></param> /// <param name="contentValueSetBuilder"></param> /// <param name="parentId"></param> /// <returns></returns> protected IDisposable GetSynchronousContentIndex( bool publishedValuesOnly, out UmbracoContentIndex index, out ContentIndexPopulator contentRebuilder, out ContentValueSetBuilder contentValueSetBuilder, int?parentId = null, IContentService contentService = null) { contentValueSetBuilder = IndexInitializer.GetContentValueSetBuilder(publishedValuesOnly); ISqlContext sqlContext = Mock.Of <ISqlContext>(x => x.Query <IContent>() == Mock.Of <IQuery <IContent> >()); IUmbracoDatabaseFactory dbFactory = Mock.Of <IUmbracoDatabaseFactory>(x => x.SqlContext == sqlContext); if (contentService == null) { contentService = IndexInitializer.GetMockContentService(); } contentRebuilder = IndexInitializer.GetContentIndexRebuilder(contentService, publishedValuesOnly, dbFactory); var luceneDir = new RandomIdRAMDirectory(); ContentValueSetValidator validator; // if only published values then we'll change the validator for tests to // ensure we don't support protected nodes and that we // mock the public access service for the special protected node. if (publishedValuesOnly) { var publicAccessServiceMock = new Mock <IPublicAccessService>(); publicAccessServiceMock.Setup(x => x.IsProtected(It.IsAny <string>())) .Returns((string path) => { if (path.EndsWith("," + ExamineDemoDataContentService.ProtectedNode)) { return(Attempt <PublicAccessEntry> .Succeed()); } return(Attempt <PublicAccessEntry> .Fail()); }); var scopeProviderMock = new Mock <IScopeProvider>(); scopeProviderMock.Setup(x => x.CreateScope( It.IsAny <IsolationLevel>(), It.IsAny <RepositoryCacheMode>(), It.IsAny <IEventDispatcher>(), It.IsAny <IScopedNotificationPublisher>(), It.IsAny <bool?>(), It.IsAny <bool>(), It.IsAny <bool>())) .Returns(Mock.Of <IScope>); validator = new ContentValueSetValidator( publishedValuesOnly, false, publicAccessServiceMock.Object, scopeProviderMock.Object, parentId); } else { validator = new ContentValueSetValidator(publishedValuesOnly, parentId); } index = IndexInitializer.GetUmbracoIndexer( HostingEnvironment, RunningRuntimeState, luceneDir, validator: validator); IDisposable syncMode = index.WithThreadingMode(IndexThreadingMode.Synchronous); return(new DisposableWrapper(syncMode, index, luceneDir)); }