public void Aspect_ReferenceFields() { Test(() => { InstallCarContentType(); var testRoot = CreateTestRoot(); Aspect aspect1 = null; try { var fields1 = new List <FieldInfo>(); fields1.Add(new FieldInfo() { Name = "MyField1", Type = "ShortText", }); fields1.Add(new FieldInfo() { Name = "MyField2", Type = "Reference", }); aspect1 = EnsureAspect("Aspect_ReferenceFields_Aspect1"); aspect1.AddFields(fields1.ToArray()); aspect1.Save(); var fn11 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[0].Name; var fn12 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[1].Name; // ----------- var content1 = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString()); content1.AddAspects(aspect1); content1[fn11] = "Hello world this is a nice summer afternoon!"; content1.Save(); var content2 = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString()); content2.AddAspects(aspect1); content2[fn11] = "Hello world this is a cold winter morning!"; content2[fn12] = new List <Node> { content1.ContentHandler }; content2.Save(); // Test reference property value after reload content2 = Content.Load(content2.Id); IEnumerable <Node> references = (IEnumerable <Node>)content2[fn12]; Assert.IsTrue(references.Any()); Assert.IsTrue(references.Count() == 1); Assert.IsTrue(references.ElementAt(0).Id == content1.Id); // Test if the field can be queried with CQL var q = CreateSafeContentQuery(fn12 + ":" + content1.Id.ToString() + " .AUTOFILTERS:OFF"); IEnumerable <int> ids = q.Execute().Identifiers; Assert.IsTrue(ids.Any()); Assert.IsTrue(ids.Contains(content2.Id)); // ----------- content1.ForceDelete(); content2.ForceDelete(); } finally { aspect1.ForceDelete(); } }); }
public void Aspect_CustomIndexing() { Aspect aspect1 = null; try { var fields1 = new List <FieldInfo>(); fields1.Add(new FieldInfo() { Name = "MyField1", Type = "ShortText", Configuration = new ConfigurationInfo(), Indexing = new IndexingInfo() { Analyzer = "Lucene.Net.Analysis.SimpleAnalyzer" } }); fields1.Add(new FieldInfo() { Name = "MyField2", Type = "LongText", Configuration = new ConfigurationInfo(), Indexing = new IndexingInfo() { Analyzer = "Lucene.Net.Analysis.Standard.StandardAnalyzer" } }); fields1.Add(new FieldInfo() { Name = "MyField3", Type = "LongText", Configuration = new ConfigurationInfo(), Indexing = new IndexingInfo() { Mode = IndexingMode.No } }); aspect1 = EnsureAspect("Aspect_CustomIndexing_Aspect1"); aspect1.AddFields(fields1.ToArray()); aspect1.Save(); var fn11 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[0].Name; var fn12 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[1].Name; var fn13 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[2].Name; var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString()); content.AddAspects(aspect1); content[fn11] = "Hello world this is a nice summer afternoon!"; content[fn12] = "Yes it's really nice indeed!"; content[fn13] = "aaa bbb ccc"; content.Save(); var id1 = content.Id; var lq1 = Content.All.DisableAutofilters().Where(c => (string)c[fn11] == "Hello").AsEnumerable().Select(c => c.Id).ToArray(); var lq2 = Content.All.DisableAutofilters().Where(c => (string)c[fn12] == "really").AsEnumerable().Select(c => c.Id).ToArray(); var lq3 = Content.All.DisableAutofilters().Where(c => (string)c[fn13] == "aaa").AsEnumerable().Select(c => c.Id).ToArray(); var lq3_2 = Content.All.DisableAutofilters().Where(c => (string)c[fn13] == "aaa bbb ccc").AsEnumerable().Select(c => c.Id).ToArray(); Assert.IsTrue(lq1.Contains(id1), "LINQ query should find the content by the first aspect field"); Assert.IsTrue(lq2.Contains(id1), "LINQ query should find the content by the second aspect field"); Assert.IsFalse(lq3.Contains(id1), "LINQ query should NOT find the content by the third aspect field (which is not indexed)"); Assert.IsFalse(lq3_2.Contains(id1), "LINQ query should NOT find the content by the third aspect field (which is not indexed), not even with exact match"); var cq1 = ContentQuery.Query(fn11 + ":Hello .AUTOFILTERS:OFF").Identifiers.ToArray(); var cq2 = ContentQuery.Query(fn12 + ":really .AUTOFILTERS:OFF").Identifiers.ToArray(); Assert.IsTrue(cq1.Contains(id1), "Content query should find the content by the first aspect field"); Assert.IsTrue(cq2.Contains(id1), "Content query should find the content by the second aspect field"); content.ForceDelete(); } finally { aspect1.ForceDelete(); } }
public void Aspect_CreateAddFieldsRemoveFields() { Test(() => { InstallCarContentType(); var testRoot = CreateTestRoot(); Aspect aspect = null; try { var aspectContent = Content.CreateNew("Aspect", Repository.AspectsFolder, "Aspect42"); aspectContent.Save(); aspect = (Aspect)aspectContent.ContentHandler; var fieldName1 = String.Concat(aspect.Name, Aspect.ASPECTFIELDSEPARATOR, "Field1"); var fieldName2 = String.Concat(aspect.Name, Aspect.ASPECTFIELDSEPARATOR, "Field2"); var content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString()); content.AddAspects((Aspect)aspect); content.Save(); //var fs1 = new ShortTextFieldSetting { Name = "Field1", ShortName = "ShortText" }; //var fs2 = new ShortTextFieldSetting { Name = "Field2", ShortName = "ShortText" }; var fs1 = new FieldInfo { Name = "Field1", Type = "ShortText" }; var fs2 = new FieldInfo { Name = "Field2", Type = "ShortText" }; //----------------------------------------------------------------------------------------------------- Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#1"); Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#2"); aspect.AddFields(fs1); content = Content.Load(content.Id); Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#11"); Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#12"); aspect.AddFields(fs2); content = Content.Load(content.Id); Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#21"); Assert.IsTrue(content.Fields.ContainsKey(fieldName2), "#22"); aspect.RemoveFields(fieldName1); content = Content.Load(content.Id); Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#31"); Assert.IsTrue(content.Fields.ContainsKey(fieldName2), "#32"); aspect.RemoveFields(fieldName2); content = Content.Load(content.Id); Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#41"); Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#42"); aspect.AddFields(fs1, fs2); content = Content.Load(content.Id); Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#51"); Assert.IsTrue(content.Fields.ContainsKey(fieldName2), "#52"); aspect.RemoveFields(fieldName1, fieldName2); content = Content.Load(content.Id); Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#61"); Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#62"); } finally { aspect.ForceDelete(); } }); }
public void Aspect_ReferenceFields() { Aspect aspect1 = null; try { var fields1 = new List <FieldInfo>(); fields1.Add(new FieldInfo() { Name = "MyField1", Type = "ShortText", }); fields1.Add(new FieldInfo() { Name = "MyField2", Type = "Reference", }); aspect1 = EnsureAspect("Aspect_ReferenceFields_Aspect1"); aspect1.AddFields(fields1.ToArray()); aspect1.Save(); var fn11 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[0].Name; var fn12 = aspect1.Name + Aspect.ASPECTFIELDSEPARATOR + fields1[1].Name; // ----------- var content1 = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString()); content1.AddAspects(aspect1); content1[fn11] = "Hello world this is a nice summer afternoon!"; content1.Save(); var content2 = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString()); content2.AddAspects(aspect1); content2[fn11] = "Hello world this is a cold winter morning!"; content2[fn12] = new List <Node> { content1.ContentHandler }; content2.Save(); // Test reference property value after reload content2 = Content.Load(content2.Id); IEnumerable <Node> references = (IEnumerable <Node>)content2[fn12]; Assert.IsTrue(references.Any()); Assert.IsTrue(references.Count() == 1); Assert.IsTrue(references.ElementAt(0).Id == content1.Id); // Test if the field can be queried with CQL var q = ContentQuery.Query(fn12 + ":" + content1.Id.ToString(), new QuerySettings { EnableAutofilters = FilterStatus.Disabled }); IEnumerable <int> ids = q.Identifiers; Assert.IsTrue(ids.Any()); Assert.IsTrue(ids.Contains(content2.Id)); // TODO: uncomment when LINQ on reference fields is implemented //// Test if the field can be queried with LINQ // //var qq = Content.All.Where(c => (int)c[fn12] == content1.Id).ToList(); // //Assert.IsTrue(qq.Any()); //Assert.IsTrue(qq.Any(c => c.Id == content2.Id)); // ----------- content1.ForceDelete(); content2.ForceDelete(); } finally { aspect1.ForceDelete(); } }