Exemple #1
0
        private void do_startup()
        {
            // this includes the executable as s[0], which we don't want
            string[] args = Environment.GetCommandLineArgs();
            Debug.Assert(args.Length >= 2, "Unexpected number of args. args[0]=exe, args[1]=dll to test");
            string[] new_args = args.Skip(2).ToArray();

            if (runUnitTest)
            {
                try
                {
                    // Setup the unit test case
                    unitTestMethod = UnitTestsUtil.FindUnitTestMethodByName(testAssembly, unitTestMethodName, new_args.Length);
                    unitTestCase   = UnitTestsUtil.CreateUnitTestCase(unitTestMethod, CreateTestContext(), new_args);
                }
                catch (Exception ex)
                {
                    ReportErrorAndExit(ex.Message, ChessExitCode.TestFailure, false, ex);
                }
            }
            else
            {
                // Use the ChessTest.Startup method
                try
                {
                    if (startup != null)
                    {
                        bool ret = (bool)startup.Invoke(null, new Object[] { new_args });
                        if (!ret)
                        {
                            ReportErrorAndExit(testclass + ".Startup returned false.", ChessExitCode.TestFailure, false, null);
                        }
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    manager.RunFinalizers();
                }
                catch (Exception ex)
                {
                    if (ex is TargetInvocationException)
                    {
                        ex = ((TargetInvocationException)ex).InnerException;
                    }

                    string message = testclass + ".Startup threw unexpected exception: " + ex.GetType();
                    ReportErrorAndExit(message, ChessExitCode.UnitTestException, false, ex);
                }
            }
        }
        internal ManagedTestCase CreateManagedTestCase(TestCaseMetadata runningTestCase)
        {
            XElement xmanagedTestMethod = runningTestCase.TestCase.DataElement.Element(XTestCaseNames.ManagedTestMethod);

            if (xmanagedTestMethod == null)
            {
                throw new Exception("Test case xml missing element " + XTestCaseNames.ManagedTestMethod);
            }

            // Get the test assembly
            Assembly testAssembly = Assembly.LoadFrom((string)xmanagedTestMethod.Attribute("assemblyLocation"));

            // Determine the managed test method
            string     testName   = (string)xmanagedTestMethod.Attribute("fullClassName") + "." + (string)xmanagedTestMethod.Attribute("methodName");
            int        argCount   = runningTestCase.TestArgs == null ? 0 : runningTestCase.TestArgs.Values.Length;
            MethodInfo testMethod = UnitTestsUtil.FindUnitTestMethodByName(testAssembly, testName, argCount);

            // And the args
            object[] args = argCount == 0 ? null : UnitTestsUtil.ParseCommandLineArguments(testMethod, runningTestCase.TestArgs.Values);

            ITestContext context = CreateTestContext(runningTestCase);

            return(new ManagedTestCase(testMethod, context, args));
        }