private void CreateNodesFor(ITestAssembly ta, int assemblyNodePosition) { TestFixtureInfoCollection tests = ta.TestFixtureInfos; SmartTreeNode root = CreateOrFindAssemblyNode(ta, assemblyNodePosition); foreach (TestFixtureInfo tf in tests) { SmartTreeNode classNode = CreateOrFindClassNode(ta, root.Nodes, tf.FullName.Split(new char[] { '.', '+' }), 0); classNode.Tag = new UiElementInfo(ta, tf, null); classNode.ImageIndex = 2; foreach (TestMethodInfo tm in tf.TestMethods) { SmartTreeNode methodNode = CreateOrFindMethodNode(classNode.Nodes, tm); methodNode.Tag = new UiElementInfo(ta, tf, tm); } } TreeViewEventHandler temp = AfterSelect; AfterSelect = null; try { RestoreCheckState(root); SetCheckedStatus(_treeTestHierarchy.Nodes); } finally { AfterSelect = temp; } if (_config.AutoExpandTestHierarchy) { root.ExpandAll(); } }
/// <summary> /// Runs the tests using the remote loader constructed in the LoadAssembly /// method. /// </summary> private void ThreadProc() { AppDomain appDomain = null; RuntimeHelpers.PrepareConstrainedRegions(); try { _appDomain = null; appDomain = CreateRemoteDomain(); #if DEBUG Debug.WriteLine(string.Format("Worker thread {0} executing in appdomain '{1}'", Thread.CurrentThread.ManagedThreadId, appDomain.FriendlyName)); #endif var currentFullName = _assemblyName.FullName; var currentModifiedTimeStamp = ModifiedTimeStamp; using (var remoteLoader = LoadAssembly(appDomain)) { TestFixtureInfos = remoteLoader.TestFixtureInfos; _modifiedTimeStamp = remoteLoader.ModifiedTimeStamp; if (_assemblyName.FullName != currentFullName || ModifiedTimeStamp != currentModifiedTimeStamp) { if (AssemblyChanged != null) { AssemblyChanged(this, new AssemblyEventArgs(_assemblyName.FullName, _assemblyName.CodeBase)); } } remoteLoader.Listener = _listener; remoteLoader.RunTests(_testRun, _twConsole); remoteLoader.Dispose(); } } catch (ThreadAbortException ex) { _appDomain = appDomain; Debug.WriteLine("Worker thread has aborted because: " + ex.Message); Debug.WriteLine(ex.ToString()); } catch (Exception ex) { _appDomain = appDomain; if (TestsAborted != null) { TestsAborted(null, new AssemblyEventArgs(_assemblyName.FullName, _assemblyName.CodeBase)); } Debug.WriteLine("Worker thread has terminated because: " + ex.Message); Debug.WriteLine(ex.ToString()); } finally { if (appDomain != null && _appDomain == null) { TearDownAppDomain(appDomain); } // _workerThread = null; _testRun = null; } }
private Test BuildAssemblyTest_Native(IAssemblyInfo assembly, string location) { if (String.IsNullOrEmpty(location)) { throw new ArgumentNullException("location"); } // If csUnit.Core is not in the GAC then it must be in the assembly path due to a // bug in csUnit setting up the AppDomain. It sets the AppDomain's base directory // to the assembly directory and sets its PrivateBinPath to the csUnit directory // which is incorrect (PrivateBinPath only specifies directories relative to the app base) // so it does actually not ensure that csUnit.Core can be loaded as desired. Assembly csUnitCoreAssembly = typeof(csUnit.Core.Loader).Assembly; if (!csUnitCoreAssembly.GlobalAssemblyCache) { string csUnitAppBase = Path.GetDirectoryName(location); string csUnitCoreAssemblyPathExpected = Path.Combine(csUnitAppBase, "csUnit.Core.dll"); if (!File.Exists(csUnitCoreAssemblyPathExpected)) { return(CreateAssemblyTest(assembly, location, delegate(Test assemblyTest) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, null, string.Format("Cannot load csUnit tests from '{0}'. " + "'csUnit.Core.dll' and related DLLs must either be copied to the same directory as the test assembly or must be installed in the GAC.", location))); })); } } // Load the assembly using the native CSUnit loader. using (Loader loader = new Loader(location)) { // Construct the test tree return(CreateAssemblyTest(assembly, location, delegate(Test assemblyTest) { TestFixtureInfoCollection collection = loader.TestFixtureInfos; if (collection == null) { return; } foreach (ITestFixtureInfo fixtureInfo in collection) { try { ITypeInfo fixtureType = assembly.GetType(fixtureInfo.FullName); assemblyTest.AddChild(CreateFixtureFromType(fixtureType, delegate(Test fixtureTest) { if (fixtureInfo.TestMethods == null) { return; } foreach (ITestMethodInfo testMethodInfo in fixtureInfo.TestMethods) { try { IMethodInfo methodType = fixtureType.GetMethod(testMethodInfo.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public); fixtureTest.AddChild(CreateTestFromMethod(methodType, null)); } catch (Exception ex) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, fixtureType, "An exception was thrown while exploring a csUnit test case.", ex)); } } })); } catch (Exception ex) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly, "An exception was thrown while exploring a csUnit test fixture.", ex)); } } })); } }