Beispiel #1
0
        public void TestGenerateEmpty()
        {
            WXMLModel model = new WXMLModel();

            Assert.IsNotNull(model);

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

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

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

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

            Assert.IsNotNull(gen.Compile(LinqToCodedom.CodeDomGenerator.Language.VB));

            Assert.IsNotNull(gen.Compile(LinqToCodedom.CodeDomGenerator.Language.CSharp));
        }
Beispiel #2
0
        public void TestGenerate()
        {
            using (Stream stream = Resources.GetXmlDocumentStream("sample1"))
            {
                Assert.IsNotNull(stream);

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

                Assert.IsNotNull(model);

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

                //CodeCompileFileUnit u = gen.GetFullSingleUnit(LinqToCodedom.CodeDomGenerator.Language.VB);

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

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

                Assert.IsNotNull(gen.Compile(LinqToCodedom.CodeDomGenerator.Language.VB));

                Assert.IsNotNull(gen.Compile(LinqToCodedom.CodeDomGenerator.Language.CSharp));
            }
        }
Beispiel #3
0
        public void TestAdventureWorksLinq()
        {
            SourceView view;

            BinaryFormatter f = new BinaryFormatter();

            ResolveEventHandler d = null;

            d = (sender, args) =>
            {
                AppDomain.CurrentDomain.AssemblyResolve -= d;
                return(typeof(WXMLModel).Assembly);
            };
            AppDomain.CurrentDomain.AssemblyResolve += d;

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (Stream fs = assembly.GetManifestResourceStream(
                       string.Format("{0}.Files.{1}", assembly.GetName().Name, "AdventureWorks.sourceview")))
            {
                Assert.IsNotNull(fs);
                view = (SourceView)f.Deserialize(fs);
            }

            Assert.IsNotNull(view);

            WXMLModel model = new WXMLModel
            {
                LinqSettings = new LinqSettingsDescriptor
                {
                    ContextName = "TestCtxDataContext"
                },
                Namespace = "LinqCodeGenTests"
            };

            SourceToModelConnector c = new SourceToModelConnector(view, model);

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

            LinqContextGenerator gen = new LinqContextGenerator(model);

            Console.WriteLine(gen.GenerateCode(LinqToCodedom.CodeDomGenerator.Language.CSharp));
        }
Beispiel #4
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);
            }
        }