/// <summary> /// Method to add test cases to the newly constructed fixture. /// </summary> private void AddTestCasesToFixture(TestFixture fixture, IPreFilter filter) { // TODO: Check this logic added from Neil's build. if (fixture.TypeInfo.ContainsGenericParameters) { fixture.MakeInvalid(NO_TYPE_ARGS_MSG); return; } var methods = fixture.TypeInfo.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); foreach (IMethodInfo method in methods) { if (filter.IsMatch(fixture.TypeInfo.Type, method.MethodInfo)) { Test test = BuildTestCase(method, fixture); if (test != null) { fixture.Add(test); } else // it's not a test, check for disallowed attributes if (method.MethodInfo.HasAttribute <ParallelizableAttribute>(false)) { fixture.MakeInvalid(PARALLEL_NOT_ALLOWED_MSG); } } } }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var fixture = _builder.BuildFrom(typeInfo, filter, this); fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); yield return(fixture); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var fixture = _builder.BuildFrom(typeInfo, filter, this); fixture.ApplyAttributesToTest(new AttributeProviderWrapper <FixtureLifeCycleAttribute>(typeInfo.Type.GetTypeInfo().Assembly)); fixture.ApplyAttributesToTest(typeInfo.Type); yield return(fixture); }
/// <summary> /// Builds any number of test fixtures from the specified type. /// </summary> /// <param name="type">The type to be used as a fixture.</param> /// <param name="filter">PreFilter used to select methods as tests.</param> public IEnumerable <TestSuite> BuildFrom(Type type, IPreFilter filter) { Type sourceType = SourceType ?? type; foreach (ITestFixtureData parms in GetParametersFor(sourceType)) { yield return(_builder.BuildFrom(type, filter, parms)); } }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var suitePermutations = GeneratePermutations(); foreach (var(fixture, isAsync, serviceVersion, parameter) in suitePermutations) { foreach (TestSuite testSuite in fixture.BuildFrom(typeInfo, filter)) { Process(testSuite, serviceVersion, isAsync, parameter); yield return(testSuite); } } }
public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var fixtures = new List <TestSuite>(); try { IFixtureBuilder[] builders = GetFixtureBuilderAttributes(typeInfo); foreach (var builder in builders) { // See if this is an enhanced attribute, accepting a filter var builder2 = builder as IFixtureBuilder2; foreach (var fixture in builder2?.BuildFrom(typeInfo, filter) ?? builder.BuildFrom(typeInfo)) { fixtures.Add(fixture); } } if (typeInfo.IsGenericType) { return(BuildMultipleFixtures(typeInfo, fixtures)); } switch (fixtures.Count) { case 0: return(_defaultBuilder.BuildFrom(typeInfo, filter)); case 1: return(fixtures[0]); default: return(BuildMultipleFixtures(typeInfo, fixtures)); } } catch (Exception ex) { var fixture = new TestFixture(typeInfo); if (ex is System.Reflection.TargetInvocationException) { ex = ex.InnerException; } fixture.MakeInvalid("An exception was thrown while loading the test." + Environment.NewLine + ex.ToString()); return(fixture); } }
/// <summary> /// Build a TestFixture from type provided. A non-null TestSuite /// must always be returned, since the method is generally called /// because the user has marked the target class as a fixture. /// If something prevents the fixture from being used, it should /// be returned nonetheless, labeled as non-runnable. /// </summary> /// <param name="typeInfo">An ITypeInfo for the fixture to be used.</param> /// <param name="filter">Filter used to select methods as tests.</param> /// <returns>A TestSuite object or one derived from TestSuite.</returns> // TODO: This should really return a TestFixture, but that requires changes to the Test hierarchy. public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var fixture = new TestFixture(typeInfo); if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); return(fixture); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var latestVersion = _serviceVersions.Any() ? _serviceVersions.Max(Convert.ToInt32) : (int?)null; _actualPlaybackServiceVersion = RecordingServiceVersion != null?Convert.ToInt32(RecordingServiceVersion) : latestVersion; int[] liveVersions = (LiveServiceVersions ?? _serviceVersions).Select(Convert.ToInt32).ToArray(); if (liveVersions.Any()) { if (TestEnvironment.GlobalTestOnlyLatestVersion) { _actualLiveServiceVersions = new[] { liveVersions.Max() }; } else if (TestEnvironment.GlobalTestServiceVersions is { Length : > 0 } globalTestServiceVersions&& _serviceVersions is { Length : > 0 })
public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var fixture = new TestFixture(typeInfo); if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(new AttributeProviderWrapper <FixtureLifeCycleAttribute>(typeInfo.Type.GetTypeInfo().Assembly)); fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); return(fixture); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { object latestVersion = GetMax(_serviceVersions); _actualPlaybackServiceVersion = RecordingServiceVersion ?? latestVersion; object[] liveVersions = (LiveServiceVersions ?? _serviceVersions).ToArray(); if (liveVersions.Any()) { if (TestEnvironment.GlobalTestOnlyLatestVersion) { _actualLiveServiceVersions = new[] { GetMax(liveVersions) }; } else if (TestEnvironment.GlobalTestServiceVersions is { Length : > 0 } globalTestServiceVersions&& _serviceVersions is { Length : > 0 })
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { Type sourceType = SourceType ?? typeInfo.Type; var fixtureSuite = new ParameterizedFixtureSuite(typeInfo); fixtureSuite.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); foreach (ITestFixtureData parms in GetParametersFor(sourceType)) { TestSuite fixture = _builder.BuildFrom(typeInfo, filter, parms); fixtureSuite.Add(fixture); } yield return(fixtureSuite); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { // This whole method does more or less the same thing as NUnit's own // TestFixtureSourceAttribute, but with two differences: // 1) this is hard-coded to use the list of test modes as its input // 2) this adds a Category of "fast" when the DirectInvocation mode is used // That second one is important for enabling a quick developer loop. Developers // can create a test playlist that runs only the "fast" tests, or if they have // NCrunch, they can define a custom Engine Mode that automatically runs only // fast tests. These "fast" tests can run without spinning up a new functions // host. Also, because they do not set up an HTTP listener, they can be executed // in parallel without hitting port conflicts. var fixtureSuite = new ParameterizedFixtureSuite(typeInfo); fixtureSuite.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); ICustomAttributeProvider assemblyLifeCycleAttributeProvider = typeInfo.Type.GetTypeInfo().Assembly; ICustomAttributeProvider typeLifeCycleAttributeProvider = typeInfo.Type.GetTypeInfo(); foreach (object[] args in FixtureArgs) { var arg = (TestHostModes)args[0]; ITestFixtureData parms = new TestFixtureParameters(new object[] { arg }); TestSuite fixture = this.builder.BuildFrom(typeInfo, filter, parms); switch (arg) { case TestHostModes.DirectInvocation: fixture.Properties["Category"].Add("fast"); fixture.Properties["Category"].Add("parallelizable"); break; case TestHostModes.InProcessEmulateFunctionWithActionResult: fixture.Properties["Category"].Add("fast"); break; } fixture.ApplyAttributesToTest(assemblyLifeCycleAttributeProvider); fixture.ApplyAttributesToTest(typeLifeCycleAttributeProvider); fixtureSuite.Add(fixture); } yield return(fixtureSuite); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { if (_serviceVersions.Any()) { foreach (object serviceVersion in _serviceVersions) { var syncFixture = new TestFixtureAttribute(false, serviceVersion); var asyncFixture = new TestFixtureAttribute(true, serviceVersion); foreach (TestSuite testSuite in asyncFixture.BuildFrom(typeInfo, filter)) { Process(testSuite, serviceVersion, true); yield return(testSuite); } foreach (TestSuite testSuite in syncFixture.BuildFrom(typeInfo, filter)) { Process(testSuite, serviceVersion, false); yield return(testSuite); } } } else { // No service versions defined var syncFixture = new TestFixtureAttribute(false); var asyncFixture = new TestFixtureAttribute(true); foreach (TestSuite testSuite in asyncFixture.BuildFrom(typeInfo, filter)) { Process(testSuite, null, true); yield return(testSuite); } foreach (TestSuite testSuite in syncFixture.BuildFrom(typeInfo, filter)) { Process(testSuite, null, false); yield return(testSuite); } } }
/// <summary> /// Build a TestFixture from type provided. A non-null TestSuite /// must always be returned, since the method is generally called /// because the user has marked the target class as a fixture. /// If something prevents the fixture from being used, it should /// be returned nonetheless, labelled as non-runnable. /// </summary> /// <param name="typeInfo">An ITypeInfo for the fixture to be used.</param> /// <param name="filter">Filter used to select methods as tests.</param> /// <returns>A TestSuite object or one derived from TestSuite.</returns> // TODO: This should really return a TestFixture, but that requires changes to the Test hierarchy. public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { // Build our custom SetUpFixture to get the NUnit runner to initialize us // even though we don't own the test assembly. var setUpFixture = _setUpFixtureBuilder.BuildFrom(typeInfo); var fixture = new TestFixture(typeInfo); SetUpRandomizedContext(setUpFixture, fixture); if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); setUpFixture.Add(fixture); return(setUpFixture); }
private IEnumerable <TestSuite> GetTestSuite(ITypeInfo typeInfo, IPreFilter filter) { InheritAttributes(typeInfo); foreach (var constructor in typeInfo.Type.GetConstructors()) { var arguments = new List <object>(); foreach (var parameter in constructor.GetParameters()) { var argument = Resolver.GetService(constructor, parameter.ParameterType); if (argument != null) { arguments.Add(argument); } } var fixture = new NUnitTestFixtureBuilder().BuildFrom(typeInfo, filter, new TestFixtureData(arguments.ToArray())); CheckApplyExecuteInSetup(fixture, constructor); yield return(fixture); } }
/// <summary> /// Method to add test cases to the newly constructed fixture. /// </summary> private void AddTestCasesToFixture(TestFixture fixture, IPreFilter filter) { // TODO: Check this logic added from Neil's build. if (fixture.TypeInfo.ContainsGenericParameters) { fixture.MakeInvalid(NO_TYPE_ARGS_MSG); return; } // We sort the methods in a deterministic order, since BuildTestCase() will invoke the // Randomizer to create seeds for each test. We want those seeds to be deterministically repeatable // so we can re-run the same conditions by manually fixing the Randomizer.InitialSeed. var methods = new SortedSet <IMethodInfo>(fixture.TypeInfo.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static), MethodInfoComparer.Default); foreach (IMethodInfo method in methods) { // Generate the seed whether or not we use a filter to ensure we invoke the Randomizer to // move to the next random test seed (a test should always get the same seed in the sequence). Test test = BuildTestCase(method, fixture); _randomSeedInitializer.GenerateRandomSeeds(test); if (filter.IsMatch(fixture.TypeInfo.Type, method.MethodInfo)) { if (test != null) { fixture.Add(test); } else // it's not a test, check for disallowed attributes if (method.MethodInfo.HasAttribute <ParallelizableAttribute>(false)) { fixture.MakeInvalid(PARALLEL_NOT_ALLOWED_MSG); } } } }
/// <inheritdoc/> public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { // This whole method does more or less the same thing as NUnit's own // TestFixtureSourceAttribute, but with one difference: it is hard-coded to use // the list of test modes as its input. var fixtureSuite = new ParameterizedFixtureSuite(typeInfo); fixtureSuite.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); ICustomAttributeProvider assemblyLifeCycleAttributeProvider = typeInfo.Type.GetTypeInfo().Assembly; ICustomAttributeProvider typeLifeCycleAttributeProvider = typeInfo.Type.GetTypeInfo(); foreach (object[] args in FixtureArgs) { var arg = (SetupModes)args[0]; ITestFixtureData parms = new TestFixtureParameters(new object[] { arg }); TestSuite fixture = this.builder.BuildFrom(typeInfo, filter, parms); fixture.ApplyAttributesToTest(assemblyLifeCycleAttributeProvider); fixture.ApplyAttributesToTest(typeLifeCycleAttributeProvider); fixtureSuite.Add(fixture); } yield return(fixtureSuite); }
/// <summary> /// Builds a single test fixture from the specified type. /// </summary> /// <param name="typeInfo">The type info of the fixture to be used.</param> /// <param name="filter">Filter used to select methods as tests.</param> public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { yield return(_builder.BuildFrom(typeInfo, filter, this)); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { var fixtureData = new List <TestFixtureData>(); if (dialect.HasFlag(Dialect.MySqlConnector)) { fixtureData.Add(new TestFixtureData(Dialect.MySqlConnector)); } if (dialect.HasFlag(Dialect.Sqlite)) { fixtureData.Add(new TestFixtureData(Dialect.Sqlite)); } if (dialect.HasFlag(Dialect.MySql5_5)) { fixtureData.Add(new TestFixtureData(Dialect.MySql5_5)); } if (dialect.HasFlag(Dialect.MySql10_1)) { fixtureData.Add(new TestFixtureData(Dialect.MySql10_1)); } if (dialect.HasFlag(Dialect.MySql10_2)) { fixtureData.Add(new TestFixtureData(Dialect.MySql10_2)); } if (dialect.HasFlag(Dialect.MySql10_3)) { fixtureData.Add(new TestFixtureData(Dialect.MySql10_3)); } if (dialect.HasFlag(Dialect.MySql10_4)) { fixtureData.Add(new TestFixtureData(Dialect.MySql10_4)); } if (dialect.HasFlag(Dialect.PostgreSql9)) { fixtureData.Add(new TestFixtureData(Dialect.PostgreSql9)); } if (dialect.HasFlag(Dialect.PostgreSql10)) { fixtureData.Add(new TestFixtureData(Dialect.PostgreSql10)); } if (dialect.HasFlag(Dialect.PostgreSql11)) { fixtureData.Add(new TestFixtureData(Dialect.PostgreSql11)); } if (dialect.HasFlag(Dialect.SqlServer)) { fixtureData.Add(new TestFixtureData(Dialect.SqlServer)); } if (dialect.HasFlag(Dialect.SqlServer2008)) { fixtureData.Add(new TestFixtureData(Dialect.SqlServer2008)); } if (dialect.HasFlag(Dialect.SqlServer2012)) { fixtureData.Add(new TestFixtureData(Dialect.SqlServer2012)); } if (dialect.HasFlag(Dialect.SqlServer2014)) { fixtureData.Add(new TestFixtureData(Dialect.SqlServer2014)); } if (dialect.HasFlag(Dialect.SqlServer2016)) { fixtureData.Add(new TestFixtureData(Dialect.SqlServer2016)); } if (dialect.HasFlag(Dialect.SqlServer2017)) { fixtureData.Add(new TestFixtureData(Dialect.SqlServer2017)); } if (dialect.HasFlag(Dialect.Firebird)) { fixtureData.Add(new TestFixtureData(Dialect.Firebird)); } if (dialect.HasFlag(Dialect.Oracle10)) { fixtureData.Add(new TestFixtureData(Dialect.Oracle10)); } if (dialect.HasFlag(Dialect.Oracle11)) { fixtureData.Add(new TestFixtureData(Dialect.Oracle11)); } if (dialect.HasFlag(Dialect.Oracle12)) { fixtureData.Add(new TestFixtureData(Dialect.Oracle12)); } if (dialect.HasFlag(Dialect.Oracle18)) { fixtureData.Add(new TestFixtureData(Dialect.Oracle18)); } if (dialect.HasFlag(Dialect.VistaDb)) { fixtureData.Add(new TestFixtureData(Dialect.VistaDb)); } foreach (var data in fixtureData) { // ignore test if not in TestConfig but add as ignored to explain why if (!TestConfig.Dialect.HasFlag((Dialect)data.Arguments[0])) { data.Ignore(reason); } data.Properties.Add(PropertyNames.Category, data.Arguments[0].ToString()); yield return(_builder.BuildFrom(typeInfo, filter, data)); } }
/// <summary> /// Overload of BuildFrom called by tests that have arguments. /// Builds a fixture using the provided type and information /// in the ITestFixtureData object. /// </summary> /// <param name="typeInfo">The TypeInfo for which to construct a fixture.</param> /// <param name="filter">Filter used to select methods as tests.</param> /// <param name="testFixtureData">An object implementing ITestFixtureData or null.</param> /// <returns></returns> public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter, ITestFixtureData testFixtureData) { Guard.ArgumentNotNull(testFixtureData, nameof(testFixtureData)); object[] arguments = testFixtureData.Arguments; if (typeInfo.ContainsGenericParameters) { Type[] typeArgs = testFixtureData.TypeArgs; if (typeArgs == null || typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(typeInfo.Type, arguments, ref typeArgs)) { typeInfo = typeInfo.MakeGenericType(typeArgs); } } var fixture = new TestFixture(typeInfo, arguments); string name = fixture.Name; if (testFixtureData.TestName != null) { fixture.Name = testFixtureData.TestName; } else { var argDisplayNames = (testFixtureData as TestParameters)?.ArgDisplayNames; if (argDisplayNames != null) { fixture.Name = typeInfo.GetDisplayName(); if (argDisplayNames.Length != 0) { fixture.Name += '(' + string.Join(", ", argDisplayNames) + ')'; } } else if (arguments != null && arguments.Length > 0) { fixture.Name = typeInfo.GetDisplayName(arguments); } } if (fixture.Name != name) // name was changed { string nspace = typeInfo.Namespace; fixture.FullName = nspace != null && nspace != "" ? nspace + "." + fixture.Name : fixture.Name; } if (fixture.RunState != RunState.NotRunnable) { fixture.RunState = testFixtureData.RunState; } foreach (string key in testFixtureData.Properties.Keys) { foreach (object val in testFixtureData.Properties[key]) { fixture.Properties.Add(key, val); } } if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); return(fixture); }
public void Add(IPreFilter filter) { if (filter == null) throw new ArgumentNullException("filter"); _filters.Add(filter); }
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); }
/// <summary> /// Adds a filter to a log target /// </summary> /// <param name="targetName">Name of the target (filename without path and extension, or "console" for the console).</param> /// <param name="logFilter">The log filter.</param> public void AddFilter(string targetName, IPreFilter logFilter) { //Targets.First(t => Path.GetFileNameWithoutExtension(t.Name) == targetName).AddFilter(logFilter); }
/// <summary> /// Adds a filter to a log target /// </summary> /// <param name="targetName">Name of the target (filename without path and extension, or "console" for the console).</param> /// <param name="logFilter">The log filter.</param> public void AddFilter(string targetName, IPreFilter logFilter) { //Targets.First(t => Path.GetFileNameWithoutExtension(t.Name) == targetName).AddFilter(logFilter); }
/// <summary> /// Adds a filter to a log target /// </summary> /// <param name="targetName">Name of the target (filename without path and extension, or "console" for the console).</param> /// <param name="logFilter">The log filter.</param> public static void AddFilter(string targetName, IPreFilter logFilter) { Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(targetName)); Contract.Requires<ArgumentNullException>(logFilter != null); //Targets.First(t => Path.GetFileNameWithoutExtension(t.Name) == targetName).AddFilter(logFilter); }
public IEnumerable <TestSuite> BuildFrom(ITypeInfo typeInfo, IPreFilter filter) { return(GetTestSuite(typeInfo, filter)); }
/// <summary> /// Overload of BuildFrom called by tests that have arguments. /// Builds a fixture using the provided type and information /// in the ITestFixtureData object. /// </summary> /// <param name="typeInfo">The TypeInfo for which to construct a fixture.</param> /// <param name="filter">Filter used to select methods as tests.</param> /// <param name="testFixtureData">An object implementing ITestFixtureData or null.</param> /// <returns></returns> public TestSuite BuildFrom(ITypeInfo typeInfo, IPreFilter filter, ITestFixtureData testFixtureData) { //Guard.ArgumentNotNull(testFixtureData, nameof(testFixtureData)); if (testFixtureData is null) { throw new ArgumentNullException(nameof(testFixtureData)); } object[] arguments = testFixtureData.Arguments; if (typeInfo.ContainsGenericParameters) { Type[] typeArgs = testFixtureData.TypeArgs; if (typeArgs is null || typeArgs.Length == 0) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(typeInfo.Type, arguments, ref typeArgs)) { typeInfo = typeInfo.MakeGenericType(typeArgs); } } // Build our custom SetUpFixture to get the NUnit runner to initialize us // even though we don't own the test assembly. var setUpFixture = _setUpFixtureBuilder.BuildFrom(typeInfo); var fixture = new TestFixture(typeInfo, arguments); SetUpRandomizedContext(setUpFixture, fixture); string name = fixture.Name; if (testFixtureData.TestName != null) { fixture.Name = testFixtureData.TestName; } else { //var argDisplayNames = (testFixtureData as NUnit.Framework.Internal.TestParameters)?.ArgDisplayNames; var testParameters = testFixtureData as NUnit.Framework.Internal.TestParameters; string[] argDisplayNames = null; if (testParameters != null) { // Hack so we can call the same internal field that NUnit does BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; FieldInfo field = typeof(NUnit.Framework.Internal.TestParameters).GetField("_argDisplayNames", bindFlags); argDisplayNames = (string[])field.GetValue(testFixtureData); } if (argDisplayNames != null) { fixture.Name = typeInfo.GetDisplayName(); if (argDisplayNames.Length != 0) { fixture.Name += '(' + string.Join(", ", argDisplayNames) + ')'; } } else if (arguments != null && arguments.Length > 0) { fixture.Name = typeInfo.GetDisplayName(arguments); } } if (fixture.Name != name) // name was changed { string nspace = typeInfo.Namespace; fixture.FullName = nspace != null && nspace != "" ? nspace + "." + fixture.Name : fixture.Name; } if (fixture.RunState != RunState.NotRunnable) { fixture.RunState = testFixtureData.RunState; } foreach (string key in testFixtureData.Properties.Keys) { foreach (object val in testFixtureData.Properties[key]) { fixture.Properties.Add(key, val); } } if (fixture.RunState != RunState.NotRunnable) { CheckTestFixtureIsValid(fixture); } fixture.ApplyAttributesToTest(typeInfo.Type.GetTypeInfo()); AddTestCasesToFixture(fixture, filter); setUpFixture.Add(fixture); return(setUpFixture); }