/// <summary> /// Load a new project, optionally selecting the config and fire events /// </summary> public void LoadProject(string filePath, string configName) { try { events.FireProjectLoading(filePath); NUnitProject newProject = NUnitProject.LoadProject(filePath); if (configName != null) { newProject.SetActiveConfig(configName); newProject.IsDirty = false; } OnProjectLoad(newProject); // return true; } catch (Exception exception) { lastException = exception; events.FireProjectLoadFailed(filePath, exception); // return false; } }
/// <summary> /// Load a new project, optionally selecting the config and fire events /// </summary> public void LoadProject(string filePath, string configName) { try { log.Info("Loading project {0}, {1} config", filePath, configName == null ? "default" : configName); events.FireProjectLoading(filePath); NUnitProject newProject = Services.ProjectService.LoadProject(filePath); if (configName != null) { newProject.SetActiveConfig(configName); newProject.IsDirty = false; } OnProjectLoad(newProject); } catch (Exception exception) { log.Error("Project load failed", exception); lastException = exception; events.FireProjectLoadFailed(filePath, exception); } }
private TestPackage GetTestPackage(string projectFileName, NUnitParameters nUnitParameters) { if (!NUnitProject.IsNUnitProjectFile(projectFileName)) return new TestPackage(projectFileName); var nunitProject = new NUnitProject(projectFileName); nunitProject.Load(); if (!string.IsNullOrEmpty(nUnitParameters.Configuration)) nunitProject.SetActiveConfig(nUnitParameters.Configuration); return nunitProject.ActiveConfig.MakeTestPackage(); }
/// <summary> /// Gets the NUnit test result. /// </summary> /// <param name="test">The test.</param> /// <param name="project">The project.</param> /// <param name="configurationSubstitutions">The configuration substitutions.</param> /// <param name="isChild">if set to <c>true</c> [is child].</param> /// <returns></returns> public TestResult GetNUnitTestResult(TestUnit test, TestProject project, DistributedConfigurationSubstitutions configurationSubstitutions, bool isChild = false) { var nativeRunner = runnerCache.GetOrLoad(test.Run, configurationSubstitutions, () => { initializer.Initialize(); string configurationFileName = configurationOperator.GetSubstitutedConfigurationFile(project, test.Run. NUnitParameters, configurationSubstitutions); var mappedAssemblyFile = Path.Combine(project.Path, Path.GetFileName( test.Run.NUnitParameters. AssembliesToTest[0])); TestPackage package; if (!NUnitProject.IsNUnitProjectFile(mappedAssemblyFile)) package = new TestPackage(mappedAssemblyFile); else { var nunitProject = new NUnitProject(mappedAssemblyFile); nunitProject.Load(); if (!string.IsNullOrEmpty(test.Run.NUnitParameters.Configuration)) nunitProject.SetActiveConfig(test.Run.NUnitParameters.Configuration); package = nunitProject.ActiveConfig.MakeTestPackage(); } package.Settings["ShadowCopyFiles"] = true; package.AutoBinPath = true; if (!string.IsNullOrEmpty(configurationFileName)) { package.ConfigurationFile = configurationFileName; } var nativeTestRunner = new NDistribUnitProcessRunner(log); nativeTestRunner.Load(package); return nativeTestRunner; }); var testOptions = test.Run.NUnitParameters; TestResult testResult = null; try { Action runTest = ()=> { try { testResult = nativeRunner.Run(new NullListener(), new NUnitTestsFilter( testOptions.IncludeCategories, testOptions.ExcludeCategories, test.UniqueTestId).NativeFilter); nativeRunner.CleanupAfterRun(); } //TODO: remove this. This is for tracking purposes only catch(AppDomainUnloadedException ex) { log.Warning("AppDomainUnloadedException is still being thrown", ex); if (!isChild) { runnerCache.Remove(test.Run, configurationSubstitutions); testResult = GetNUnitTestResult(test, project, configurationSubstitutions, isChild: true); } else throw; } }; if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA && !Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA)) { var thread = new Thread(()=> exceptionCatcher.Run(runTest)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); } else { runTest(); } } catch (Exception ex) { log.Error("Error while running test on agent", ex); throw; } return testResult; }