Ejemplo n.º 1
0
        public void Aspect_HasFieldIfHasAspect()
        {
            Aspect aspect1 = null;
            Aspect aspect2 = null;

            try
            {
                aspect1 = EnsureAspect("Aspect_HasFieldIfHasAspect_Aspect1");
                aspect1.AspectDefinition = @"<AspectDefinition xmlns='http://schemas.com/ContentRepository/AspectDefinition'>
<Fields>
    <AspectField name='Field1' type='ShortText' />
  </Fields>
</AspectDefinition>";
                aspect1.Save();

                aspect2 = EnsureAspect("Aspect_HasFieldIfHasAspect_Aspect2");
                aspect2.AspectDefinition = @"<AspectDefinition xmlns='http://schemas.com/ContentRepository/AspectDefinition'>
<Fields>
    <AspectField name='Field2' type='ShortText' />
  </Fields>
</AspectDefinition>";
                aspect2.Save();

                var fieldName1 = String.Concat(aspect1.Name, Aspect.ASPECTFIELDSEPARATOR, "Field1");
                var fieldName2 = String.Concat(aspect2.Name, Aspect.ASPECTFIELDSEPARATOR, "Field2");

                var content = Content.CreateNew("Car", TestRoot, Guid.NewGuid().ToString());
                Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#1");
                Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#2");

                content.AddAspects(aspect1);
                Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#3");
                Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#4");

                content.RemoveAspects(aspect1);
                Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#5");
                Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#6");

                content.AddAspects(aspect1, aspect2);
                Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#7");
                Assert.IsTrue(content.Fields.ContainsKey(fieldName2), "#8");

                content.RemoveAspects(aspect2.Path);
                Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#9");
                Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#10");

                content.AddAspects(aspect2.Id);
                Assert.IsTrue(content.Fields.ContainsKey(fieldName1), "#11");
                Assert.IsTrue(content.Fields.ContainsKey(fieldName2), "#12");

                content.RemoveAllAspects();
                Assert.IsFalse(content.Fields.ContainsKey(fieldName1), "#13");
                Assert.IsFalse(content.Fields.ContainsKey(fieldName2), "#14");
            }
            finally
            {
                aspect1.ForceDelete();
                aspect2.ForceDelete();
            }
        }
Ejemplo n.º 2
0
        public void Aspect_UniqueName_02()
        {
            var aspectName = Guid.NewGuid().ToString();
            var aspect1    = new Aspect(Repository.AspectsFolder)
            {
                Name = aspectName
            };

            aspect1.Save();

            Assert.AreEqual(aspect1.Id, Aspect.LoadAspectByName(aspectName).Id, "#1 load newly created aspect by name failed: a different aspect was loaded.");

            //delete aspect to make its name available
            aspect1.ForceDelete();

            //create aspect with the same name
            var aspect2 = new Aspect(Repository.AspectsFolder)
            {
                Name = aspectName
            };

            aspect2.Save();
        }
Ejemplo n.º 3
0
        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();
                }
            });
        }
Ejemplo n.º 4
0
        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();
                }
            });
        }
Ejemplo n.º 5
0
        public void Aspect_Sortable()
        {
            Test(() =>
            {
                InstallCarContentType();
                var testRoot = CreateTestRoot();

                Aspect aspect1 = null;
                try
                {
                    aspect1 = EnsureAspect("Aspect_Sortable_Aspect1");
                    aspect1.AspectDefinition = @"<AspectDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/AspectDefinition'>
<Fields>
    <AspectField name='Field1' type='ShortText' />
  </Fields>
</AspectDefinition>";
                    aspect1.Save();

                    var fieldName1 = String.Concat(aspect1.Name, Aspect.ASPECTFIELDSEPARATOR, "Field1");

                    var content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString());
                    content.AddAspects(aspect1);
                    content[fieldName1] = "Aspect_Sortable1b";
                    content.Save();
                    var id1 = content.Id;

                    content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString());
                    content.AddAspects(aspect1);
                    content[fieldName1] = "Aspect_Sortable1c";
                    content.Save();
                    var id2 = content.Id;

                    content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString());
                    content.AddAspects(aspect1);
                    content[fieldName1] = "Aspect_Sortable1a";
                    content.Save();
                    var id3 = content.Id;

                    ContentTypeManager.Reset(); //---- must work with loaded indexing info table
                    content = Content.Load(content.Id);

                    var r0 = Content.All.DisableAutofilters().Where(c => c.InTree(testRoot) && ((string)c[fieldName1]).StartsWith("Aspect_Sortable1")).ToArray().Select(x => x.Id);
                    var r1 = Content.All.DisableAutofilters().Where(c => c.InTree(testRoot) && ((string)c[fieldName1]).StartsWith("Aspect_Sortable1")).OrderBy(c => c[fieldName1]).ToArray().Select(x => x.Id);
                    var r2 = Content.All.DisableAutofilters().Where(c => c.InTree(testRoot) && ((string)c[fieldName1]).StartsWith("Aspect_Sortable1")).OrderByDescending(c => c[fieldName1]).ToArray().Select(x => x.Id);
                    var r3 = CreateSafeContentQuery($"+InTree:'{testRoot.Path}' +{fieldName1}:Aspect_Sortable1* .AUTOFILTERS:OFF .SORT:{fieldName1}").Execute().Identifiers;
                    var r4 = CreateSafeContentQuery($"+InTree:'{testRoot.Path}' +{fieldName1}:Aspect_Sortable1* .AUTOFILTERS:OFF .REVERSESORT:{fieldName1}").Execute().Identifiers;

                    var expected1 = String.Join(",", new[] { id3, id1, id2 });
                    var expected2 = String.Join(",", new[] { id2, id1, id3 });
                    var result0   = String.Join(",", r0);
                    var result1   = String.Join(",", r1);
                    var result2   = String.Join(",", r2);
                    var result3   = String.Join(",", r3);
                    var result4   = String.Join(",", r4);

                    //Assert.AreEqual(expected1, result1);
                    //Assert.AreEqual(expected2, result2);
                    Assert.AreEqual(expected1, result3);
                    Assert.AreEqual(expected2, result4);
                }
                finally
                {
                    aspect1.ForceDelete();
                }
            });
        }
Ejemplo n.º 6
0
        public void Aspect_Searchable()
        {
            Test(() =>
            {
                InstallCarContentType();
                var testRoot = CreateTestRoot();

                Aspect aspect1 = null;
                Aspect aspect2 = null;
                try
                {
                    aspect1 = EnsureAspect("Aspect1");
                    aspect1.AspectDefinition = @"<AspectDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/AspectDefinition'>
<Fields>
    <AspectField name='Field1' type='ShortText' />
  </Fields>
</AspectDefinition>";
                    aspect1.Save();

                    aspect2 = EnsureAspect("Aspect2");
                    aspect2.AspectDefinition = @"<AspectDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/AspectDefinition'>
<Fields>
    <AspectField name='Field2' type='ShortText' />
  </Fields>
</AspectDefinition>";
                    aspect2.Save();

                    var fieldName1 = String.Concat(aspect1.Name, Aspect.ASPECTFIELDSEPARATOR, "Field1");
                    var fieldName2 = String.Concat(aspect2.Name, Aspect.ASPECTFIELDSEPARATOR, "Field2");

                    var content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString());
                    content.AddAspects(aspect1, aspect2);
                    content[fieldName1] = "Value1";
                    content[fieldName2] = "Value2";
                    content.Save();
                    var id1 = content.Id;

                    content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString());
                    content.AddAspects(aspect1, aspect2);
                    content[fieldName1] = "Value1a";
                    content[fieldName2] = "Value2";
                    content.Save();
                    var id2 = content.Id;

                    content = Content.CreateNew("Car", testRoot, Guid.NewGuid().ToString());
                    content.AddAspects(aspect1);
                    content[fieldName1] = "Value1";
                    content.Save();
                    var id3 = content.Id;

                    ContentTypeManager.Reset(); //---- must work with loaded indexing info table
                    content = Content.Load(content.Id);

                    var r1 = Content.All.DisableAutofilters().Where(c => (string)c[fieldName1] == "Value1").ToArray().Select(x => x.Id);
                    var r2 = Content.All.DisableAutofilters().Where(c => (string)c[fieldName2] == "Value2").ToArray().Select(x => x.Id);
                    var r3 = CreateSafeContentQuery(fieldName1 + ":Value1 .AUTOFILTERS:OFF").Execute().Identifiers;
                    var r4 = CreateSafeContentQuery(fieldName2 + ":Value2 .AUTOFILTERS:OFF").Execute().Identifiers;

                    var expected1 = String.Join(",", new[] { id1, id3 });
                    var expected2 = String.Join(",", new[] { id1, id2 });
                    var result1   = String.Join(",", r1);
                    var result2   = String.Join(",", r2);
                    var result3   = String.Join(",", r3);
                    var result4   = String.Join(",", r4);

                    Assert.AreEqual(expected1, result1);
                    Assert.AreEqual(expected2, result2);
                    Assert.AreEqual(expected1, result3);
                    Assert.AreEqual(expected2, result4);
                }
                finally
                {
                    aspect1.ForceDelete();
                    aspect2.ForceDelete();
                }
            });
        }
Ejemplo n.º 7
0
        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();
            }
        }
Ejemplo n.º 8
0
        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();
            }
        }