예제 #1
0
        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());
            }
        }
예제 #2
0
        public void TestAddType()
        {
            using (Stream stream = Resources.GetXmlDocumentStream("suppressed"))
            {
                Assert.IsNotNull(stream);

                WXMLModel model = WXMLModel.LoadFromXml(new XmlTextReader(stream));

                Assert.IsNotNull(model);

                Assert.AreEqual(2, model.GetTypes().Count());

                WXMLModel newModel = new WXMLModel();

                TypeDefinition newType = new TypeDefinition("tInt16", typeof(short));

                newModel.AddType(newType);

                model.Merge(Normalize(newModel));

                Assert.AreEqual(3, model.GetTypes().Count());
            }
        }
예제 #3
0
        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);
            }
        }