private static void InvokeTestMethod(StiDriverParameters driverParameters) { MethodBase methodToInvoke = GetMethodBaseFromLooselyTypedArguments(driverParameters.Class, driverParameters.Method, driverParameters.MethodParams); object[] methodParameters = new object[driverParameters.MethodParams.Length]; TypeConvertParameters(methodToInvoke, driverParameters.MethodParams, ref methodParameters); if (methodToInvoke.IsStatic) { methodToInvoke.Invoke(null, methodParameters); } else { if (driverParameters.Class.IsAbstract) { throw new TargetException("Non-static method " + methodToInvoke.Name + " on abstract class " + driverParameters.Class.Name + " cannot be invoked."); } MethodBase constructorToInvoke = GetMethodBaseFromLooselyTypedArguments(driverParameters.Class, driverParameters.Class.Name, driverParameters.CtorParams); if (constructorToInvoke == null) { throw new MissingMethodException("No constructor with matching signature found."); } else if (constructorToInvoke as ConstructorInfo == null) { throw new TargetException("MethodBase with name matching class name was not a ConstructorInfo."); } object[] ctorParameters = new object[driverParameters.CtorParams.Length]; TypeConvertParameters(constructorToInvoke, driverParameters.CtorParams, ref ctorParameters); object testObj = (constructorToInvoke as ConstructorInfo).Invoke(ctorParameters); methodToInvoke.Invoke(testObj, methodParameters); } }
// This method needs to be public because it is given as an AppDomain callback, and if // the created appdomain is partial trust, non-public accessibility throws a security exception. public static void ExecuteTestCase(string[] args) { StiDriverParameters driverParameters = new StiDriverParameters(DriverState.DriverParameters, args); #if TESTBUILD_CLR20 StiUtilities.ApplySecurityPolicy(driverParameters.SecurityLevel); #endif bool hasNext = false; do { driverParameters = new StiDriverParameters(DriverState.DriverParameters, args); LogManager.BeginTest(DriverState.TestName); try { LogReproArguments(); InvokeTestMethod(driverParameters); // If there is an open variation, we need to close it down so we can end the test. if (Variation.Current != null) { if (Variation.Current.Result != null) { Variation.Current.LogMessage("FAILURE: Test did not close its variation. Because it already logged a result, we will close it and create a synthetic variation to report failure."); Variation.Current.Close(); Log.Current.CreateVariation("Variation not closed synthetic variation"); } Variation.Current.LogMessage("FAILURE: Test did not close its variation."); Variation.Current.LogResult(Result.Fail); Variation.Current.Close(); } } catch (Exception exception) { // If there is an open variation, we need to close it down so we can end the test. if (Variation.Current != null) { Variation.Current.LogObject(exception.ToString()); Variation.Current.LogResult(Result.Fail); Variation.Current.Close(); } else { LogManager.LogMessageDangerously(exception.ToString()); } } finally { LogManager.LogMessageDangerously(string.Format(CultureInfo.InvariantCulture, "Repro Arguments: /Name={0} /Area={1} /SubArea={2}", DriverState.TestName, DriverState.TestArea, DriverState.TestSubArea)); LogManager.EndTest(); } hasNext = DriverState.HasNext(); if (hasNext) { DriverState.Next(); } } while (hasNext); }