public void GetClassTest() { var fs = new FeatureSchema("Foo", "Bar"); Assert.AreEqual("Foo", fs.Name); Assert.AreEqual("Bar", fs.Description); Assert.AreEqual(0, fs.Classes.Count); var cls = new ClassDefinition("Class1", "Test Class"); fs.AddClass(cls); Assert.NotNull(fs.GetClass("Class1")); }
public void TestFeatureSchemaRoundtrip() { FeatureSchema schema = new FeatureSchema("Default", "Default Schema"); ClassDefinition cls = new ClassDefinition("Class1", "Test Class"); cls.AddProperty(new DataPropertyDefinition("ID", "ID Property") { IsAutoGenerated = true, DataType = DataPropertyType.Int64, IsNullable = false, }, true); var prop = cls.FindProperty("ID") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(1, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.Int64, prop.DataType); Assert.IsTrue(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); cls.AddProperty(new DataPropertyDefinition("Name", "The name") { DataType = DataPropertyType.String, Length = 255 }); prop = cls.FindProperty("Name") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(2, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.String, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); cls.AddProperty(new DataPropertyDefinition("Date", "The date") { DataType = DataPropertyType.DateTime, IsNullable = true }); prop = cls.FindProperty("Date") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.DateTime, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsTrue(prop.IsNullable); schema.AddClass(cls); Assert.AreEqual(1, schema.Classes.Count); XmlDocument doc = new XmlDocument(); schema.WriteXml(doc, doc); string path = Path.GetTempFileName(); doc.Save(path); FeatureSourceDescription fsd = new FeatureSourceDescription(Utils.OpenFile(path)); Assert.AreEqual(1, fsd.Schemas.Length); schema = fsd.Schemas[0]; Assert.NotNull(schema); cls = schema.GetClass("Class1"); Assert.NotNull(cls); prop = cls.FindProperty("ID") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.Int64, prop.DataType); Assert.IsTrue(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); prop = cls.FindProperty("Name") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.String, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); prop = cls.FindProperty("Date") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.DateTime, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsTrue(prop.IsNullable); }