예제 #1
0
        public void TestFillEntityTables()
        {
            Worm_CodeGen_Core_OrmXmlParserAccessor parser;

            parser = null;
            using (XmlReader rdr = XmlReader.Create(GetSampleFileStream()))
            {
                object privateParser = Worm_CodeGen_Core_OrmXmlParserAccessor.CreatePrivate(rdr);
                parser = new Worm_CodeGen_Core_OrmXmlParserAccessor(privateParser);
                parser.Read();
            }

            parser.FillSourceFragments();
            parser.FindEntities();


            WXMLModel ormObjectDef = parser.Model;

            EntityDefinition entity = ormObjectDef.GetEntities()
                                      .Single(match => match.Identifier == "eArtist" && match.Name == "Artist");

            Assert.AreEqual <int>(2, entity.GetSourceFragments().Count());
            Assert.IsTrue(entity.GetSourceFragments().Any(match => match.Identifier.Equals("tblArtists") &&
                                                          match.Name.Equals("artists")));
            Assert.IsTrue(entity.GetSourceFragments().Any(match => match.Identifier.Equals("tblSiteAccess") &&
                                                          match.Name.Equals("sites_access")));
        }
예제 #2
0
        public void TestFillUnify()
        {
            MSSQLProvider p = new MSSQLProvider(GetTestDB(), null);

            SourceView sv = p.GetSourceView(null, "aspnet_Membership, aspnet_Users");

            WXMLModel model = new WXMLModel();

            SourceToModelConnector c = new SourceToModelConnector(sv, model);

            c.ApplySourceViewToModel(false, relation1to1.Unify, true, true, false);

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

            Assert.AreEqual(1, model.GetEntities().Count());

            Assert.AreEqual(2, model.GetEntities().Single().GetSourceFragments().Count());
        }
예제 #3
0
        public void TestFindEntities()
        {
            Worm_CodeGen_Core_OrmXmlParserAccessor parser = null;

            using (XmlReader rdr = XmlReader.Create(GetSampleFileStream()))
            {
                object privateParser = Worm_CodeGen_Core_OrmXmlParserAccessor.CreatePrivate(rdr);
                parser = new Worm_CodeGen_Core_OrmXmlParserAccessor(privateParser);
                parser.Read();
            }
            parser.FillSourceFragments();
            parser.FindEntities();

            WXMLModel ormObjectDef = parser.Model;

            Assert.AreEqual <int>(6, ormObjectDef.GetEntities().Count());
            Assert.AreEqual <int>(5, ormObjectDef.GetActiveEntities().Count());
            Assert.IsTrue(ormObjectDef.GetEntities().Any(delegate(EntityDefinition match) { return(match.Identifier == "eArtist" && match.Name == "Artist"); }));
            Assert.IsTrue(ormObjectDef.GetEntities().Any(delegate(EntityDefinition match) { return(match.Identifier == "eAlbum" && match.Name == "Album"); }));
            Assert.IsTrue(ormObjectDef.GetEntities().Any(delegate(EntityDefinition match) { return(match.Identifier == "Album2ArtistRelation" && match.Name == "Album2ArtistRelation"); }));
        }
예제 #4
0
        public void TestFillModel4()
        {
            MSSQLProvider p = new MSSQLProvider(GetTestDB(), null);

            SourceView sv = p.GetSourceView(null, "aspnet_Membership, 3to3");

            WXMLModel model = new WXMLModel();

            SourceToModelConnector c = new SourceToModelConnector(sv, model);

            c.ApplySourceViewToModel();

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

            Assert.AreEqual(2, model.GetEntities().Count());
        }
예제 #5
0
        public void TestFillModel3()
        {
            MSSQLProvider p = new MSSQLProvider(GetTestDB(), null);

            SourceView sv = p.GetSourceView(null, "complex_fk");

            WXMLModel model = new WXMLModel();

            SourceToModelConnector c = new SourceToModelConnector(sv, model);

            c.ApplySourceViewToModel();

            Assert.AreEqual(1, model.GetSourceFragments().Count());

            Assert.AreEqual(1, model.GetEntities().Count());
        }
예제 #6
0
        public void TestFillPropertiesWithGroups()
        {
            Worm_CodeGen_Core_OrmXmlParserAccessor parser;

            using (XmlReader rdr = XmlReader.Create(GetFile("groups")))
            {
                object privateParser = Worm_CodeGen_Core_OrmXmlParserAccessor.CreatePrivate(rdr, new TestXmlUrlResolver());
                parser = new Worm_CodeGen_Core_OrmXmlParserAccessor(privateParser);
                parser.Read();
            }

            parser.FillSourceFragments();
            parser.FindEntities();
            parser.FillImports();
            parser.FillTypes();

            WXMLModel model = parser.Model;

            EntityDefinition entity = model.GetEntities()
                                      .Single(match => match.Identifier == "e1");

            parser.FillProperties(entity);

            Assert.AreEqual <int>(7, entity.OwnProperties.Count());

            PropertyDefinition prop = entity.GetProperty("Identifier1");

            Assert.IsNull(prop);
            prop = entity.GetProperty("ID");
            Assert.IsNotNull(prop);

            Assert.IsNull(prop.Group);

            prop = entity.GetProperty("prop1");
            Assert.IsNotNull(prop);
            Assert.IsNotNull(prop.Group);
            Assert.AreEqual("grp", prop.Group.Name);
            Assert.IsTrue(prop.Group.Hide);

            prop = entity.GetProperty("prop4");
            Assert.IsNotNull(prop);
            Assert.IsNotNull(prop.Group);
            Assert.AreEqual("grp1", prop.Group.Name);
            Assert.IsFalse(prop.Group.Hide);
        }
예제 #7
0
        public EntityDefinition(string id, string name, string @namespace, string description,
                                WXMLModel model, EntityDefinition baseEntity, EntityBehaviuor behaviour)
        {
            _id                     = id;
            _name                   = name;
            _description            = description;
            _sourceFragments        = new List <SourceFragmentRefDefinition>();
            _properties             = new List <PropertyDefinition>();
            _suppressedProperties   = new List <string>();
            _model                  = model;
            EntitySpecificNamespace = @namespace;
            _baseEntity             = baseEntity;
            Behaviour               = behaviour;

            if (model != null && !model.GetEntities().Any(item => item.Identifier == id))
            {
                model.AddEntity(this);
            }

            Interfaces = new Dictionary <string, TypeDefinition>();
        }
예제 #8
0
        public void TestFillHierarchy()
        {
            MSSQLProvider p = new MSSQLProvider(GetTestDB(), null);

            SourceView sv = p.GetSourceView(null, "aspnet_Membership, aspnet_Users");

            WXMLModel model = new WXMLModel();

            SourceToModelConnector c = new SourceToModelConnector(sv, model);

            c.ApplySourceViewToModel();

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

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

            EntityDefinition membership = model.GetEntity("e_dbo_aspnet_Membership");

            Assert.IsNotNull(membership);

            EntityDefinition users = model.GetEntity("e_dbo_aspnet_Users");

            Assert.IsNotNull(users);

            Assert.AreEqual(membership.BaseEntity, users);

            Assert.AreEqual(2, membership.GetSourceFragments().Count());

            Assert.AreEqual(1, membership.OwnSourceFragments.Count());

            Assert.AreEqual(1, users.GetSourceFragments().Count());

            Assert.AreEqual(1, users.OwnSourceFragments.Count());

            Assert.IsNull(users.BaseEntity);
        }
예제 #9
0
        public void TestCompareLinqCtxMoreTables()
        {
            MSSQLProvider p = new MSSQLProvider(GetTestDB(), null);

            SourceView sv = p.GetSourceView(null, "ent1,ent2,1to2,ent3,3to3,complex_pk,complex_fk,aspnet_Applications,aspnet_Membership,aspnet_Users");

            Assert.AreEqual(10, sv.GetSourceFragments().Count());

            WXMLModel model = new WXMLModel();

            SourceToModelConnector c = new SourceToModelConnector(sv, model);

            c.ApplySourceViewToModel(false, relation1to1.Default, false, false, false);

            Assert.AreEqual(10, model.GetSourceFragments().Count());

            Assert.AreEqual(8, model.GetEntities().Count());

            model.LinqSettings = new LinqSettingsDescriptor
            {
                ContextName = "TestCtxDataContext"
            };

            model.Namespace = "LinqCodeGenTests";

            LinqContextGenerator gen = new LinqContextGenerator(model, new WXML.CodeDom.WXMLCodeDomGeneratorSettings());

            Console.WriteLine(gen.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp));

            Assembly assembly = gen.Compile(LinqToCodedom.CodeDomGenerator.Language.CSharp);

            Assert.IsNotNull(assembly);

            Type ctxType = assembly.GetType(
                string.IsNullOrEmpty(model.Namespace) ? model.LinqSettings.ContextName
                    : model.Namespace + "." + model.LinqSettings.ContextName
                );

            Assert.IsNotNull(ctxType);

            DataContext ctx = (DataContext)Activator.CreateInstance(ctxType, GetTestDBConnectionString());

            Assert.IsNotNull(ctx);

            ctx.Log = Console.Out;

            TestCtxDataContext realCtx = new TestCtxDataContext(GetTestDBConnectionString());

            Type rctxType = typeof(TestCtxDataContext);

            foreach (PropertyInfo pi in ctxType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                PropertyInfo rpi = rctxType.GetProperties().SingleOrDefault(item => item.Name == pi.Name);

                Assert.IsNotNull(rpi, "Cannot find property {0}", pi.Name);

                Assert.AreEqual(rpi.Attributes, pi.Attributes);
                Assert.AreEqual(rpi.CanRead, pi.CanRead);
                Assert.AreEqual(rpi.CanWrite, pi.CanWrite);

                Assert.AreEqual(rpi.GetGetMethod().Attributes, pi.GetGetMethod().Attributes);

                IListSource ent1s = (IListSource)pi.GetValue(ctx, null);

                Assert.IsNotNull(ent1s.GetList());

                Assert.AreEqual(((IListSource)rpi.GetValue(realCtx, null)).GetList().Count, ent1s.GetList().Count);
            }
        }
예제 #10
0
        public void TestFillProperties()
        {
            Worm_CodeGen_Core_OrmXmlParserAccessor parser;

            using (XmlReader rdr = XmlReader.Create(GetSampleFileStream()))
            {
                object privateParser = Worm_CodeGen_Core_OrmXmlParserAccessor.CreatePrivate(rdr);
                parser = new Worm_CodeGen_Core_OrmXmlParserAccessor(privateParser);
                parser.Read();
            }

            parser.FillSourceFragments();
            parser.FindEntities();
            parser.FillImports();
            parser.FillTypes();


            WXMLModel ormObjectDef = parser.Model;

            EntityDefinition entity = ormObjectDef.GetEntities()
                                      .Single(match => match.Identifier == "eArtist" && match.Name == "Artist");

            parser.FillProperties(entity);

            Assert.AreEqual <int>(8, entity.OwnProperties.Count());

            ScalarPropertyDefinition prop = (ScalarPropertyDefinition)entity.GetProperty("ID");

            Assert.IsNotNull(prop);
            //Assert.AreEqual<int>(1, prop.Attributes.Length, "Attributes is undefined");
            Assert.AreEqual <string>("PK", prop.Attributes.ToString(), "Attributes is not correct defined");
            Assert.IsNotNull(prop.SourceFragment, "Table is undefined");
            Assert.AreEqual <string>("tblArtists", prop.SourceFragment.Identifier, "Table.Identifier is undefined");
            Assert.AreEqual <string>("id", prop.SourceFieldExpression, "FieldName is undefined");
            Assert.AreEqual <string>("System.Int32", prop.PropertyType.GetTypeName(null), "PropertyTypeString is undefined");
            Assert.AreEqual <string>("Property ID Description", prop.Description, "Description is undefined");
            Assert.AreEqual <AccessLevel>(AccessLevel.Private, prop.FieldAccessLevel, "FieldAccessLevel");
            Assert.AreEqual <AccessLevel>(AccessLevel.Public, prop.PropertyAccessLevel, "PropertyAccessLevel");
            Assert.AreEqual <string>(prop.Name, prop.PropertyAlias, "PropertyAlias");

            prop = (ScalarPropertyDefinition)entity.GetProperty("Title");
            Assert.IsNotNull(prop);
            //Assert.AreEqual<int>(0, prop.Attributes.Length, "Attributes is undefined");
            Assert.IsNotNull(prop.SourceFragment, "Table is undefined");
            Assert.AreEqual <string>("tblArtists", prop.SourceFragment.Identifier, "Table.Identifier is undefined");
            Assert.AreEqual <string>("name", prop.SourceFieldExpression, "FieldName is undefined");
            Assert.AreEqual <string>("System.String", prop.PropertyType.GetTypeName(null), "PropertyTypeString is undefined");
            Assert.AreEqual <string>("Property Title Description", prop.Description, "Description");
            Assert.AreEqual <AccessLevel>(AccessLevel.Private, prop.FieldAccessLevel, "FieldAccessLevel");
            Assert.AreEqual <AccessLevel>(AccessLevel.Assembly, prop.PropertyAccessLevel, "PropertyAccessLevel");
            Assert.AreEqual <string>(prop.Name, prop.PropertyAlias, "PropertyAlias");

            prop = (ScalarPropertyDefinition)entity.GetProperty("DisplayTitle");
            Assert.IsNull(prop);
            prop = (ScalarPropertyDefinition)entity.GetProperty("DisplayName");
            Assert.IsNotNull(prop);
            Assert.AreEqual <string>("DisplayTitle", prop.Name, "Name is undefined");
            //Assert.AreEqual<int>(0, prop.Attributes.Length, "Attributes is undefined");
            Assert.IsNotNull(prop.SourceFragment, "Table is undefined");
            Assert.AreEqual <string>("tblArtists", prop.SourceFragment.Identifier, "Table.Identifier is undefined");
            Assert.AreEqual <string>("display_name", prop.SourceFieldExpression, "FieldName is undefined");
            Assert.AreEqual <string>("System.String", prop.PropertyType.GetTypeName(null), "PropertyTypeString is undefined");
            Assert.AreEqual <string>("Property Title Description", prop.Description, "Property Title Description");
            Assert.AreEqual <AccessLevel>(AccessLevel.Family, prop.FieldAccessLevel, "FieldAccessLevel");
            Assert.AreEqual <AccessLevel>(AccessLevel.Family, prop.PropertyAccessLevel, "PropertyAccessLevel");
            Assert.AreEqual <string>("DisplayName", prop.PropertyAlias, "PropertyAlias");

            prop = (ScalarPropertyDefinition)entity.GetProperty("Fact");

            //Assert.AreEqual<int>(1, prop.Attributes.Length, "Attributes.Factory absent");
            Assert.AreEqual <string>("Factory", prop.Attributes.ToString(), "Attributes.Factory invalid");

            prop = (ScalarPropertyDefinition)entity.GetProperty("TestInsDef");

            //Assert.AreEqual<int>(1, prop.Attributes.Length, "Attributes.Factory absent");
            Assert.AreEqual <string>("InsertDefault", prop.Attributes.ToString(), "Attributes.InsertDefault invalid");

            prop = (ScalarPropertyDefinition)entity.GetProperty("TestNullabe");

            Assert.AreEqual <Type>(typeof(int?), prop.PropertyType.ClrType);
            Assert.IsFalse(prop.Disabled, "Disabled false");

            prop = (ScalarPropertyDefinition)entity.GetProperty("TestDisabled");
            Assert.IsTrue(prop.Disabled, "Disabled true");
        }