public void TestAddEntity() { using (Stream stream = Resources.GetXmlDocumentStream("suppressed")) { Assert.IsNotNull(stream); WXMLModel model = WXMLModel.LoadFromXml(new XmlTextReader(stream)); Assert.IsNotNull(model); Assert.AreEqual(2, model.GetActiveEntities().Count()); WXMLModel newModel = new WXMLModel(); EntityDefinition newEntity = new EntityDefinition("ee", "ee", string.Empty, string.Empty, newModel); SourceFragmentRefDefinition sf = new SourceFragmentRefDefinition(newModel.GetOrCreateSourceFragment("dbo", "ee")); newEntity.AddSourceFragment(sf); newEntity.AddProperty(new ScalarPropertyDefinition(newEntity, "ID", "ID", Field2DbRelations.None, string.Empty, newModel.GetOrCreateType(typeof(Int32)), new SourceFieldDefinition(sf, "id"), AccessLevel.Private, AccessLevel.Public)); model.Merge(Normalize(newModel)); Assert.AreEqual(3, model.GetActiveEntities().Count()); Assert.AreEqual(1, model.GetActiveEntities().Single(item => item.Identifier == "ee").GetActiveProperties().Count()); } }
public void TestAlterEntity_ChangeTable() { using (Stream stream = Resources.GetXmlDocumentStream("suppressed")) { Assert.IsNotNull(stream); WXMLModel newModel = WXMLModel.LoadFromXml(new XmlTextReader(stream)); Assert.IsNotNull(newModel); Assert.AreEqual(2, newModel.GetActiveEntities().Count()); EntityDefinition e = newModel.GetActiveEntities().Single(item => item.Identifier == "e1"); Assert.AreEqual(1, e.GetSourceFragments().Count()); Assert.AreEqual(1, newModel.GetSourceFragments().Count()); Assert.AreEqual("tbl1", e.GetSourceFragments().First().Name); Assert.IsTrue(string.IsNullOrEmpty(e.GetSourceFragments().First().Selector)); SourceFragmentRefDefinition sf = new SourceFragmentRefDefinition( newModel.GetOrCreateSourceFragment("dbo", "table")); //foreach (SourceFragmentRefDefinition rsf in e.GetSourceFragments()) //{ // e.MarkAsDeleted(rsf); //} e.ClearSourceFragments(); e.AddSourceFragment(sf); foreach (PropertyDefinition property in e.GetProperties()) { property.SourceFragment = sf; } WXMLModel model = GetModel("suppressed"); model.Merge(Normalize(newModel)); e = model.GetActiveEntities().Single(item => item.Identifier == "e1"); Assert.AreEqual(1, e.GetSourceFragments().Count()); Assert.AreEqual(2, model.GetSourceFragments().Count()); Assert.AreEqual("table", e.GetSourceFragments().First().Name); Assert.AreEqual("dbo", e.GetSourceFragments().First().Selector); e = model.GetActiveEntities().Single(item => item.Identifier == "e11"); Assert.AreEqual(1, e.GetSourceFragments().Count()); Assert.AreEqual("table", e.GetSourceFragments().First().Name); Assert.AreEqual("dbo", e.GetSourceFragments().First().Selector); } }