public static bool RunAllTests() { MethodInfo[] methods = typeof(BinderTracingTest) .GetMethods(BindingFlags.Public | BindingFlags.Static) .Where(m => m.GetCustomAttribute <BinderTestAttribute>() != null && m.ReturnType == typeof(BindOperation)) .ToArray(); foreach (var method in methods) { BinderTestAttribute attribute = method.GetCustomAttribute <BinderTestAttribute>(); if (attribute.Isolate && Environment.GetEnvironmentVariable("COMPlus_GCStress") != null) { continue; } bool success = attribute.Isolate ? RunTestInSeparateProcess(method) : RunSingleTest(method); if (!success) { return(false); } } return(true); }
private static bool RunSingleTest(MethodInfo method) { Console.WriteLine($"Running {method.Name}..."); try { BinderTestAttribute attribute = method.GetCustomAttribute <BinderTestAttribute>(); if (!string.IsNullOrEmpty(attribute.TestSetup)) { MethodInfo setupMethod = method.DeclaringType .GetMethod(attribute.TestSetup, BindingFlags.Public | BindingFlags.Static); Assert.IsTrue(setupMethod != null); setupMethod.Invoke(null, new object[0]); } Func <BindOperation> func = (Func <BindOperation>)method.CreateDelegate(typeof(Func <BindOperation>)); using (var listener = new BinderEventListener()) { BindOperation expected = func(); ValidateSingleBind(listener, expected.AssemblyName.Name, expected); } } catch (Exception e) { Console.WriteLine($"Test {method.Name} failed: {e}"); return(false); } return(true); }
private static bool RunSingleTest(MethodInfo method) { Console.WriteLine($"[{DateTime.Now:T}] Running {method.Name}..."); try { BinderTestAttribute attribute = method.GetCustomAttribute <BinderTestAttribute>(); if (!string.IsNullOrEmpty(attribute.TestSetup)) { MethodInfo setupMethod = method.DeclaringType .GetMethod(attribute.TestSetup, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); Assert.True(setupMethod != null); setupMethod.Invoke(null, new object[0]); } var loadsToTrack = new string[] { Assembly.GetExecutingAssembly().GetName().Name, DependentAssemblyName, $"{DependentAssemblyName}.resources", SubdirectoryAssemblyName, $"{SubdirectoryAssemblyName}.resources", }; if (attribute.AdditionalLoadsToTrack != null) { loadsToTrack = loadsToTrack.Union(attribute.AdditionalLoadsToTrack).ToArray(); } Func <BindOperation> func = (Func <BindOperation>)method.CreateDelegate(typeof(Func <BindOperation>)); using (var listener = new BinderEventListener(loadsToTrack)) { BindOperation expected = func(); ValidateSingleBind(listener, expected.AssemblyName, expected); } } catch (Exception e) { Console.WriteLine($"Test {method.Name} failed: {e}"); return(false); } return(true); }