Пример #1
0
 public void CanCompileModel()
 {
     BuildModel().Compile("ComplexMultiTypes", "ComplexMultiTypes.dll");
     PEVerify.Verify("ComplexMultiTypes.dll");
 }
Пример #2
0
        public void TestDateTimeCanCompileFully()
        {
            var model = CreateModel().Compile("TestDateTimeCanCompileFully", "TestDateTimeCanCompileFully.dll");

            PEVerify.Verify("TestDateTimeCanCompileFully.dll");
        }
Пример #3
0
 public void CanCompileModelFully()
 {
     CreateModel().Compile("InheritanceTests", "InheritanceTests.dll");
     PEVerify.Verify("InheritanceTests.dll", 0, false);
 }
Пример #4
0
 public void TestUriCanCompileFully()
 {
     _ = CreateModel().Compile("TestUriCanCompileFully", "TestUriCanCompileFully.dll");
     PEVerify.Verify("TestUriCanCompileFully.dll");
 }
Пример #5
0
        public void RunTest(Generator test, bool exe, string testName = null)
        {
            if (test == null)
            {
                throw new ArgumentNullException(nameof(test));
            }
            testName = testName ?? GetTestName(test);
            Console.WriteLine(">>> GEN {0}", testName);
            string name = testName;

            string exeDir      = string.Empty;
            string exeFilePath = string.Empty;

            if (exe)
            {
                exeDir      = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                exeFilePath = Path.Combine(exeDir, name + ".exe");
                Directory.CreateDirectory(exeDir);
            }

            AssemblyGen asm;

            asm = !exe
                      ? new AssemblyGen(name, new CompilerOptions())
                      : new AssemblyGen(name, new CompilerOptions()
            {
                OutputPath = exeFilePath
            });
            test(asm);
            if (exe)
            {
                asm.Save();
                PEVerify.AssertValid(exeFilePath);
            }
            Console.WriteLine("=== RUN {0}", testName);

            string[] testArguments = GetTestArguments(test);
#if !FEAT_IKVM
            if (!exe)
            {
#if SILVERLIGHT
                Type entryType = asm.GetAssembly().DefinedTypes.First(t => t.GetMethod("Main", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null);
#else
                Type entryType = ((TypeBuilder)asm.GetAssembly().EntryPoint.DeclaringType).CreateType();
#endif

                MethodInfo entryMethod = entryType.GetMethod(asm.GetAssembly().EntryPoint?.Name ?? "Main", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                object[]   entryArgs   = null;
                if (entryMethod.GetParameters().Length == 1)
                {
                    entryArgs = new object[] { testArguments };
                }
                entryMethod.Invoke(null, entryArgs);
            }
            else
#endif
            {
                try
                {
                    AppDomain.CurrentDomain.ExecuteAssembly(exeFilePath, null, testArguments);
                }
                catch (System.BadImageFormatException)
                {
                    throw;
                }
                catch (AppDomainUnloadedException)
                {
                    throw;
                }
                catch (Exception e)
                {
#if SILVERLIGHT
                    throw;
#else
                    throw new TargetInvocationException(e);
#endif
                }
            }

            Console.WriteLine("<<< END {0}", testName);
            Console.WriteLine();

            if (exe)
            {
                try
                {
                    File.Delete(exeFilePath);
                }
                catch { }
            }
        }
 public void CanBuildAndCompileModel()
 {
     BuildModel().Compile("AbstractListsWithInheritance", "AbstractListsWithInheritance.dll");
     PEVerify.Verify("AbstractListsWithInheritance.dll");
 }