public NUnitProject LoadProject(string path) { if ( NUnitProject.IsNUnitProjectFile(path) ) { NUnitProject project = new NUnitProject( path ); project.Load(); return project; } return ConvertFrom(path); }
public NUnitProject LoadProject(string path) { if (NUnitProject.IsNUnitProjectFile(path)) { NUnitProject project = new NUnitProject(path); project.Load(); return(project); } return(ConvertFrom(path)); }
/// <summary> /// Return a test project by either loading it from /// the supplied path, creating one from a VS file /// or wrapping an assembly. /// </summary> public static NUnitProject LoadProject(string path) { if (NUnitProject.IsProjectFile(path)) { NUnitProject project = new NUnitProject(path); project.Load(); return(project); } else if (VSProject.IsProjectFile(path)) { return(NUnitProject.FromVSProject(path)); } else if (VSProject.IsSolutionFile(path)) { return(NUnitProject.FromVSSolution(path)); } else { return(NUnitProject.FromAssembly(path)); } }
/// <summary> /// Return a test project by either loading it from /// the supplied path, creating one from a VS file /// or wrapping an assembly. /// </summary> public static NUnitProject LoadProject( string path ) { if ( NUnitProject.IsProjectFile( path ) ) { NUnitProject project = new NUnitProject( path ); project.Load(); return project; } else if ( VSProject.IsProjectFile( path ) ) return NUnitProject.FromVSProject( path ); else if ( VSProject.IsSolutionFile( path ) ) return NUnitProject.FromVSSolution( path ); else return NUnitProject.FromAssembly( path ); }
private IEnumerable<string> GetDistributedConfigurationFileNames(TestProject project, NUnitParameters nUnitParameters) { if (nUnitParameters.AssembliesToTest.Count == 1) { var localName = Path.Combine(project.Path, Path.GetFileName(nUnitParameters.AssembliesToTest[0])); if (NUnitProject.IsNUnitProjectFile(localName) && File.Exists(localName)) { var nUnitProject = new NUnitProject(localName); nUnitProject.Load(); var matchingConfig = nUnitProject.Configs.Cast<ProjectConfig>().Where(c => c.Name.Equals(nUnitParameters.Configuration)).FirstOrDefault(); if (matchingConfig == null) { var configFileNamedAsProject = Path.ChangeExtension(localName, ".config"); if (File.Exists(configFileNamedAsProject)) yield return configFileNamedAsProject; yield break; } yield return matchingConfig.ConfigurationFilePath; yield break; } } foreach (var assembly in nUnitParameters.AssembliesToTest) { var localName = Path.Combine(project.Path, Path.GetFileName(assembly)); string possibleConfigName = null; if (File.Exists(possibleConfigName = localName + ".config")) yield return possibleConfigName; else if (File.Exists(possibleConfigName = Path.ChangeExtension(localName, ".config"))) yield return possibleConfigName; } }
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; }