Exemplo n.º 1
0
        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);
            });
        }
Exemplo n.º 2
0
        public void SchemaWriter_RemovePropertyTypeFromContentListType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var lt  = ed.CreateContentListType("LT1-" + Guid.NewGuid());
                var pt0 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                var pt1 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                var pt2 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                var pt3 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                var pt4 = ed.CreateContentListPropertyType(DataType.Int, GetNextMapping(ed, true));
                lt.AddPropertyType(pt0);
                lt.AddPropertyType(pt1);
                lt.AddPropertyType(pt2);
                lt.AddPropertyType(pt3);
                lt.AddPropertyType(pt4);
                ed.Register();

                // ACTION
                ed = new SchemaEditor();
                ed.Load();
                lt = ed.ContentListTypes[lt.Name];
                lt.RemovePropertyType(ed.PropertyTypes[pt4.Name]); // last
                lt.RemovePropertyType(ed.PropertyTypes[pt2.Name]); // middle
                lt.RemovePropertyType(ed.PropertyTypes[pt0.Name]); // first
                ed.Register();

                // ASSERT
                var schema = DP.LoadSchemaAsync(CancellationToken.None).GetAwaiter().GetResult();
                var ltData = schema.ContentListTypes.First(x => x.Name == lt.Name);
                AssertSequenceEqual(new[] { pt1.Name, pt3.Name }, ltData.Properties);
            });
        }
        private ContentListType CreateContentListType(SchemaEditor editor, string name, int id)
        {
            var lt = editor.CreateContentListType(name);

            SetSchemaItemId(lt, id);
            return(lt);
        }
Exemplo n.º 4
0
        public void SchEd_WriterCalling_CreateContentListType()
        {
            Test(() =>
            {
                SchemaEditor ed1            = new SchemaEditor();
                SchemaEditor ed2            = new SchemaEditor();
                SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
                TestSchemaWriter wr         = new TestSchemaWriter();

                //-- create original
                ed1.CreateContentListPropertyType(DataType.String, 0);
                SetSchemaItemId(ed1.PropertyTypes["#String_0"], 1);
                //-- create current
                ed2.CreateContentListPropertyType(DataType.String, 0);
                SetSchemaItemId(ed2.PropertyTypes["#String_0"], 1);

                //-- edit
                ed2.CreateContentListType("LT1");
                ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["#String_0"], ed2.ContentListTypes["LT1"]);

                //-- register
                ed2Acc.RegisterSchema(ed1, wr);

                //-- test
                string expectedLog = @"
				Open();
				CreateContentListType(name=<LT1>);
				AddPropertyTypeToPropertySet(propertyType=<#String_0>, owner=<LT1>, isDeclared=<True>);
				Close();
				"                .Replace("\r\n", "").Replace("\t", "");
                string log         = wr.Log.Replace("\r\n", "");
                Assert.IsTrue(log == expectedLog);
            });
        }
Exemplo n.º 5
0
        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);
            });
        }
Exemplo n.º 6
0
        private ContentListType ManageContentListTypeOneAttempt(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], null));
                }
                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, null));
                        newBindings.Add(name, bindList);
                    }
                }
            }
            if (hasChanges)
            {
                editor.Register();
            }
            this.ContentListBindings = newBindings;
            return(ActiveSchema.ContentListTypes[listType.Name]);
        }
Exemplo n.º 7
0
        public void SchemaEditor_AddWrongPropertyToContentListType()
        {
            SchemaEditor editor = new SchemaEditor();
            PropertyType pt1    = editor.CreatePropertyType("PT1", DataType.String);
            var          lt1    = editor.CreateContentListType("LT1");

            editor.AddPropertyTypeToPropertySet(pt1, lt1);
        }
Exemplo n.º 8
0
        public void SchemaEditor_CreateContentListType()
        {
            SchemaEditor editor = new SchemaEditor();
            var          lt1    = editor.CreateContentListType("LT1");

            Assert.IsTrue(editor.NodeTypes.Count == 0, "#1");
            Assert.IsNotNull(editor.ContentListTypes["LT1"], "#2");
            Assert.IsTrue(lt1.Id == 0, "#3");
        }
Exemplo n.º 9
0
        public void SchemaEditor_AddPropertyToContentListType()
        {
            SchemaEditor editor = new SchemaEditor();
            PropertyType pt1    = editor.CreateContentListPropertyType(DataType.String, 0);
            var          lt1    = editor.CreateContentListType("LT1");

            editor.AddPropertyTypeToPropertySet(pt1, lt1);
            Assert.IsNotNull(lt1.PropertyTypes["#String_0"], "#1");
            Assert.IsTrue(lt1.Id == 0, "#2");
        }
Exemplo n.º 10
0
        public void SchemaEditor_RemoveContentListType()
        {
            SchemaEditor editor = new SchemaEditor();

            var          lt1   = editor.CreateContentListType("LT1");
            PropertyType slot1 = editor.CreateContentListPropertyType(DataType.String, 0);

            editor.AddPropertyTypeToPropertySet(slot1, lt1);

            editor.DeleteContentListType(editor.ContentListTypes["LT1"]);

            Assert.IsTrue(editor.ContentListTypes.Count == 0);
        }
Exemplo n.º 11
0
        /* ============================================================================== ContentListType */

        public void SchemaWriter_CreateContentListType()
        {
            IntegrationTest(() =>
            {
                var ed = new SchemaEditor();
                ed.Load();
                var contentListTypeCountBefore = ed.ContentListTypes.Count;
                var lastContentListTypeId      = ed.ContentListTypes.Any() ? ed.ContentListTypes.Max(x => x.Id) : 0;
                var contentListTypeName        = "LT1-" + Guid.NewGuid();

                // ACTION
                ed.CreateContentListType(contentListTypeName);
                ed.Register();

                // ASSERT
                Assert.AreEqual(contentListTypeCountBefore + 1, StorageSchema.ContentListTypes.Count);
                var listType = StorageSchema.ContentListTypes[contentListTypeName];
                Assert.IsTrue(lastContentListTypeId < listType.Id);
                Assert.AreEqual(contentListTypeName, listType.Name);
            });
        }
Exemplo n.º 12
0
        public void SchEd_WriterCalling_DeleteContentListType()
		{
			SchemaEditor ed1 = new SchemaEditor();
			SchemaEditor ed2 = new SchemaEditor();
			SchemaEditorAccessor ed2Acc = new SchemaEditorAccessor(ed2);
			TestSchemaWriter wr = new TestSchemaWriter();

			//-- create original
			ed1.CreateContentListPropertyType(DataType.String, 0);
			SetSchemaItemId(ed1.PropertyTypes["#String_0"], 1);
			ed1.CreateContentListType("LT1");
			SetSchemaItemId(ed1.ContentListTypes["LT1"], 1);
			ed1.AddPropertyTypeToPropertySet(ed1.PropertyTypes["#String_0"], ed1.ContentListTypes["LT1"]);
			//-- create current
			ed2.CreateContentListPropertyType(DataType.String, 0);
			SetSchemaItemId(ed2.PropertyTypes["#String_0"], 1);
			ed2.CreateContentListType("LT1");
			SetSchemaItemId(ed2.ContentListTypes["LT1"], 1);
			ed2.AddPropertyTypeToPropertySet(ed2.PropertyTypes["#String_0"], ed2.ContentListTypes["LT1"]);

			//-- edit
			ed2.DeleteContentListType(ed2.ContentListTypes["LT1"]);

			//-- register
			ed2Acc.RegisterSchema(ed1, wr);

			//-- test
			string expectedLog = @"
				Open();
				DeleteContentListType(contentListType=<LT1>);
				Close();
				".Replace("\r\n", "").Replace("\t", "").Replace(" ", "");
			string log = wr.Log.Replace("\r\n", "").Replace(" ", "");
			Assert.IsTrue(log == expectedLog);
		}
Exemplo n.º 13
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];
		}
Exemplo n.º 14
0
        public void SchemaEditor_RemoveContentListType()
		{
			SchemaEditor editor = new SchemaEditor();

            var lt1 = editor.CreateContentListType("LT1");
			PropertyType slot1 = editor.CreateContentListPropertyType(DataType.String, 0);
			editor.AddPropertyTypeToPropertySet(slot1, lt1);

			editor.DeleteContentListType(editor.ContentListTypes["LT1"]);

			Assert.IsTrue(editor.ContentListTypes.Count == 0);
		}
Exemplo n.º 15
0
        public void SchemaEditor_AddPropertyToContentListType()
		{
			SchemaEditor editor = new SchemaEditor();
			PropertyType pt1 = editor.CreateContentListPropertyType(DataType.String, 0);
            var lt1 = editor.CreateContentListType("LT1");
			editor.AddPropertyTypeToPropertySet(pt1, lt1);
			Assert.IsNotNull(lt1.PropertyTypes["#String_0"], "#1");
			Assert.IsTrue(lt1.Id == 0, "#2");
		}
Exemplo n.º 16
0
        public void SchemaEditor_CreateContentListType()
		{
			SchemaEditor editor = new SchemaEditor();
            var lt1 = editor.CreateContentListType("LT1");
			Assert.IsTrue(editor.NodeTypes.Count == 0, "#1");
			Assert.IsNotNull(editor.ContentListTypes["LT1"], "#2");
			Assert.IsTrue(lt1.Id == 0, "#3");
		}
Exemplo n.º 17
0
        public void SchemaEditor_AddWrongPropertyToContentListType()
		{
			SchemaEditor editor = new SchemaEditor();
			PropertyType pt1 = editor.CreatePropertyType("PT1", DataType.String);
            var lt1 = editor.CreateContentListType("LT1");
			editor.AddPropertyTypeToPropertySet(pt1, lt1);
		}
Exemplo n.º 18
0
		private ContentListType CreateContentListType(SchemaEditor editor, string name, int id)
		{
            var lt = editor.CreateContentListType(name);
			SetSchemaItemId(lt, id);
			return lt;
		}