public void TestAddProperty() { using (Stream stream = Resources.GetXmlDocumentStream("suppressed")) { Assert.IsNotNull(stream); WXMLModel model = WXMLModel.LoadFromXml(new XmlTextReader(stream)); Assert.IsNotNull(model); EntityDefinition entity = model.GetActiveEntities().Single(item => item.Identifier == "e1"); Assert.IsNotNull(entity); Assert.AreEqual(2, model.GetActiveEntities().Count()); Assert.AreEqual(2, entity.GetActiveProperties().Count()); WXMLModel newModel = new WXMLModel(); EntityDefinition newEntity = new EntityDefinition(entity.Identifier, entity.Name, entity.Namespace, entity.Description, newModel); //newModel.AddEntity(newEntity); TypeDefinition tString = model.GetTypes().Single(item => item.Identifier == "tString"); newModel.AddType(tString); SourceFragmentRefDefinition newTable = entity.GetSourceFragments().First(); newModel.AddSourceFragment(newTable); newEntity.AddSourceFragment(newTable); newEntity.AddProperty(new ScalarPropertyDefinition(newEntity, "Prop2", "Prop2", Field2DbRelations.None, null, tString, new SourceFieldDefinition(newTable, "prop2"), AccessLevel.Private, AccessLevel.Public)); model.Merge(Normalize(newModel)); Assert.AreEqual(2, model.GetActiveEntities().Count()); Assert.AreEqual(3, entity.GetActiveProperties().Count()); } }
private void ProcessOne2Many() { foreach (EntityDefinition e_ in Model.GetEntities()) { EntityDefinition e = e_; foreach (EntityDefinition oe_ in from k in Model.GetActiveEntities() where /*k != e && */ !e.One2ManyRelations.Any(item => !item.Disabled && item.Entity.Identifier == k.Identifier) select k) { EntityDefinition oe = oe_; var entityProps = oe.GetActiveProperties() .Where(item => item.PropertyType.IsEntityType && item.PropertyType.Entity.Identifier == e.Identifier) .Cast <EntityPropertyDefinition>(); int idx = 1; foreach (EntityPropertyDefinition pd in entityProps) { int cnt = Model.GetActiveRelations().OfType <RelationDefinition>().Count(r => (r.Left.Entity.Identifier == oe.Identifier && r.Right.Entity.Identifier == e.Identifier) || (r.Left.Entity.Identifier == e.Identifier && r.Right.Entity.Identifier == oe.Identifier)); string accName = null; string prop = null; if (cnt > 0 || entityProps.Count() > 1) { accName = WXMLCodeDomGeneratorNameHelper.GetMultipleForm(oe.Name + idx); prop = pd.Name; } e.AddEntityRelations(new EntityRelationDefinition() { Entity = oe, SourceEntity = e, AccessorName = accName, PropertyAlias = prop, }); idx++; } } } }
public void TestAlterProperty() { using (Stream stream = Resources.GetXmlDocumentStream("suppressed")) { Assert.IsNotNull(stream); WXMLModel model = WXMLModel.LoadFromXml(new XmlTextReader(stream)); Assert.IsNotNull(model); EntityDefinition entity = model.GetActiveEntities().Single(item => item.Identifier == "e1"); Assert.IsNotNull(entity); Assert.AreEqual(2, entity.GetActiveProperties().Count()); var p = entity.GetActiveProperties().SingleOrDefault(item => item.PropertyAlias == "Prop1"); Assert.IsNotNull(p); Assert.IsFalse(p.FromBase); Assert.AreEqual("Prop1", p.Name); WXMLModel newModel = new WXMLModel(); ScalarPropertyDefinition oldProp = ((ScalarPropertyDefinition)p).Clone(); Assert.IsFalse(oldProp.FromBase); TypeDefinition newType = new TypeDefinition("tInt16", typeof(short)); newModel.AddType(newType); EntityDefinition newEntity = new EntityDefinition(entity.Identifier, entity.Name, entity.Namespace, entity.Description, newModel); //newModel.AddEntity(newEntity); ScalarPropertyDefinition newProp = new ScalarPropertyDefinition(newEntity, "Prop2") { PropertyAlias = "Prop1", PropertyType = newType }; newEntity.AddProperty(newProp); model.Merge(Normalize(newModel)); Assert.AreEqual(2, entity.GetActiveProperties().Count()); ScalarPropertyDefinition renewProp = (ScalarPropertyDefinition)entity.GetActiveProperties() .Single(item => item.PropertyAlias == "Prop1"); Assert.AreEqual("Prop2", renewProp.Name); Assert.AreEqual(oldProp.DefferedLoadGroup, renewProp.DefferedLoadGroup); Assert.AreEqual(oldProp.AvailableFrom, renewProp.AvailableFrom); Assert.AreEqual(oldProp.AvailableTo, renewProp.AvailableTo); Assert.AreEqual(oldProp.Description, renewProp.Description); Assert.AreEqual(oldProp.Disabled, renewProp.Disabled); Assert.AreEqual(oldProp.EnablePropertyChanged, renewProp.EnablePropertyChanged); Assert.AreEqual(oldProp.FieldAccessLevel, renewProp.FieldAccessLevel); Assert.AreEqual(oldProp.FromBase, renewProp.FromBase); Assert.AreEqual(oldProp.Group, renewProp.Group); Assert.AreEqual(oldProp.IsSuppressed, renewProp.IsSuppressed); Assert.AreEqual(oldProp.Obsolete, renewProp.Obsolete); Assert.AreEqual(oldProp.ObsoleteDescripton, renewProp.ObsoleteDescripton); Assert.AreEqual(oldProp.PropertyAccessLevel, renewProp.PropertyAccessLevel); Assert.AreEqual(oldProp.PropertyAlias, renewProp.PropertyAlias); Assert.AreEqual(oldProp.SourceFragment, renewProp.SourceFragment); Assert.AreEqual(oldProp.SourceType, renewProp.SourceType); Assert.AreEqual(oldProp.IsNullable, renewProp.IsNullable); Assert.AreEqual(oldProp.SourceTypeSize, renewProp.SourceTypeSize); Assert.AreEqual(oldProp.SourceFieldAlias, renewProp.SourceFieldAlias); Assert.AreEqual(oldProp.SourceFieldExpression, renewProp.SourceFieldExpression); } }
private void ImplementIRelation(SelfRelationDefinition relation, EntityDefinition entity, CodeTypeDeclaration entitySchemaDefClass) { entitySchemaDefClass.BaseTypes.Add(new CodeTypeReference(typeof(IRelation))); #region Pair<string, Type> GetFirstType() CodeMemberMethod method = new CodeMemberMethod { Name = "GetFirstType", // тип возвращаемого значения ReturnType = new CodeTypeReference(typeof(IRelation.RelationDesc)), // модификаторы доступа Attributes = MemberAttributes.Public }; // реализует метод базового класса method.ImplementationTypes.Add(typeof(IRelation)); method.Statements.Add( new CodeMethodReturnStatement( new CodeObjectCreateExpression( new CodeTypeReference(typeof(IRelation.RelationDesc)), WXMLCodeDomGeneratorHelper.GetFieldNameReferenceExpression(Settings, entity.GetActiveProperties().OfType <EntityPropertyDefinition>().SingleOrDefault(item => item.SourceFields.Any(sf => relation.Direct.FieldName.Contains(sf.SourceFieldExpression))) , false), new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), "_schema" ), "GetTypeByEntityName" ), new CodePrimitiveExpression(relation.Entity.Name) ), new CodePrimitiveExpression(true) ) ) ); entitySchemaDefClass.Members.Add(method); #endregion Pair<string, Type> GetFirstType() #region Pair<string, Type> GetSecondType() method = new CodeMemberMethod { Name = "GetSecondType", // тип возвращаемого значения ReturnType = new CodeTypeReference(typeof(IRelation.RelationDesc)), // модификаторы доступа Attributes = MemberAttributes.Public }; // реализует метод базового класса method.ImplementationTypes.Add(typeof(IRelation)); method.Statements.Add( new CodeMethodReturnStatement( new CodeObjectCreateExpression( new CodeTypeReference(typeof(IRelation.RelationDesc)), WXMLCodeDomGeneratorHelper.GetFieldNameReferenceExpression(Settings, entity.GetActiveProperties().OfType <EntityPropertyDefinition>().SingleOrDefault(item => item.SourceFields.Any(sf => relation.Reverse.FieldName.Contains(sf.SourceFieldExpression))) , false), new CodeMethodInvokeExpression( new CodeMethodReferenceExpression( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), "_schema" ), "GetTypeByEntityName" ), new CodePrimitiveExpression(relation.Entity.Name) ), new CodePrimitiveExpression(false) ) ) ); entitySchemaDefClass.Members.Add(method); #endregion Pair<string, Type> GetSecondType() }