private NodeType CreateNodeType(SchemaEditor editor, NodeType parent, string name, string className, int id)
        {
            NodeType nt = editor.CreateNodeType(parent, name, className);

            SetSchemaItemId(nt, id);
            return(nt);
        }
        public void SqlSchemaWriter_RemovePropertyTypeFromNodeType_Text()
        {
            SchemaEditor ed = new SchemaEditor();
            NodeType     nt = CreateNodeType(ed, null, "NT0", "NT0Class", 1);
            PropertyType pt = CreatePropertyType(ed, "PT0", DataType.Text, 2);

            ed.AddPropertyTypeToPropertySet(pt, nt);

            var writer = SqlSchemaWriterAccessor.Create();

            writer.Open();
            writer.RemovePropertyTypeFromPropertySet(pt, nt);

            string expectedSql = @"-- Reset property value: NT0.PT0:Text
DELETE FROM dbo.TextPropertiesNVarchar WHERE TextPropertyNVarcharId IN (SELECT dbo.TextPropertiesNVarchar.TextPropertyNVarcharId FROM dbo.Nodes
	INNER JOIN dbo.Versions ON dbo.Versions.NodeId = dbo.Nodes.NodeId
	INNER JOIN dbo.TextPropertiesNVarchar ON dbo.Versions.VersionId = dbo.TextPropertiesNVarchar.VersionId
WHERE (dbo.Nodes.NodeTypeId = 1) AND (dbo.TextPropertiesNVarchar.PropertyTypeId = 2))
-- Reset property value: NT0.PT0:Text
DELETE FROM dbo.TextPropertiesNText WHERE TextPropertyNTextId IN (SELECT dbo.TextPropertiesNText.TextPropertyNTextId FROM dbo.Nodes
	INNER JOIN dbo.Versions ON dbo.Versions.NodeId = dbo.Nodes.NodeId
	INNER JOIN dbo.TextPropertiesNText ON dbo.Versions.VersionId = dbo.TextPropertiesNText.VersionId
WHERE (dbo.Nodes.NodeTypeId = 1) AND (dbo.TextPropertiesNText.PropertyTypeId = 2))
-- Remove PropertyType 'PT0' from PropertySet 'NT0'
DELETE FROM [dbo].[SchemaPropertySetsPropertyTypes] WHERE PropertyTypeId = 2 AND PropertySetId = 1
GO
";

            string sql = writer.GetSqlScript();

            Assert.IsTrue(ScriptsAreEqual(sql, expectedSql));
        }
        public void SqlSchemaWriter_CreateNodeType_More()
        {
            SchemaEditor ed = new SchemaEditor();
            NodeType     nt = CreateNodeType(ed, null, "NT0", "NT0Class", 1);

            var writer = SqlSchemaWriterAccessor.Create();

            writer.Open();
            writer.CreateNodeType(nt, "NT1", "NT1Class");
            writer.CreateNodeType(nt, "NT2", "NT2Class");

            string expectedSql = @"
						-- Create NodeType NT0/NT1
						DECLARE @parentId int
						SELECT @parentId = [PropertySetId] FROM [dbo].[SchemaPropertySets] WHERE [Name] = 'NT0'
						INSERT INTO [dbo].[SchemaPropertySets] ([ParentId], [Name], [PropertySetTypeId], [ClassName]) VALUES (@parentId, 'NT1', 1, 'NT1Class')
						GO
						-- Create NodeType NT0/NT2
						DECLARE @parentId int
						SELECT @parentId = [PropertySetId] FROM [dbo].[SchemaPropertySets] WHERE [Name] = 'NT0'
						INSERT INTO [dbo].[SchemaPropertySets] ([ParentId], [Name], [PropertySetTypeId], [ClassName]) VALUES (@parentId, 'NT2', 1, 'NT2Class')
						GO"                        ;

            string sql = writer.GetSqlScript();

            Assert.IsTrue(ScriptsAreEqual(sql, expectedSql));
        }
        public void SqlSchemaWriter_ModifyNodeType()
        {
            SchemaEditor ed  = new SchemaEditor();
            NodeType     nt0 = CreateNodeType(ed, null, "NT0", "NT0C", 1);
            NodeType     nt1 = CreateNodeType(ed, nt0, "NT1", "NT1C", 2);

            var writer = SqlSchemaWriterAccessor.Create();

            writer.Open();
            writer.ModifyNodeType(nt0, nt0.Parent, "NT0Cmod");
            writer.ModifyNodeType(nt1, nt1.Parent, "NT1Cmod");

            string expectedSql = @"
						-- Modify NodeType: NT0 (original ClassName = 'NT0C')
						UPDATE [dbo].[SchemaPropertySets] SET
								[ParentId] = null
								,[ClassName] = 'NT0Cmod'
						WHERE PropertySetId = 1
						GO
						-- Modify NodeType: NT1 (original ClassName = 'NT1C')
						UPDATE [dbo].[SchemaPropertySets] SET
								[ParentId] = 1
								,[ClassName] = 'NT1Cmod'
						WHERE PropertySetId = 2
						GO"                        ;

            string sql = writer.GetSqlScript();

            Assert.IsTrue(ScriptsAreEqual(sql, expectedSql));
        }
        public void SqlSchemaWriter_RemovePropertyTypeFromNodeType_String()
        {
            SchemaEditor ed = new SchemaEditor();
            NodeType     nt = CreateNodeType(ed, null, "NT0", "NT0Class", 1);
            PropertyType pt = CreatePropertyType(ed, "PT0", DataType.String, 2);

            ed.AddPropertyTypeToPropertySet(pt, nt);

            var writer = SqlSchemaWriterAccessor.Create();

            writer.Open();
            writer.RemovePropertyTypeFromPropertySet(pt, nt);

            string expectedSql = @"
						-- Reset property values
						UPDATE dbo.FlatProperties 
							SET nvarchar_1 = NULL
						WHERE Id IN (SELECT dbo.FlatProperties.Id FROM dbo.Nodes 
							INNER JOIN dbo.Versions ON dbo.Versions.NodeId = dbo.Nodes.NodeId 
							INNER JOIN dbo.FlatProperties ON dbo.Versions.VersionId = dbo.FlatProperties.VersionId 
							WHERE (dbo.Nodes.NodeTypeId = 1) AND (dbo.FlatProperties.Page = 0))
						-- Remove PropertyType 'PT0' from PropertySet 'NT0'
						DELETE FROM [dbo].[SchemaPropertySetsPropertyTypes] WHERE PropertyTypeId = 2 AND PropertySetId = 1
						GO"                        ;

            string sql = writer.GetSqlScript();

            Assert.IsTrue(ScriptsAreEqual(sql, expectedSql));
        }
        private PropertyType CreateContentListPropertyType(SchemaEditor editor, DataType dataType, int mapping, int id)
        {
            PropertyType pt = editor.CreateContentListPropertyType(dataType, mapping);

            SetSchemaItemId(pt, id);
            return(pt);
        }
Example #7
0
        private PermissionType CreatePermissionType(SchemaEditor ed, string name, int id)
        {
            PermissionType perm = ed.CreatePermissionType(name);

            SetSchemaItemId(perm, id);
            return(perm);
        }
        public void InMemSchemaWriter_FW_RemovePropertyTypeFromContentListType()
        {
            (RepositorySchemaData schema, SchemaWriter writer) = CreateEmptySchemaAndWriter();
            schema.ContentListTypes.Add(new ContentListTypeData()
            {
                Id         = 1,
                Name       = "LT0",
                Properties = new List <string> {
                    "#Int_0", "#Int_1", "#Int_2", "#Int_3", "#Int_4"
                }
            });
            SchemaEditor ed  = new SchemaEditor();
            var          lt  = CreateContentListType(ed, "LT0", 1);
            var          pt0 = CreateContentListPropertyType(ed, DataType.Int, 0, 1);
            var          pt1 = CreateContentListPropertyType(ed, DataType.Int, 1, 2);
            var          pt2 = CreateContentListPropertyType(ed, DataType.Int, 2, 3);
            var          pt3 = CreateContentListPropertyType(ed, DataType.Int, 3, 4);
            var          pt4 = CreateContentListPropertyType(ed, DataType.Int, 4, 5);

            // ACTION
            writer.Open();
            writer.RemovePropertyTypeFromPropertySet(pt4, lt); // last
            writer.RemovePropertyTypeFromPropertySet(pt2, lt); // middle
            writer.RemovePropertyTypeFromPropertySet(pt0, lt); // first

            // ASSERT
            Assert.AreEqual("#Int_1,#Int_3", ArrayToString(schema.ContentListTypes[0].Properties));
        }
        public void InMemSchemaWriter_FW_UpdatePropertyTypeDeclarationState()
        {
            (RepositorySchemaData schema, SchemaWriter writer) = CreateEmptySchemaAndWriter();
            schema.NodeTypes.Add(new NodeTypeData
            {
                Id         = 1,
                Name       = "NT0",
                ParentName = null,
                ClassName  = "NT0Class",
                Properties = new List <string> {
                    "PT0", "PT1", "PT2"
                }
            });

            var ed  = new SchemaEditor();
            var nt  = CreateNodeType(ed, null, "NT0", "NT0Class", 1);
            var pt0 = CreatePropertyType(ed, "PT0", DataType.String, 1);
            var pt1 = CreatePropertyType(ed, "PT1", DataType.String, 2);
            var pt2 = CreatePropertyType(ed, "PT2", DataType.String, 3);
            var pt3 = CreatePropertyType(ed, "PT3", DataType.String, 4);

            // ACTION
            writer.Open();
            writer.UpdatePropertyTypeDeclarationState(pt1, nt, false);
            writer.UpdatePropertyTypeDeclarationState(pt3, nt, true);

            // ASSERT
            Assert.AreEqual("PT0,PT2,PT3", ArrayToString(schema.NodeTypes[0].Properties));
        }
        public void InMemSchemaWriter_FW_DeleteContentListType()
        {
            (RepositorySchemaData schema, SchemaWriter writer) = CreateEmptySchemaAndWriter();
            schema.ContentListTypes.Add(new ContentListTypeData {
                Id = 1, Name = "LT0"
            });
            schema.ContentListTypes.Add(new ContentListTypeData {
                Id = 2, Name = "LT1"
            });
            schema.ContentListTypes.Add(new ContentListTypeData {
                Id = 3, Name = "LT2"
            });
            schema.ContentListTypes.Add(new ContentListTypeData {
                Id = 4, Name = "LT3"
            });
            var ed  = new SchemaEditor();
            var lt0 = CreateContentListType(ed, "LT0", 1);
            var lt2 = CreateContentListType(ed, "LT2", 1);
            var lt3 = CreateContentListType(ed, "LT3", 1);

            // ACTION
            writer.Open();
            writer.DeleteContentListType(lt2); // last
            writer.DeleteContentListType(lt3); // middle
            writer.DeleteContentListType(lt0); // first

            // ASSERT
            Assert.AreEqual(1, schema.ContentListTypes.Count);
            var listType = schema.ContentListTypes[0];

            Assert.AreEqual(2, listType.Id);
            Assert.AreEqual("LT1", listType.Name);
        }
        public void InMemSchemaWriter_FW_RemovePropertyTypeFromNodeType()
        {
            (RepositorySchemaData schema, SchemaWriter writer) = CreateEmptySchemaAndWriter();
            schema.NodeTypes.Add(new NodeTypeData
            {
                Id         = 1,
                Name       = "NT0",
                ParentName = null,
                ClassName  = "NT0Class",
                Properties = new List <string> {
                    "PT0", "PT1", "PT2", "PT3", "PT4"
                }
            });

            var ed  = new SchemaEditor();
            var nt  = CreateNodeType(ed, null, "NT0", "NT0Class", 1);
            var pt0 = CreatePropertyType(ed, "PT0", DataType.String, 1);
            var pt1 = CreatePropertyType(ed, "PT1", DataType.String, 2);
            var pt2 = CreatePropertyType(ed, "PT2", DataType.String, 3);
            var pt3 = CreatePropertyType(ed, "PT3", DataType.String, 4);
            var pt4 = CreatePropertyType(ed, "PT4", DataType.String, 5);

            // ACTION
            writer.Open();
            writer.RemovePropertyTypeFromPropertySet(pt4, nt); // last
            writer.RemovePropertyTypeFromPropertySet(pt2, nt); // middle
            writer.RemovePropertyTypeFromPropertySet(pt0, nt); // first

            // ASSERT
            Assert.AreEqual("PT1,PT3", ArrayToString(schema.NodeTypes[0].Properties));
        }
Example #12
0
        public void SqlSchemaWriter_RemovePropertyTypeFromNodeType_Reference()
        {
            SchemaEditor ed = new SchemaEditor();
            NodeType     nt = CreateNodeType(ed, null, "NT0", "NT0Class", 1);
            PropertyType pt = CreatePropertyType(ed, "PT0", DataType.Reference, 2);

            ed.AddPropertyTypeToPropertySet(pt, nt);

            var writer = SqlSchemaWriterAccessor.Create();

            writer.Open();
            writer.RemovePropertyTypeFromPropertySet(pt, nt);

            string expectedSql = @"
						-- Reset property value: NT0.PT0:Reference
						DELETE FROM dbo.ReferenceProperties WHERE ReferencePropertyId IN (SELECT dbo.ReferenceProperties.ReferencePropertyId FROM dbo.Nodes
							INNER JOIN dbo.Versions ON dbo.Versions.NodeId = dbo.Nodes.NodeId
							INNER JOIN dbo.ReferenceProperties ON dbo.Versions.VersionId = dbo.ReferenceProperties.VersionId
						WHERE (dbo.Nodes.NodeTypeId = 1) AND (dbo.ReferenceProperties.PropertyTypeId = 2))
						-- Remove PropertyType 'PT0' from PropertySet 'NT0'
						DELETE FROM [dbo].[SchemaPropertySetsPropertyTypes] WHERE PropertyTypeId = 2 AND PropertySetId = 1
						GO"                        ;

            string sql = writer.GetSqlScript();

            AssertScriptsAreEqual(expectedSql, sql);;
        }
Example #13
0
 public void SchemaEditor_CreatePropertySlot_WithTheSameName()
 {
     //-- hiba: nevutkozes
     SchemaEditor editor = new SchemaEditor();
     PropertyType slot1  = editor.CreatePropertyType("NewSlot", DataType.String);
     PropertyType slot2  = editor.CreatePropertyType("NewSlot", DataType.String);
 }
Example #14
0
        public void SchemaEditor_RemovePropertyType_FromTopReDeclarerType()
        {
            SchemaEditor editor = new SchemaEditor();
            NodeType     nt1    = editor.CreateNodeType(null, "nt1");
            NodeType     nt2    = editor.CreateNodeType(nt1, "nt2");
            NodeType     nt3    = editor.CreateNodeType(nt2, "nt3");
            PropertyType slot   = editor.CreatePropertyType("slot", DataType.String, 0);

            editor.AddPropertyTypeToPropertySet(slot, nt2);
            editor.AddPropertyTypeToPropertySet(slot, nt1);

            //-- meg kell jelenjen mindharmon
            PropertyType pt1 = nt1.PropertyTypes["slot"];
            PropertyType pt2 = nt2.PropertyTypes["slot"];
            PropertyType pt3 = nt3.PropertyTypes["slot"];

            //-- toroljuk a deklaralas eredeti helyerol
            PropertyType pt = editor.PropertyTypes["slot"];

            editor.RemovePropertyTypeFromPropertySet(pt, nt1);

            //-- el kell tunjon mindkettorol
            pt1 = nt1.PropertyTypes["slot"];
            pt2 = nt2.PropertyTypes["slot"];
            pt3 = nt3.PropertyTypes["slot"];
            Assert.IsNull(nt1.PropertyTypes["slot"], "#1");
            Assert.IsNotNull(nt2.PropertyTypes["slot"], "#2");
            Assert.IsNotNull(nt3.PropertyTypes["slot"], "#3");
        }
        public void SchemaWriter_DeleteNodeType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var nodeTypeName = "NT1-" + Guid.NewGuid();
                ed.CreateNodeType(null, nodeTypeName, "NT1Class");
                ed.Register();
                var nodeTypeCountBefore = StorageSchema.NodeTypes.Count;
                var nodeTypeId          = StorageSchema.NodeTypes[nodeTypeName].Id;

                // ACTION
                ed = new SchemaEditor();
                ed.Load();
                var nt = ed.NodeTypes[nodeTypeName];
                ed.DeleteNodeType(nt);
                ed.Register();

                // ASSERT
                Assert.AreEqual(nodeTypeCountBefore - 1, StorageSchema.NodeTypes.Count);
                Assert.IsNull(StorageSchema.NodeTypes[nodeTypeName]);
                Assert.IsNull(StorageSchema.NodeTypes.GetItemById(nodeTypeId));
            });
        }
        public void InMemSchemaWriter_FW_DeletePropertyType()
        {
            (RepositorySchemaData schema, SchemaWriter writer) = CreateEmptySchemaAndWriter();
            schema.PropertyTypes.Add(new PropertyTypeData
            {
                Id = 1, Name = "PT0", DataType = DataType.String, Mapping = 1, IsContentListProperty = false
            });
            schema.PropertyTypes.Add(new PropertyTypeData
            {
                Id = 2, Name = "PT1", DataType = DataType.String, Mapping = 2, IsContentListProperty = false
            });
            var ed = new SchemaEditor();
            var pt = CreatePropertyType(ed, "PT0", DataType.String, 1);

            // ACTION
            writer.Open();
            writer.DeletePropertyType(pt);

            // ASSERT
            Assert.AreEqual(1, schema.PropertyTypes.Count);
            var propType = schema.PropertyTypes[0];

            Assert.AreEqual(2, propType.Id);
            Assert.AreEqual("PT1", propType.Name);
            Assert.AreEqual(DataType.String, propType.DataType);
            Assert.AreEqual(2, propType.Mapping);
            Assert.AreEqual(false, propType.IsContentListProperty);
        }
        private PropertyType CreatePropertyType(SchemaEditor editor, string name, DataType dataType, int id)
        {
            PropertyType pt = editor.CreatePropertyType(name, dataType);

            SetSchemaItemId(pt, id);
            return(pt);
        }
        private ContentListType CreateContentListType(SchemaEditor editor, string name, int id)
        {
            var lt = editor.CreateContentListType(name);

            SetSchemaItemId(lt, id);
            return(lt);
        }
        /* ============================================================================== PropertyType */

        public void SchemaWriter_CreatePropertyType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var propertyTypeCountBefore = ed.PropertyTypes.Count;
                var lastPropertyTypeId      = ed.PropertyTypes.Max(x => x.Id);
                var propertyTypeName        = "PT1-" + Guid.NewGuid();
                var mapping = GetNextMapping(ed, false);

                // ACTION
                ed.CreatePropertyType(propertyTypeName, DataType.String, mapping);
                ed.Register();

                // ASSERT
                StorageSchema.Reload();

                Assert.AreEqual(propertyTypeCountBefore + 1, StorageSchema.PropertyTypes.Count);
                var propType = StorageSchema.PropertyTypes[propertyTypeName];
                Assert.AreEqual(propertyTypeName, propType.Name);
                Assert.AreEqual(lastPropertyTypeId + 1, propType.Id);
                Assert.AreEqual(DataType.String, propType.DataType);
                Assert.AreEqual(mapping, propType.Mapping);
                Assert.AreEqual(false, propType.IsContentListProperty);
            });
        }
Example #20
0
        public void SchemaEditor_RemovePropertyType_FromDeclarerType()
        {
            //-- krealunk egy torolhetot es felulirjuk
            SchemaEditor editor = new SchemaEditor();
            NodeType     nt1    = editor.CreateNodeType(null, "nt1");
            NodeType     nt2    = editor.CreateNodeType(nt1, "nt2");
            PropertyType slot   = editor.CreatePropertyType("slot", DataType.String, 0);

            editor.AddPropertyTypeToPropertySet(slot, nt1);

            //-- meg kell jelenjen mindketton
            PropertyType pt1 = nt1.PropertyTypes["slot"];
            PropertyType pt2 = nt2.PropertyTypes["slot"];

            //-- toroljuk a deklaralas eredeti helyerol
            PropertyType pt = editor.PropertyTypes["slot"];

            editor.RemovePropertyTypeFromPropertySet(pt, nt1);

            //-- el kell tunjon mindkettorol
            pt1 = nt1.PropertyTypes["slot"];
            pt2 = nt2.PropertyTypes["slot"];
            Assert.IsNull(nt1.PropertyTypes["slot"], "Ancestor PropertyType was not deleted");
            Assert.IsNull(nt2.PropertyTypes["slot"], "Inherited PropertyType was not deleted");
        }
        public void SchemaWriter_ModifyNodeType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var nodeTypeName = "NT1-" + Guid.NewGuid();
                ed.CreateNodeType(null, nodeTypeName, "NT1Class");
                ed.Register();
                var nodeTypeCountBefore = StorageSchema.NodeTypes.Count;
                var nodeTypeId          = StorageSchema.NodeTypes[nodeTypeName].Id;

                // ACTION
                ed = new SchemaEditor();
                ed.Load();
                var nt = ed.NodeTypes[nodeTypeName];
                ed.ModifyNodeType(nt, "NT1Class_modified");
                ed.Register();

                // ASSERT
                Assert.AreEqual(nodeTypeCountBefore, StorageSchema.NodeTypes.Count);
                var nodeType = StorageSchema.NodeTypes[nodeTypeName];
                Assert.AreEqual(nodeTypeId, nodeType.Id);
                Assert.AreEqual(nodeTypeName, nodeType.Name);
                Assert.AreEqual("NT1Class_modified", nodeType.ClassName);
            });
        }
        /* ============================================================================== NodeType */

        public void SchemaWriter_CreateRootNodeType_WithoutClassName()
        {
            IntegrationTest(() =>
            {
                try
                {
                    var ed = new SchemaEditor();
                    ed.Load();

                    // ACTION
                    ed.CreateNodeType(null, "NT1-" + Guid.NewGuid(), null);
                    ed.Register();

                    Assert.Fail();
                }
                catch (Exception e)
                {
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    Assert.IsTrue(e.Message.Contains("ClassName"));
                    // ignored
                }
            });
        }
        public void SchemaWriter_CreateNodeType_WithParent()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var nodeTypeCountBefore = StorageSchema.NodeTypes.Count;
                var lastNodeTypeId      = StorageSchema.NodeTypes.Max(x => x.Id);
                var nodeTypeName1       = "NT1-" + Guid.NewGuid();
                var nodeTypeName2       = "NT2-" + Guid.NewGuid();
                var className1          = "NT0Class";
                var className2          = "NT1Class";

                // ACTION
                var nt1 = ed.CreateNodeType(null, nodeTypeName1, className1);
                ed.CreateNodeType(nt1, nodeTypeName2, className2);
                ed.Register();

                // ASSERT
                Assert.AreEqual(nodeTypeCountBefore + 2, StorageSchema.NodeTypes.Count);
                var nodeType1 = StorageSchema.NodeTypes[nodeTypeName1];
                Assert.AreEqual(lastNodeTypeId + 1, nodeType1.Id);
                Assert.AreEqual(nodeTypeName1, nodeType1.Name);
                Assert.AreEqual(null, nodeType1.Parent);
                Assert.AreEqual(className1, nodeType1.ClassName);
                var nodeType2 = StorageSchema.NodeTypes[nodeTypeName2];
                Assert.AreEqual(lastNodeTypeId + 2, nodeType2.Id);
                Assert.AreEqual(nodeTypeName2, nodeType2.Name);
                Assert.AreEqual(nodeType1, nodeType2.Parent);
                Assert.AreEqual(className2, nodeType2.ClassName);
            });
        }
Example #24
0
        public void TypeCollection_Remove()
        {
            SchemaEditor ed = new SchemaEditor();

            for (int i = 0; i < 5; i++)
            {
                ed.CreateNodeType(null, String.Concat("NT", i));
            }

            var tc = TypeCollectionAccessor <NodeType> .Create(ed);

            foreach (NodeType nt in ed.NodeTypes)
            {
                tc.Add(nt);
            }

            NodeType nt1          = ed.NodeTypes[1];
            bool     removed      = tc.Remove(nt1);
            bool     removedAgain = tc.Remove(nt1);

            Assert.IsTrue(tc[0].Name == "NT0");
            Assert.IsTrue(tc[1].Name == "NT2");
            Assert.IsTrue(tc[2].Name == "NT3");
            Assert.IsTrue(tc[3].Name == "NT4");
            Assert.IsTrue(tc.Count == 4);
            Assert.IsTrue(removed && !removedAgain);
        }
        public static ContentTypeInstaller CreateBatchContentTypeInstaller()
        {
            SchemaEditor editor = new SchemaEditor();

            editor.Load();
            return(CreateBatchContentTypeInstaller(editor));
        }
Example #26
0
        public void TypeCollection_IndexOf()
        {
            SchemaEditor ed = new SchemaEditor();

            ed.Load();
            int id = ed.NodeTypes[1].Id;
            var tc = TypeCollectionAccessor <NodeType> .Create(ed);

            foreach (NodeType nt in ed.NodeTypes)
            {
                tc.Add(nt);
            }
            tc.RemoveAt(0);
            for (int i = 1; i < tc.Count; i++)
            {
                if (tc.IndexOf(ed.NodeTypes[i]) != i - 1)
                {
                    Assert.Fail();
                }
            }
            if (tc.IndexOf(ed.NodeTypes[0]) != -1)
            {
                Assert.Fail();
            }
            Assert.IsTrue(true);
        }
Example #27
0
        public void TypeCollection_Insert()
        {
            SchemaEditor ed = new SchemaEditor();

            for (int i = 0; i < 5; i++)
            {
                ed.CreateNodeType(null, String.Concat("NT", i));
            }

            var tc = TypeCollectionAccessor <NodeType> .Create(ed);

            foreach (NodeType nt in ed.NodeTypes)
            {
                tc.Add(nt);
            }

            NodeType nt1 = ed.NodeTypes[0];

            tc.RemoveAt(0);
            tc.Insert(1, nt1);

            Assert.IsTrue(tc[0].Name == "NT1");
            Assert.IsTrue(tc[1].Name == "NT0");
            Assert.IsTrue(tc[2].Name == "NT2");
            Assert.IsTrue(tc[3].Name == "NT3");
            Assert.IsTrue(tc[4].Name == "NT4");
        }
        public void SchemaWriter_DeleteContentListType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var contentListTypeCountBefore = ed.ContentListTypes.Count;
                var contentListTypeName1       = "LT1-" + Guid.NewGuid();
                var contentListTypeName2       = "LT2-" + Guid.NewGuid();
                var contentListTypeName3       = "LT3-" + Guid.NewGuid();
                var contentListTypeName4       = "LT4-" + Guid.NewGuid();
                ed.CreateContentListType(contentListTypeName1);
                ed.CreateContentListType(contentListTypeName2);
                ed.CreateContentListType(contentListTypeName3);
                ed.CreateContentListType(contentListTypeName4);
                ed.Register();
                Assert.AreEqual(contentListTypeCountBefore + 4, StorageSchema.ContentListTypes.Count);

                // ACTION
                ed = new SchemaEditor();
                ed.Load();
                ed.DeleteContentListType(ed.ContentListTypes[contentListTypeName4]); // last
                ed.DeleteContentListType(ed.ContentListTypes[contentListTypeName2]); // middle
                ed.DeleteContentListType(ed.ContentListTypes[contentListTypeName1]); // first
                ed.Register();

                // ASSERT
                Assert.AreEqual(contentListTypeCountBefore + 1, StorageSchema.ContentListTypes.Count);
                var listType = StorageSchema.ContentListTypes[contentListTypeName3];
                Assert.AreEqual(contentListTypeName3, listType.Name);
            });
        }
        /* ============================================================================== PropertyType assignment */

        public void SchemaWriter_AddPropertyTypeToNodeType_Declared()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var nodeTypeName = "NT1-" + Guid.NewGuid();
                var ptName1      = "PT1-" + Guid.NewGuid();
                var ptName2      = "PT2-" + Guid.NewGuid();
                ed.CreateNodeType(null, nodeTypeName, "NT0Class");
                ed.Register();

                // ACTION
                ed = new SchemaEditor();
                ed.Load();
                var pt1 = ed.CreatePropertyType(ptName1, DataType.String, GetNextMapping(ed, false));
                var pt2 = ed.CreatePropertyType(ptName2, DataType.String, GetNextMapping(ed, false));
                var nt  = ed.NodeTypes[nodeTypeName];
                nt.AddPropertyType(pt1);
                nt.AddPropertyType(pt2);
                ed.Register();

                // ASSERT
                nt = StorageSchema.NodeTypes[nodeTypeName];
                AssertSequenceEqual(
                    new[] { ptName1, ptName2 },
                    nt.PropertyTypes.Select(x => x.Name));
            });
        }
        public void SchemaWriter_AddPropertyTypeToContentListType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var lt = ed.CreateContentListType("LT0" + Guid.NewGuid());

                // ACTION
                var pt0 = ed.CreateContentListPropertyType(DataType.String, GetNextMapping(ed, true));
                var pt1 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                var pt2 = ed.CreateContentListPropertyType(DataType.String, GetNextMapping(ed, true));
                var pt3 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                ed.AddPropertyTypeToPropertySet(pt0, lt);
                ed.AddPropertyTypeToPropertySet(pt1, lt);
                ed.AddPropertyTypeToPropertySet(pt2, lt);
                ed.AddPropertyTypeToPropertySet(pt3, lt);
                ed.Register();

                // ASSERT
                var schema = DP.LoadSchemaAsync(CancellationToken.None).GetAwaiter().GetResult();
                var ltData = schema.ContentListTypes.First(x => x.Name == lt.Name);
                AssertSequenceEqual(new[] { pt0.Name, pt1.Name, pt2.Name, pt3.Name }, ltData.Properties);
            });
        }
Example #31
0
		public void TypeCollection_Constructor_WithAllAllowedTypes()
		{
			SchemaEditor ed = new SchemaEditor();
			TypeCollection<NodeType> tc1 = TypeCollectionAccessor<NodeType>.Create(ed).Target;
			TypeCollection<PermissionType> tc4 = TypeCollectionAccessor<PermissionType>.Create(ed).Target;
			TypeCollection<PropertyType> tc5 = TypeCollectionAccessor<PropertyType>.Create(ed).Target;
		}
Example #32
0
		public void TypeCollection_Add_NodeTypeToSchema()
		{
			SchemaEditor ed = new SchemaEditor();
			var nodeTypes = TypeCollectionAccessor<NodeType>.Create(ed);
			ed.Load();
			nodeTypes.Add(ed.NodeTypes[0]);
			nodeTypes.Add(ed.NodeTypes[1]);

			Assert.IsTrue(nodeTypes.Count == 2 && nodeTypes[0] == ed.NodeTypes[0] && nodeTypes[1] == ed.NodeTypes[1]);
		}
Example #33
0
		public void SchemaEditor_LoadSchema()
		{
			SchemaEditor editor1 = new SchemaEditor();
			editor1.Load();

			editor1.CreatePermissionType("PermA");

			string s = editor1.ToXml();
			XmlDocument xd = new XmlDocument();
			xd.LoadXml(s);

			SchemaEditor editor2 = new SchemaEditor();
			editor2.Load(xd);
			string ss = editor2.ToXml();
		}
Example #34
0
        private PropertyType CreateContentListPropertyType(SchemaEditor editor, DataType dataType, int mapping, int id)
		{
			PropertyType pt = editor.CreateContentListPropertyType(dataType, mapping);
			SetSchemaItemId(pt, id);
			return pt;
		}
Example #35
0
		private ContentListType CreateContentListType(SchemaEditor editor, string name, int id)
		{
            var lt = editor.CreateContentListType(name);
			SetSchemaItemId(lt, id);
			return lt;
		}
Example #36
0
		private void RemoveContentType(ContentType contentType, SchemaEditor editor)
		{
			//-- Remove recursive
			foreach (FieldSetting fieldSetting in contentType.FieldSettings)
				if (fieldSetting.Owner == contentType)
					fieldSetting.ParentFieldSetting = null;
			foreach (ContentType childType in contentType.ChildTypes)
				RemoveContentType(childType, editor);
			NodeType nodeType = editor.NodeTypes[contentType.Name];
			if (nodeType != null)
				editor.DeleteNodeType(nodeType);
			_contentTypes.Remove(contentType.Name);
			_contentPaths.Remove(contentType.Name);
		}
Example #37
0
		internal static void ApplyChangesInEditor(ContentType contentType, SchemaEditor editor)
		{
			//-- Find ContentHandler
			Type handlerType = TypeHandler.GetType(contentType.HandlerName);
			if (handlerType == null)
				throw new RegistrationException(String.Concat(
					SR.Exceptions.Registration.Msg_ContentHandlerNotFound, ": ", contentType.HandlerName));

			//-- parent type
			NodeType parentNodeType = null;
			if (contentType.ParentTypeName != null)
			{
				parentNodeType = editor.NodeTypes[contentType.ParentTypeName];
				if (parentNodeType == null)
					throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_UnknownParentContentType, contentType.Name);
			}

			//-- handler type
			NodeType nodeType = editor.NodeTypes[contentType.Name];
			if (nodeType == null)
				nodeType = editor.CreateNodeType(parentNodeType, contentType.Name, contentType.HandlerName);
			if (nodeType.ClassName != contentType.HandlerName)
				editor.ModifyNodeType(nodeType, contentType.HandlerName);
			if (nodeType.Parent != parentNodeType)
				editor.ModifyNodeType(nodeType, parentNodeType);

			//-- 1: ContentHandler properties
			NodeTypeRegistration ntReg = ParseAttributes(handlerType);
			if (ntReg == null)
				throw new ContentRegistrationException(
					SR.Exceptions.Registration.Msg_DefinedHandlerIsNotAContentHandler, contentType.Name);

			//-- 2: Field properties
			foreach (FieldSetting fieldSetting in contentType.FieldSettings)
			{
				Type[][] slots = fieldSetting.HandlerSlots;
				int fieldSlotCount = slots.GetLength(0);

				if (fieldSetting.Bindings.Count != fieldSlotCount)
					throw new ContentRegistrationException(String.Format(CultureInfo.InvariantCulture,
						SR.Exceptions.Registration.Msg_FieldBindingsCount_1, fieldSlotCount), contentType.Name, fieldSetting.Name);
				for (int i = 0; i < fieldSetting.Bindings.Count; i++)
				{
					string propName = fieldSetting.Bindings[i];
					var dataType = fieldSetting.DataTypes[i];
					CheckDataType(propName, dataType, contentType.Name, editor);
					PropertyInfo propInfo = handlerType.GetProperty(propName);
					if (propInfo != null)
					{
						//-- #1: there is a property under the slot:
						bool ok = false;
						for (int j = 0; j < slots[i].Length; j++)
						{
							//if (slots[i][j] == propInfo.PropertyType)
							if (slots[i][j].IsAssignableFrom(propInfo.PropertyType))
							{
								PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propName);
								if (propInfo.DeclaringType != handlerType)
								{
									if (propReg == null)
									{
										object[] attrs = propInfo.GetCustomAttributes(typeof(RepositoryPropertyAttribute), false);
										if (attrs.Length > 0)
										{
											propReg = new PropertyTypeRegistration(propInfo, (RepositoryPropertyAttribute)attrs[0]);
											ntReg.PropertyTypeRegistrations.Add(propReg);
										}
									}
								}
								if (propReg != null && propReg.DataType != fieldSetting.DataTypes[i])
									throw new ContentRegistrationException(String.Concat(
										"The data type of the field in the content type definition does not match the data type of its content handler's property. ",
										"Please modify the field type in the content type definition. ",
										"ContentTypeDefinition: '", contentType.Name,
										"', FieldName: '", fieldSetting.Name,
										"', DataType of Field's binding: '", fieldSetting.DataTypes[i],
										"', ContentHandler: '", handlerType.FullName,
										"', PropertyName: '", propReg.Name,
										"', DataType of property: '", propReg.DataType,
										"'"));

								ok = true;
								fieldSetting.HandlerSlotIndices[i] = j;
								fieldSetting.PropertyIsReadOnly = !PropertyHasPublicSetter(propInfo);
								break;
							}
						}
						if (!ok)
						{
							//if (fieldSetting.ShortName != "Reference")
							//    if (fieldSetting.DataTypes[i] != RepositoryDataType.Reference)
							//        throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable,
							//            contentType.Name, fieldSetting.Name);
							//CheckReference(propInfo, slots[i], contentType, fieldSetting);

							if (fieldSetting.ShortName == "Reference" || fieldSetting.DataTypes[i] == RepositoryDataType.Reference)
								CheckReference(propInfo, slots[i], contentType, fieldSetting);
							//else if (fieldSetting.ShortName == "Choice")
							//    CheckChoice(propInfo, slots[i], contentType, fieldSetting);
							else
								throw new ContentRegistrationException(SR.Exceptions.Registration.Msg_PropertyAndFieldAreNotConnectable,
									contentType.Name, fieldSetting.Name);
						}
					}
					else
					{
						//-- #2: there is not a property under the slot:
						PropertyTypeRegistration propReg = new PropertyTypeRegistration(propName, dataType);
						ntReg.PropertyTypeRegistrations.Add(propReg);
					}
				}
			}

			//-- Collect deletables. Check equals
			foreach (PropertyType propType in nodeType.PropertyTypes.ToArray())
			{
				PropertyTypeRegistration propReg = ntReg.PropertyTypeRegistrationByName(propType.Name);
				if (propReg == null)
				{
					editor.RemovePropertyTypeFromPropertySet(propType, nodeType);
				}
			}


			//-- Register
			foreach (PropertyTypeRegistration ptReg in ntReg.PropertyTypeRegistrations)
			{
				PropertyType propType = nodeType.PropertyTypes[ptReg.Name];
				if (propType == null)
				{
					propType = editor.PropertyTypes[ptReg.Name];
					if (propType == null)
						propType = editor.CreatePropertyType(ptReg.Name, ConvertDataType(ptReg.DataType));
					editor.AddPropertyTypeToPropertySet(propType, nodeType);
				}
			}
		}
Example #38
0
		private ContentListType ManageContentListType(Dictionary<string, FieldDescriptor> fieldInfoList, Dictionary<string, List<string>> oldBindings, bool modify, out List<FieldSetting> fieldSettings)
		{
			fieldSettings = new List<FieldSetting>();
			if (!modify)
			{
				//-- Load
                foreach (string name in fieldInfoList.Keys)
                    fieldSettings.Add(FieldSetting.Create(fieldInfoList[name], oldBindings[name]));
                return this.ContentListType;
			}

			SchemaEditor editor = new SchemaEditor();
			editor.Load();
			bool hasChanges = false;
            var listType = this.ContentListType;
			Dictionary<string, List<string>> newBindings = new Dictionary<string, List<string>>();
			SlotTable slotTable = new SlotTable(oldBindings);
			if (listType == null)
			{
				//-- new
				listType = editor.CreateContentListType(Guid.NewGuid().ToString());
				foreach (string name in fieldInfoList.Keys)
					fieldSettings.Add(CreateNewFieldType(fieldInfoList[name], newBindings, listType, slotTable, editor));
				hasChanges = true;
			}
			else
			{
				//-- merge
				listType = editor.ContentListTypes[listType.Name];
				hasChanges |= RemoveUnusedFields(fieldInfoList, oldBindings, listType, editor);
				foreach (string name in fieldInfoList.Keys)
				{
					FieldSetting origField = GetFieldTypeByName(name, _fieldSettings);
					if (origField == null)
					{
						fieldSettings.Add(CreateNewFieldType(fieldInfoList[name], newBindings, listType, slotTable, editor));
						hasChanges = true;
					}
					else
					{
						List<string> bindList = new List<string>(origField.Bindings.ToArray());
                        fieldSettings.Add(FieldSetting.Create(fieldInfoList[name], bindList));
                        newBindings.Add(name, bindList);
					}
				}
			}
			if (hasChanges)
				editor.Register();
            this.ContentListBindings = newBindings;
			return ActiveSchema.ContentListTypes[listType.Name];
		}
Example #39
0
		private bool RemoveUnusedFields(Dictionary<string, FieldDescriptor> fieldInfoList, Dictionary<string, List<string>> oldBindings, ContentListType listType, SchemaEditor editor)
		{
			bool hasChanges = false;
			for (int i = _fieldSettings.Count - 1; i >= 0; i--)
			{
				FieldSetting oldType = _fieldSettings[i];
				bool needtoDelete = !fieldInfoList.ContainsKey(oldType.Name);
				if (!needtoDelete)
				{
					FieldDescriptor newType = fieldInfoList[oldType.Name];
					if (oldType.DataTypes.Length != newType.DataTypes.Length)
					{
						needtoDelete = true;
					}
					else
					{
						for (int j = 0; j < oldType.DataTypes.Length; j++)
						{
							if (oldType.DataTypes[j] != newType.DataTypes[j])
							{
								needtoDelete = true;
								break;
							}
						}
					}
				}
				if (needtoDelete)
				{
					hasChanges = true;
					foreach (string binding in oldType.Bindings)
					{
						PropertyType oldPropertyType = editor.PropertyTypes[binding];
						editor.RemovePropertyTypeFromPropertySet(oldPropertyType, listType);
					}
					_fieldSettings.RemoveAt(i);
					oldBindings.Remove(oldType.Name);
				}
			}
			//-- Apply changes. Slot reusing prerequisit: values of unused slots must be null.
            //if (hasChanges)
            //    editor.Register();
            return hasChanges;
		}
Example #40
0
		public void TypeCollection_IndexOf()
		{
			SchemaEditor ed = new SchemaEditor();
			ed.Load();
			int id = ed.NodeTypes[1].Id;
			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);
			tc.RemoveAt(0);
			for (int i = 1; i < tc.Count; i++)
				if (tc.IndexOf(ed.NodeTypes[i]) != i - 1)
					Assert.Fail();
			if (tc.IndexOf(ed.NodeTypes[0]) != -1)
				Assert.Fail();
			Assert.IsTrue(true);
		}
Example #41
0
		//TODO: Change structure: not implemented
		//[TestMethod()]
		//public void ContentType_FullInstall_InheritedClass_ChangeParent()
		//{
		//    Assembly asm = SchemaTestTools.DynamicAssembly;

		//    //-- Step 1: Install content types: TestType1, TestType2 and TestType1/TestType3
		//    string contentTypeDef1 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType1' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
		//			<Fields>
		//				<Field name='TestField' type='ShortText'>
		//					<DisplayName>TestField1</DisplayName>
		//				</Field>
		//			</Fields>
		//		</ContentType>";
		//    string contentTypeDef2 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType2' parentType='GenericContent' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
		//			<Fields>
		//				<Field name='TestField' type='ShortText'>
		//					<DisplayName>TestField2</DisplayName>
		//				</Field>
		//			</Fields>
		//		</ContentType>";
		//    string contentTypeDef3 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType3' parentType='TestType1' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'>
		//			<Fields>
		//				<Field name='TestField' type='ShortText'></Field>
		//			</Fields>
		//		</ContentType>";

		//    ContentTypeInstaller installer = ContentTypeInstaller.CreateBatchContentTypeInstaller();
		//    installer.AddContentType(contentTypeDef1);
		//    installer.AddContentType(contentTypeDef2);
		//    installer.AddContentType(contentTypeDef3);
		//    installer.ExecuteBatch();

		//    //-- Step 2: Reinstall TestType3 under TestType2
		//    contentTypeDef3 = @"<?xml version='1.0' encoding='utf-8'?>
		//		<ContentType name='TestType3' parentType='TestType2' handler='SenseNet.ContentRepository.GenericContent' xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition'></ContentType>";

		//    ContentTypeInstaller.InstallContentType(contentTypeDef3);

		//    NodeType nt1 = ActiveSchema.NodeTypes["TestType1"];
		//    NodeType nt2 = ActiveSchema.NodeTypes["TestType2"];
		//    NodeType nt3 = ActiveSchema.NodeTypes["TestType3"];
		//    ContentType ct1 = ContentTypeManager.Current.GetContentTypeByName(nt1.Name);
		//    ContentType ct2 = ContentTypeManager.Current.GetContentTypeByName(nt2.Name);
		//    ContentType ct3 = ContentTypeManager.Current.GetContentTypeByName(nt3.Name);

		//    SNC.Content c3 = SNC.Content.CreateNew("TestType3", this.TestRoot, "ChangeParentTest3");

		//    Assert.IsTrue(ct3.Path == Path.Combine(ct2.Path, ct3.Name));
		//    Assert.IsTrue(c3.Fields["TestField"].Title == "TestField2");
		//}


		//================================================= Tools =================================================

		private string InstallContentType(string contentTypeDefInstall, string contentTypeDefModify)
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();

			ContentTypeManagerAccessor ctmAcc = new ContentTypeManagerAccessor(ContentTypeManager.Current);
			ContentType cts = ctmAcc.LoadOrCreateNew(contentTypeDefInstall);
            if (contentTypeDefModify != null)
            {
                cts.Save(false);
                var parent = ContentType.GetByName(cts.ParentName);
                ContentTypeManager.Current.AddContentType(cts);
            }

			ctmAcc.ApplyChangesInEditor(cts, ed2);

			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();
			ed2Acc.RegisterSchema(ed1, wr);

			if (contentTypeDefModify != null)
			{
				//-- Id-k beallitasa es klonozas
				SchemaEditor ed3 = new SchemaEditor();
				SchemaEditorAccessor ed3Acc = new SchemaEditorAccessor(ed3);
				SchemaItemAccessor schItemAcc;
				int id = 1;
				foreach (PropertyType pt in ed2.PropertyTypes)
				{
					PropertyType clone = ed3.CreatePropertyType(pt.Name, pt.DataType, pt.Mapping);
					schItemAcc = new SchemaItemAccessor(pt);
					schItemAcc.Id = id++;
					schItemAcc = new SchemaItemAccessor(clone);
					schItemAcc.Id = pt.Id;
				}
				id = 1;
				foreach (NodeType nt in ed2.NodeTypes)
				{
					NodeType clone = ed3.CreateNodeType(nt.Parent, nt.Name, nt.ClassName);
					foreach (PropertyType pt in nt.PropertyTypes)
						ed3.AddPropertyTypeToPropertySet(ed3.PropertyTypes[pt.Name], clone);
					schItemAcc = new SchemaItemAccessor(nt);
					schItemAcc.Id = id++;
					schItemAcc = new SchemaItemAccessor(clone);
					schItemAcc.Id = nt.Id;
				}

				cts = ctmAcc.LoadOrCreateNew(contentTypeDefModify);
				ctmAcc.ApplyChangesInEditor(cts, ed3);
				wr = new TestSchemaWriter();
				ed3Acc.RegisterSchema(ed2, wr);
			}

			return wr.Log;
		}
Example #42
0
		public void TypeCollection_GetEnumerator()
		{
			SchemaEditor ed = new SchemaEditor();
			var nodeTypes = TypeCollectionAccessor<NodeType>.Create(ed);
			ed.Load();
			nodeTypes.Add(ed.NodeTypes[0]);
			nodeTypes.Add(ed.NodeTypes[1]);
			nodeTypes.Add(ed.NodeTypes[2]);
			IEnumerator<NodeType> enumerator = nodeTypes.GetEnumerator();
			int index = 0;
			while (enumerator.MoveNext())
				if (ed.NodeTypes[index++] != enumerator.Current)
					Assert.Fail();
			Assert.IsTrue(true);
		}
Example #43
0
		public void TypeCollection_GetItemById()
		{
			SchemaEditor ed = new SchemaEditor();
			ed.Load();
			int id = ed.NodeTypes[1].Id;
			var tc = TypeCollectionAccessor<NodeType>.Create(ed.NodeTypes);
			NodeType nt = tc.GetItemById(id);

			Assert.IsTrue(nt.Id == id);
		}
Example #44
0
		public void TypeCollection_CopyTo_1()
		{
			SchemaEditor ed = new SchemaEditor();
			var nodeTypes = TypeCollectionAccessor<NodeType>.Create(ed);
			ed.Load();
			nodeTypes.Add(ed.NodeTypes[0]);
			nodeTypes.Add(ed.NodeTypes[1]);
			nodeTypes.Add(ed.NodeTypes[2]);
			NodeType[] copy = new NodeType[4];
			nodeTypes.CopyTo(copy, 1);
			Assert.IsTrue(copy[1] == ed.NodeTypes[0] && copy[2] == ed.NodeTypes[1] && copy[3] == ed.NodeTypes[2]);
		}
Example #45
0
		public void TypeCollection_Contains_ANodeType()
		{
			SchemaEditor ed = new SchemaEditor();
			var nodeTypes = TypeCollectionAccessor<NodeType>.Create(ed);
			ed.Load();
			nodeTypes.Add(ed.NodeTypes[0]);
			nodeTypes.Add(ed.NodeTypes[1]);

			Assert.IsTrue(nodeTypes.Contains(ed.NodeTypes[0]) && !nodeTypes.Contains(ed.NodeTypes[2]));
		}
Example #46
0
		private PropertyType CreatePropertyType(SchemaEditor editor, string name, DataType dataType, int id)
		{
			PropertyType pt = editor.CreatePropertyType(name, dataType);
			SetSchemaItemId(pt, id);
			return pt;
		}
Example #47
0
		private NodeType CreateNodeType(SchemaEditor editor, NodeType parent, string name, string className, int id)
		{
			NodeType nt = editor.CreateNodeType(parent, name, className);
			SetSchemaItemId(nt, id);
			return nt;
		}
Example #48
0
		public void TypeCollection_RemoveAt()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			tc.RemoveAt(1);

			Assert.IsTrue(tc[0].Name == "NT0");
			Assert.IsTrue(tc[1].Name == "NT2");
			Assert.IsTrue(tc[2].Name == "NT3");
			Assert.IsTrue(tc[3].Name == "NT4");
			Assert.IsTrue(tc.Count == 4);
		}
Example #49
0
		public void TypeCollection_Add_AlienNodeTypeToSchema()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			ed1.Load();
			ed2.Load();
			var nodeTypes = TypeCollectionAccessor<NodeType>.Create(ed1);
			try
			{
				nodeTypes.Add(ed2.NodeTypes[0]);
			}
			catch (Exception e)
			{
				//  :)
				throw e.InnerException;
			}
		}
Example #50
0
		public void TypeCollection_GetItem()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			for (int i = 0; i < 5; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i));
		}
Example #51
0
		private string InstallContentType(string contentTypeDefInstall, string contentTypeDefModify)
		{
			XmlDocument schema = new XmlDocument();
			schema.LoadXml(@"<?xml version='1.0' encoding='utf-8' ?>
<StorageSchema xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/Storage/Schema'>
	<UsedPropertyTypes>
		<PropertyType itemID='1' name='Binary' dataType='Binary' mapping='0' />
		<PropertyType itemID='2' name='VersioningMode' dataType='Int' mapping='0' />
		<PropertyType itemID='3' name='Make' dataType='String' mapping='0' />
		<PropertyType itemID='4' name='Model' dataType='String' mapping='1' />
		<PropertyType itemID='5' name='Style' dataType='String' mapping='2' />
		<PropertyType itemID='6' name='Color' dataType='String' mapping='3' />
		<PropertyType itemID='7' name='EngineSize' dataType='String' mapping='4' />
		<PropertyType itemID='8' name='Power' dataType='String' mapping='5' />
		<PropertyType itemID='9' name='Price' dataType='String' mapping='6' />
		<PropertyType itemID='10' name='Description' dataType='Text' mapping='0' />
		<PropertyType itemID='11' name='Enabled' dataType='Int' mapping='1' />
		<PropertyType itemID='12' name='Domain' dataType='String' mapping='7' />
		<PropertyType itemID='13' name='Email' dataType='String' mapping='8' />
		<PropertyType itemID='14' name='FullName' dataType='String' mapping='9' />
		<PropertyType itemID='15' name='PasswordHash' dataType='String' mapping='10' />
		<PropertyType itemID='16' name='Memberships' dataType='Binary' mapping='1' />
		<PropertyType itemID='17' name='PendingUserLang' dataType='String' mapping='11' />
		<PropertyType itemID='18' name='Language' dataType='Int' mapping='2' />
		<PropertyType itemID='19' name='Url' dataType='String' mapping='12' />
		<PropertyType itemID='20' name='AuthenticationType' dataType='String' mapping='13' />
		<PropertyType itemID='21' name='StartPage' dataType='String' mapping='14' />
		<PropertyType itemID='22' name='LoginPage' dataType='String' mapping='15' />
		<PropertyType itemID='23' name='StatisticalLog' dataType='Int' mapping='3' />
		<PropertyType itemID='24' name='AuditLog' dataType='Int' mapping='4' />
		<PropertyType itemID='26' name='PageNameInMenu' dataType='String' mapping='16' />
		<PropertyType itemID='27' name='Hidden' dataType='Int' mapping='6' />
		<PropertyType itemID='28' name='Keywords' dataType='String' mapping='17' />
		<PropertyType itemID='29' name='MetaDescription' dataType='String' mapping='18' />
		<PropertyType itemID='30' name='MetaTitle' dataType='String' mapping='19' />
		<PropertyType itemID='31' name='PageTemplateNode' dataType='Reference' mapping='0' />
		<PropertyType itemID='32' name='DefaultPortletSkin' dataType='String' mapping='20' />
		<PropertyType itemID='33' name='HiddenPageFrom' dataType='String' mapping='21' />
		<PropertyType itemID='34' name='Authors' dataType='String' mapping='22' />
		<PropertyType itemID='35' name='CustomMeta' dataType='String' mapping='23' />
		<PropertyType itemID='36' name='Comment' dataType='String' mapping='24' />
		<PropertyType itemID='37' name='PersonalizationSettings' dataType='Binary' mapping='2' />
		<PropertyType itemID='38' name='Title' dataType='String' mapping='25' />
		<PropertyType itemID='39' name='Subtitle' dataType='String' mapping='26' />
		<PropertyType itemID='40' name='Header' dataType='Text' mapping='1' />
		<PropertyType itemID='41' name='Body' dataType='Text' mapping='2' />
		<PropertyType itemID='42' name='Links' dataType='Text' mapping='3' />
		<PropertyType itemID='43' name='ContentLanguage' dataType='String' mapping='27' />
		<PropertyType itemID='44' name='Author' dataType='String' mapping='28' />
		<PropertyType itemID='45' name='ContractId' dataType='String' mapping='29' />
		<PropertyType itemID='46' name='Project' dataType='String' mapping='30' />
		<PropertyType itemID='47' name='Responsee' dataType='String' mapping='31' />
		<PropertyType itemID='48' name='Lawyer' dataType='String' mapping='32' />
		<PropertyType itemID='49' name='MasterPageNode' dataType='Reference' mapping='1' />
		<PropertyType itemID='50' name='Members' dataType='Reference' mapping='2' />
		<PropertyType itemID='51' name='Manufacturer' dataType='String' mapping='33' />
		<PropertyType itemID='52' name='Driver' dataType='String' mapping='34' />
		<PropertyType itemID='53' name='InheritableVersioningMode' dataType='Int' mapping='35' />
		<PropertyType itemID='54' name='HasApproving' dataType='Int' mapping='36' />
	</UsedPropertyTypes>
	<NodeTypeHierarchy>
		<NodeType itemID='7' name='PersonalizationFile' className='SenseNet.ContentRepository.PersonalizationFile'>
			<PropertyType name='Binary' />
			<PropertyType name='VersioningMode' />
			<PropertyType name='InheritableVersioningMode' />
			<PropertyType name='HasApproving' />
		</NodeType>
		<NodeType itemID='5' name='GenericContent' className='SenseNet.ContentRepository.GenericContent'>
			<PropertyType name='VersioningMode' />
			<PropertyType name='InheritableVersioningMode' />
			<PropertyType name='HasApproving' />
			<NodeType itemID='3' name='User' className='SenseNet.ContentRepository.User'>
				<PropertyType name='VersioningMode' />
				<PropertyType name='Enabled' />
				<PropertyType name='Domain' />
				<PropertyType name='Email' />
				<PropertyType name='FullName' />
				<PropertyType name='PasswordHash' />
				<PropertyType name='Memberships' />
			</NodeType>
			<NodeType itemID='1' name='Folder' className='SenseNet.ContentRepository.Folder'>
				<PropertyType name='VersioningMode' />
				<NodeType itemID='16' name='Page' className='SenseNet.Portal.Page'>
					<PropertyType name='Binary' />
					<PropertyType name='PageNameInMenu' />
					<PropertyType name='Hidden' />
					<PropertyType name='Keywords' />
					<PropertyType name='MetaDescription' />
					<PropertyType name='MetaTitle' />
					<PropertyType name='PageTemplateNode' />
					<PropertyType name='DefaultPortletSkin' />
					<PropertyType name='HiddenPageFrom' />
					<PropertyType name='Authors' />
					<PropertyType name='CustomMeta' />
					<PropertyType name='Comment' />
					<PropertyType name='PersonalizationSettings' />
				</NodeType>
				<NodeType itemID='15' name='OrganizationalUnit' className='SenseNet.ContentRepository.OrganizationalUnit'>
				</NodeType>
				<NodeType itemID='14' name='Site' className='SenseNet.Portal.Site'>
					<PropertyType name='Description' />
					<PropertyType name='PendingUserLang' />
					<PropertyType name='Language' />
					<PropertyType name='Url' />
					<PropertyType name='AuthenticationType' />
					<PropertyType name='StartPage' />
					<PropertyType name='LoginPage' />
					<PropertyType name='StatisticalLog' />
					<PropertyType name='AuditLog' />
				</NodeType>
			</NodeType>
			<NodeType itemID='10' name='WebContentDemo' className='SenseNet.ContentRepository.GenericContent'>
				<PropertyType name='Keywords' />
				<PropertyType name='Title' />
				<PropertyType name='Subtitle' />
				<PropertyType name='Header' />
				<PropertyType name='Body' />
				<PropertyType name='Links' />
				<PropertyType name='ContentLanguage' />
				<PropertyType name='Author' />
			</NodeType>
			<NodeType itemID='9' name='File' className='SenseNet.ContentRepository.File'>
				<PropertyType name='Binary' />
				<NodeType itemID='13' name='PageTemplate' className='SenseNet.Portal.PageTemplate'>
					<PropertyType name='MasterPageNode' />
				</NodeType>
				<NodeType itemID='12' name='Contract' className='SenseNet.ContentRepository.File'>
					<PropertyType name='Description' />
					<PropertyType name='Language' />
					<PropertyType name='Keywords' />
					<PropertyType name='ContractId' />
					<PropertyType name='Project' />
					<PropertyType name='Responsee' />
					<PropertyType name='Lawyer' />
				</NodeType>
				<NodeType itemID='11' name='MasterPage' className='SenseNet.Portal.MasterPage' />
			</NodeType>
			<NodeType itemID='8' name='Car' className='SenseNet.ContentRepository.GenericContent'>
				<PropertyType name='Make' />
				<PropertyType name='Model' />
				<PropertyType name='Style' />
				<PropertyType name='Color' />
				<PropertyType name='EngineSize' />
				<PropertyType name='Power' />
				<PropertyType name='Price' />
				<PropertyType name='Description' />
			</NodeType>
		</NodeType>
		<NodeType itemID='4' name='ContentType' className='SenseNet.ContentRepository.Schema.ContentType'>
			<PropertyType name='Binary' />
		</NodeType>
		<NodeType itemID='2' name='Group' className='SenseNet.ContentRepository.Group'>
			<PropertyType name='VersioningMode' />
			<PropertyType name='Members' />
		</NodeType>
	</NodeTypeHierarchy>
	<PermissionTypes>
		<PermissionType itemID='1' name='See' />
		<PermissionType itemID='2' name='Open' />
		<PermissionType itemID='3' name='OpenMinor' />
		<PermissionType itemID='4' name='Save' />
		<PermissionType itemID='5' name='Publish' />
		<PermissionType itemID='6' name='ForceCheckin' />
		<PermissionType itemID='7' name='AddNew' />
		<PermissionType itemID='8' name='Approve' />
		<PermissionType itemID='9' name='Delete' />
		<PermissionType itemID='10' name='RecallOldVersion' />
		<PermissionType itemID='11' name='DeleteOldVersion' />
		<PermissionType itemID='12' name='SeePermissions' />
		<PermissionType itemID='13' name='SetPermissions' />
		<PermissionType itemID='14' name='RunApplication' />
	</PermissionTypes>
</StorageSchema>
");

			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			ed1.Load(schema);
			ed2.Load(schema);

			ContentTypeManagerAccessor ctmAcc = new ContentTypeManagerAccessor(ContentTypeManager.Current);
			ContentType cts = ctmAcc.LoadOrCreateNew(contentTypeDefInstall);
			ctmAcc.ApplyChangesInEditor(cts, ed2);

			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();
			ed2Acc.RegisterSchema(ed1, wr);

			if (contentTypeDefModify != null)
			{
				XmlDocument schema2 = new XmlDocument();
				schema2.LoadXml(ed2.ToXml());
				SchemaEditor ed3 = new SchemaEditor();
				ed3.Load(schema2);
				SchemaEditorAccessor ed3Acc = new SchemaEditorAccessor(ed3);


				cts = ctmAcc.LoadOrCreateNew(contentTypeDefModify);
				ctmAcc.ApplyChangesInEditor(cts, ed3);
				wr = new TestSchemaWriter();
				ed3Acc.RegisterSchema(ed2, wr);
			}

			return wr.Log;
		}
Example #52
0
		public void TypeCollection_SetItem()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			//-- Content: NT0, NT1, NT2, NT3, NT4
			for (int i = 0; i < 5; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i));

			tc.RemoveAt(0);

			//-- Content: NT1, NT2, NT3, NT4
			for (int i = 0; i < 4; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i + 1));

			for (int i = 0; i < 4; i++)
				tc[i] = ed.NodeTypes[i];

			//-- Content: NT0, NT1, NT2, NT3
			for (int i = 0; i < 4; i++)
				Assert.IsTrue(tc[i].Name == String.Concat("NT", i));
		}
Example #53
0
		private FieldSetting CreateNewFieldType(FieldDescriptor fieldInfo, Dictionary<string, List<string>> newBindings, ContentListType listType, SlotTable slotTable, SchemaEditor editor)
		{
			List<string> bindList = new List<string>();
			foreach (RepositoryDataType slotType in FieldManager.GetDataTypes(fieldInfo.FieldTypeShortName))
			{
				if (slotType == RepositoryDataType.NotDefined)
					continue;
				int slotNumber = slotTable.ReserveSlot((DataType)slotType);
				string binding = EncodeBinding(slotType, slotNumber);
				bindList.Add(binding);

				PropertyType pt = editor.PropertyTypes[binding];
				if (pt == null)
					pt = editor.CreateContentListPropertyType((DataType)slotType, slotNumber);
				editor.AddPropertyTypeToPropertySet(pt, listType);
			}
			newBindings.Add(fieldInfo.FieldName, bindList);

			return FieldSetting.Create(fieldInfo, bindList);
		}
Example #54
0
		public void TypeCollection_GetItemWithName()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			//-- Content: NT0, NT1, NT2, NT3, NT4
			tc.RemoveAt(0);
			//-- Content: NT1, NT2, NT3, NT4

			Assert.IsTrue(tc["NT2"] == ed.NodeTypes["NT2"]);

		}
Example #55
0
		internal void RemoveContentType(string name)
		{
			//-- Caller: ContentType.Delete()
			lock (_syncRoot)
			{
				ContentType contentType;
				if (_contentTypes.TryGetValue(name, out contentType))
				{
					SchemaEditor editor = new SchemaEditor();
					editor.Load();
					RemoveContentType(contentType, editor);
					editor.Register();

					// The ContentTypeManager distributes its reset, no custom DistributedAction call needed
					ContentTypeManager.Reset();
				}
			}
		}
Example #56
0
		public void TypeCollection_SetItemWithName()
		{
			SchemaEditor ed = new SchemaEditor();
			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			tc.Add(ed.CreateNodeType(null, String.Concat("NT0")));
			tc.Add(ed.CreateNodeType(null, String.Concat("NT1")));
			try
			{
				tc["NT1"] = ed.NodeTypes["NT0"];
			}
			catch (Exception e)
			{
				throw e.InnerException;
			}
		}
Example #57
0
		internal static void ApplyChanges(ContentType settings)
		{
			SchemaEditor editor = new SchemaEditor();
			editor.Load();
			ApplyChangesInEditor(settings, editor);
			editor.Register();

			// The ContentTypeManager distributes its reset, no custom DistributedAction call needed
			ContentTypeManager.Reset();
		}
Example #58
0
		public void TypeCollection_ToArray()
		{
			SchemaEditor ed = new SchemaEditor();
			for (int i = 0; i < 5; i++)
				ed.CreateNodeType(null, String.Concat("NT", i));

			var tc = TypeCollectionAccessor<NodeType>.Create(ed);
			foreach (NodeType nt in ed.NodeTypes)
				tc.Add(nt);

			NodeType[] ntArray = tc.ToArray();

			for (int i = 0; i < 5; i++)
				Assert.IsTrue(ntArray[i] == tc[i] && ntArray[i] == ed.NodeTypes[i]);
		}
Example #59
0
		private static void CheckDataType(string propName, RepositoryDataType dataType, string nodeTypeName, SchemaEditor editor)
		{
			var propType = editor.PropertyTypes[propName];

			if (propType == null)
				return;
			if (dataType == (RepositoryDataType)propType.DataType)
				return;

			//"DataType collision in two properties. NodeType = '{0}', PropertyType = '{1}', original DataType = {2}, passed DataType = {3}.";
			throw new RegistrationException(String.Format(SR.Exceptions.Registration.Msg_DataTypeCollisionInTwoProperties_4,
				nodeTypeName, propName, propType.DataType, dataType));
		}
Example #60
0
		private PermissionType CreatePermissionType(SchemaEditor ed, string name, int id)
		{
			PermissionType perm = ed.CreatePermissionType(name);
			SetSchemaItemId(perm, id);
			return perm;
		}