private static IEnumerable SourceMustBeStaticError() { var parms = new TestFixtureParameters(); parms.RunState = RunState.NotRunnable; parms.Properties.Set(PropertyNames.SkipReason, MUST_BE_STATIC); return(new TestFixtureParameters[] { parms }); }
static TestFixtureParameters CreateTestFixtureDataForGenericTest(Type genericType) { var data = new TestFixtureAttribute { TypeArgs = new[] { genericType } }; var parameters = new TestFixtureParameters(data); return(parameters); }
/// <summary> /// Returns a set of ITestFixtureData items for use as arguments /// to a parameterized test fixture. /// </summary> /// <param name="sourceType">The type for which data is needed.</param> /// <returns></returns> public IEnumerable <ITestFixtureData> GetParametersFor(Type sourceType) { List <ITestFixtureData> data = new List <ITestFixtureData>(); try { IEnumerable source = GetTestFixtureSource(sourceType); if (source != null) { foreach (object item in source) { var parms = item as ITestFixtureData; if (parms == null) { object[] args = item as object[]; if (args == null) { args = new object[] { item }; } parms = new TestFixtureParameters(args); } if (this.Category != null) { foreach (string cat in this.Category.Split(new char[] { ',' })) { parms.Properties.Add(PropertyNames.Category, cat); } } data.Add(parms); } } } catch (Exception ex) { data.Clear(); data.Add(new TestFixtureParameters(ex)); } return(data); }
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); }
/// <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); }