private TestSuite BuildTestAssembly(Assembly assembly, string assemblyName, IList <Test> fixtures) { TestSuite testAssembly = new TestAssembly(assembly, assemblyName); if (fixtures.Count == 0) { testAssembly.MakeInvalid("Has no TestFixtures"); } else { NamespaceTreeBuilder treeBuilder = new NamespaceTreeBuilder(testAssembly); treeBuilder.Add(fixtures); testAssembly = treeBuilder.RootSuite; } testAssembly.ApplyAttributesToTest(assembly); #if !PORTABLE && !NETSTANDARD1_6 testAssembly.Properties.Set(PropertyNames.ProcessID, System.Diagnostics.Process.GetCurrentProcess().Id); testAssembly.Properties.Set(PropertyNames.AppDomain, AppDomain.CurrentDomain.FriendlyName); #endif // TODO: Make this an option? Add Option to sort assemblies as well? testAssembly.Sort(); return(testAssembly); }
private TestSuite BuildTestAssembly(Assembly assembly, string assemblyNameOrPath, IList <Test> fixtures) { TestSuite testAssembly = new TestAssembly(assembly, assemblyNameOrPath); if (fixtures.Count == 0) { testAssembly.MakeInvalid("No test fixtures were found."); } else { NamespaceTreeBuilder treeBuilder = new NamespaceTreeBuilder(testAssembly); treeBuilder.Add(fixtures); testAssembly = treeBuilder.RootSuite; } testAssembly.ApplyAttributesToTest(assembly); try { testAssembly.Properties.Set(PropertyNames.ProcessId, System.Diagnostics.Process.GetCurrentProcess().Id); } catch (PlatformNotSupportedException) { } testAssembly.Properties.Set(PropertyNames.AppDomain, AppDomain.CurrentDomain.FriendlyName); // TODO: Make this an option? Add Option to sort assemblies as well? testAssembly.Sort(); return(testAssembly); }
/// <summary> /// Build a suite of tests given the name or the location of an assembly /// </summary> /// <param name="assemblyNameOrPath">The name or the location of the assembly.</param> /// <param name="options">A dictionary of options to use in building the suite</param> /// <returns> /// A TestSuite containing the tests found in the assembly /// </returns> public ITest Build(string assemblyNameOrPath, IDictionary <string, object> options) { log.Debug("Loading {0} in AppDomain {1}", assemblyNameOrPath, AppDomain.CurrentDomain.FriendlyName); TestSuite testAssembly = null; try { var assembly = AssemblyHelper.Load(assemblyNameOrPath); testAssembly = Build(assembly, assemblyNameOrPath, options); } catch (Exception ex) { testAssembly = new TestAssembly(assemblyNameOrPath); testAssembly.MakeInvalid(ExceptionHelper.BuildMessage(ex, true)); } return(testAssembly); }
/// <summary> /// Build a suite of tests given the filename of an assembly /// </summary> /// <param name="assemblyName">The filename of the assembly from which tests are to be built</param> /// <param name="options">A dictionary of options to use in building the suite</param> /// <returns> /// A TestSuite containing the tests found in the assembly /// </returns> public ITest Build(string assemblyName, IDictionary <string, object> options) { #if PORTABLE || NETSTANDARD1_6 log.Debug("Loading {0}", assemblyName); #else log.Debug("Loading {0} in AppDomain {1}", assemblyName, AppDomain.CurrentDomain.FriendlyName); #endif TestSuite testAssembly = null; try { var assembly = AssemblyHelper.Load(assemblyName); testAssembly = Build(assembly, assemblyName, options); } catch (Exception ex) { testAssembly = new TestAssembly(assemblyName); testAssembly.MakeInvalid(ExceptionHelper.BuildFriendlyMessage(ex)); } return(testAssembly); }
private TestSuite Build(Assembly assembly, string assemblyPath, IDictionary <string, object> options) { TestSuite testAssembly = null; try { if (options.ContainsKey(FrameworkPackageSettings.DefaultTestNamePattern)) { TestNameGenerator.DefaultTestNamePattern = options[FrameworkPackageSettings.DefaultTestNamePattern] as string; } if (options.ContainsKey(FrameworkPackageSettings.TestParametersDictionary)) { var testParametersDictionary = options[FrameworkPackageSettings.TestParametersDictionary] as IDictionary <string, string>; if (testParametersDictionary != null) { foreach (var parameter in testParametersDictionary) { TestContext.Parameters.Add(parameter.Key, parameter.Value); } } } else { // This cannot be changed without breaking backwards compatibility with old runners. // Deserializes the way old runners understand. if (options.ContainsKey(FrameworkPackageSettings.TestParameters)) { string parameters = options[FrameworkPackageSettings.TestParameters] as string; if (!string.IsNullOrEmpty(parameters)) { foreach (string param in parameters.Split(new[] { ';' })) { int eq = param.IndexOf("="); if (eq > 0 && eq < param.Length - 1) { var name = param.Substring(0, eq); var val = param.Substring(eq + 1); TestContext.Parameters.Add(name, val); } } } } } IList fixtureNames = null; if (options.ContainsKey(FrameworkPackageSettings.LOAD)) { fixtureNames = options[FrameworkPackageSettings.LOAD] as IList; } var fixtures = GetFixtures(assembly, fixtureNames); testAssembly = BuildTestAssembly(assembly, assemblyPath, fixtures); } catch (Exception ex) { testAssembly = new TestAssembly(assemblyPath); testAssembly.MakeInvalid(ExceptionHelper.BuildFriendlyMessage(ex)); } return(testAssembly); }
private TestSuite Build(Assembly assembly, string assemblyNameOrPath, IDictionary <string, object> options) { TestSuite testAssembly = null; try { // if (options.ContainsKey(FrameworkPackageSettings.DefaultTestNamePattern)) // TestNameGenerator.DefaultTestNamePattern = options[FrameworkPackageSettings.DefaultTestNamePattern] as string; // if (options.ContainsKey(FrameworkPackageSettings.WorkDirectory)) // TestContext.DefaultWorkDirectory = options[FrameworkPackageSettings.WorkDirectory] as string; // else // TestContext.DefaultWorkDirectory = Directory.GetCurrentDirectory(); // if (options.ContainsKey(FrameworkPackageSettings.TestParametersDictionary)) // { // var testParametersDictionary = options[FrameworkPackageSettings.TestParametersDictionary] as IDictionary<string, string>; // if (testParametersDictionary != null) // { // foreach (var parameter in testParametersDictionary) // TestContext.Parameters.Add(parameter.Key, parameter.Value); // } // } // else // { // // This cannot be changed without breaking backwards compatibility with old runners. // // Deserializes the way old runners understand. // if (options.ContainsKey(FrameworkPackageSettings.TestParameters)) // { // string parameters = options[FrameworkPackageSettings.TestParameters] as string; // if (!string.IsNullOrEmpty(parameters)) // foreach (string param in parameters.Split(new[] { ';' })) // { // int eq = param.IndexOf('='); // if (eq > 0 && eq < param.Length - 1) // { // var name = param.Substring(0, eq); // var val = param.Substring(eq + 1); // TestContext.Parameters.Add(name, val); // } // } // } // } _filter = new PreFilter(); // if (options.ContainsKey(FrameworkPackageSettings.LOAD)) // foreach (string filterText in (IList)options[FrameworkPackageSettings.LOAD]) // _filter.Add(filterText); var fixtures = GetFixtures(assembly); testAssembly = BuildTestAssembly(assembly, assemblyNameOrPath, fixtures); } catch (Exception ex) { testAssembly = new TestAssembly(assemblyNameOrPath); testAssembly.MakeInvalid(ExceptionHelper.BuildMessage(ex, true)); } return(testAssembly); }
private TestSuite Build(Assembly assembly, string assemblyNameOrPath, IDictionary <string, object> options) { TestSuite testAssembly = null; try { if (options.TryGetValue(FrameworkPackageSettings.DefaultTestNamePattern, out object defaultTestNamePattern)) { TestNameGenerator.DefaultTestNamePattern = defaultTestNamePattern as string; } if (options.TryGetValue(FrameworkPackageSettings.WorkDirectory, out object workDirectory)) { TestContext.DefaultWorkDirectory = workDirectory as string; } else { TestContext.DefaultWorkDirectory = Directory.GetCurrentDirectory(); } if (options.TryGetValue(FrameworkPackageSettings.TestParametersDictionary, out object testParametersObject) && testParametersObject is Dictionary <string, string> testParametersDictionary) { foreach (var parameter in testParametersDictionary) { TestContext.Parameters.Add(parameter.Key, parameter.Value); } } else { // This cannot be changed without breaking backwards compatibility with old runners. // Deserializes the way old runners understand. options.TryGetValue(FrameworkPackageSettings.TestParameters, out object testParameters); string parametersString = testParameters as string; if (!string.IsNullOrEmpty(parametersString)) { foreach (string param in parametersString.Split(new[] { ';' })) { int eq = param.IndexOf('='); if (eq > 0 && eq < param.Length - 1) { var name = param.Substring(0, eq); var val = param.Substring(eq + 1); TestContext.Parameters.Add(name, val); } } } } _filter = new PreFilter(); if (options.TryGetValue(FrameworkPackageSettings.LOAD, out object load)) { foreach (string filterText in (IList)load) { _filter.Add(filterText); } } var fixtures = GetFixtures(assembly); testAssembly = BuildTestAssembly(assembly, assemblyNameOrPath, fixtures); } catch (Exception ex) { testAssembly = new TestAssembly(assemblyNameOrPath); testAssembly.MakeInvalid(ExceptionHelper.BuildMessage(ex, true)); } return(testAssembly); }