static ITestCaseOrderer GetXunitTestCaseOrderer(IAttributeInfo ordererAttribute) { var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); var ordererType = Reflector.GetType(args[1], args[0]); return(ExtensibilityPointFactory.GetTestCaseOrderer(ordererType)); }
/// <summary> /// Gives an opportunity to override test case orderer. By default, this method gets the /// orderer from the collection definition. If this function returns <c>null</c>, the /// test case orderer passed into the constructor will be used. /// </summary> protected virtual ITestCaseOrderer GetTestCaseOrderer() { if (TestCollection.CollectionDefinition != null) { var ordererAttribute = TestCollection.CollectionDefinition.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { try { var testCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(DiagnosticMessageSink, ordererAttribute); if (testCaseOrderer != null) { return(testCaseOrderer); } var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Could not find type '{args[0]}' in {args[1]} for collection-level test case orderer on test collection '{TestCollection.DisplayName}'")); } catch (Exception ex) { var innerEx = ex.Unwrap(); var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Collection-level test case orderer '{args[0]}' for test collection '{TestCollection.DisplayName}' threw '{innerEx.GetType().FullName}' during construction: {innerEx.Message}{Environment.NewLine}{innerEx.StackTrace}")); } } } return(null); }
/// <inheritdoc/> protected override Task AfterTestClassStartingAsync() { var ordererAttribute = Class.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { TestCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(ordererAttribute); } var testClassTypeInfo = Class.Type.GetTypeInfo(); if (testClassTypeInfo.ImplementedInterfaces.Any(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(ICollectionFixture <>))) { Aggregator.Add(new TestClassException("A test class may not be decorated with ICollectionFixture<> (decorate the test collection class instead).")); } foreach (var interfaceType in testClassTypeInfo.ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(IClassFixture <>))) { CreateFixture(interfaceType); } if (TestClass.TestCollection.CollectionDefinition != null) { var declarationType = ((IReflectionTypeInfo)TestClass.TestCollection.CollectionDefinition).Type; foreach (var interfaceType in declarationType.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(IClassFixture <>))) { CreateFixture(interfaceType); } } return(Task.FromResult(0)); }
/// <inheritdoc/> protected override void OnAssemblyStarting() { collectionBehaviorAttribute = AssemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); if (collectionBehaviorAttribute != null) { disableParallelization = collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); maxParallelThreads = collectionBehaviorAttribute.GetNamedArgument <int>("MaxParallelThreads"); } disableParallelization = ExecutionOptions.GetValue <bool>(TestOptionsNames.Execution.DisableParallelization, disableParallelization); var maxParallelThreadsOption = ExecutionOptions.GetValue <int>(TestOptionsNames.Execution.MaxParallelThreads, 0); if (maxParallelThreadsOption > 0) { maxParallelThreads = maxParallelThreadsOption; } scheduler = GetTaskScheduler(maxParallelThreads); var ordererAttribute = AssemblyInfo.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { TestCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(ordererAttribute); } }
void Initialize() { if (initialized) { return; } collectionBehaviorAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); if (collectionBehaviorAttribute != null) { disableParallelization = collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); maxParallelThreads = collectionBehaviorAttribute.GetNamedArgument <int>("MaxParallelThreads"); } disableParallelization = ExecutionOptions.GetValue <bool>(TestOptionsNames.Execution.DisableParallelization, disableParallelization); var maxParallelThreadsOption = ExecutionOptions.GetValue <int>(TestOptionsNames.Execution.MaxParallelThreads, 0); if (maxParallelThreadsOption > 0) { maxParallelThreads = maxParallelThreadsOption; } scheduler = GetTaskScheduler(maxParallelThreads); var ordererAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { TestCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(ordererAttribute); } initialized = true; }
/// <inheritdoc/> protected override async Task AfterTestClassStartingAsync() { var ordererAttribute = Class.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { try { var testCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(DiagnosticMessageSink, ordererAttribute); if (testCaseOrderer != null) { TestCaseOrderer = testCaseOrderer; } else { var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Could not find type '{args[0]}' in {args[1]} for class-level test case orderer on test class '{TestClass.Class.Name}'")); } } catch (Exception ex) { var innerEx = ex.Unwrap(); var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage($"Class-level test case orderer '{args[0]}' for test class '{TestClass.Class.Name}' threw '{innerEx.GetType().FullName}' during construction: {innerEx.Message}{Environment.NewLine}{innerEx.StackTrace}")); } } var testClassTypeInfo = Class.Type.GetTypeInfo(); if (testClassTypeInfo.ImplementedInterfaces.Any(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(ICollectionFixture <>))) { Aggregator.Add(new TestClassException("A test class may not be decorated with ICollectionFixture<> (decorate the test collection class instead).")); } var createClassFixtureAsyncTasks = new List <Task>(); foreach (var interfaceType in testClassTypeInfo.ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(IClassFixture <>))) { createClassFixtureAsyncTasks.Add(CreateClassFixtureAsync(interfaceType.GetTypeInfo().GenericTypeArguments.Single())); } if (TestClass.TestCollection.CollectionDefinition != null) { var declarationType = ((IReflectionTypeInfo)TestClass.TestCollection.CollectionDefinition).Type; foreach (var interfaceType in declarationType.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(IClassFixture <>))) { createClassFixtureAsyncTasks.Add(CreateClassFixtureAsync(interfaceType.GetTypeInfo().GenericTypeArguments.Single())); } } await Task.WhenAll(createClassFixtureAsyncTasks); }
/// <inheritdoc/> protected override void AfterTestCollectionStarting() { if (TestCollection.CollectionDefinition != null) { var declarationType = ((IReflectionTypeInfo)TestCollection.CollectionDefinition).Type; foreach (var interfaceType in declarationType.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(ICollectionFixture <>))) { CreateFixture(interfaceType); } var ordererAttribute = TestCollection.CollectionDefinition.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { TestCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(ordererAttribute); } } }
/// <summary> /// Ensures the assembly runner is initialized (sets up the collection behavior, /// parallelization options, and test orderers from their assembly attributes). /// </summary> protected void Initialize() { if (initialized) { return; } collectionBehaviorAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); if (collectionBehaviorAttribute != null) { disableParallelization = collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); maxParallelThreads = collectionBehaviorAttribute.GetNamedArgument <int>("MaxParallelThreads"); } disableParallelization = ExecutionOptions.DisableParallelization() ?? disableParallelization; var maxParallelThreadsOption = ExecutionOptions.MaxParallelThreads() ?? 0; if (maxParallelThreadsOption > 0) { maxParallelThreads = maxParallelThreadsOption; } var testCaseOrdererAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (testCaseOrdererAttribute != null) { TestCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(DiagnosticMessageSink, testCaseOrdererAttribute); } var testCollectionOrdererAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(TestCollectionOrdererAttribute)).SingleOrDefault(); if (testCollectionOrdererAttribute != null) { TestCollectionOrderer = ExtensibilityPointFactory.GetTestCollectionOrderer(DiagnosticMessageSink, testCollectionOrdererAttribute); } initialized = true; }
/// <inheritdoc/> protected override Task AfterTestCollectionStartingAsync() { if (TestCollection.CollectionDefinition != null) { var declarationType = ((IReflectionTypeInfo)TestCollection.CollectionDefinition).Type; foreach (var interfaceType in declarationType.GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(ICollectionFixture <>))) { CreateFixture(interfaceType); } var ordererAttribute = TestCollection.CollectionDefinition.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (ordererAttribute != null) { try { var testCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(diagnosticMessageSink, ordererAttribute); if (testCaseOrderer != null) { TestCaseOrderer = testCaseOrderer; } else { var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); diagnosticMessageSink.OnMessage(new DiagnosticMessage("Could not find type '{0}' in {1} for collection-level test case orderer on test collection '{2}'", args[0], args[1], TestCollection.DisplayName)); } } catch (Exception ex) { var innerEx = ex.Unwrap(); var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); diagnosticMessageSink.OnMessage(new DiagnosticMessage("Collection-level test case orderer '{0}' for test collection '{1}' threw '{2}' during construction: {3}", args[0], TestCollection.DisplayName, innerEx.GetType().FullName, innerEx.StackTrace)); } } } return(Task.FromResult(0)); }
/// <summary> /// Ensures the assembly runner is initialized (sets up the collection behavior, /// parallelization options, and test orderers from their assembly attributes). /// </summary> protected void Initialize() { if (initialized) { return; } collectionBehaviorAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); if (collectionBehaviorAttribute != null) { disableParallelization = collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); maxParallelThreads = collectionBehaviorAttribute.GetNamedArgument <int>("MaxParallelThreads"); } disableParallelization = ExecutionOptions.DisableParallelization() ?? disableParallelization; var maxParallelThreadsOption = ExecutionOptions.MaxParallelThreads() ?? 0; if (maxParallelThreadsOption > 0) { maxParallelThreads = maxParallelThreadsOption; } var testCaseOrdererAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault(); if (testCaseOrdererAttribute != null) { try { var testCaseOrderer = ExtensibilityPointFactory.GetTestCaseOrderer(DiagnosticMessageSink, testCaseOrdererAttribute); if (testCaseOrderer != null) { TestCaseOrderer = testCaseOrderer; } else { var args = testCaseOrdererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage("Could not find type '{0}' in {1} for assembly-level test case orderer", args[0], args[1])); } } catch (Exception ex) { var innerEx = ex.Unwrap(); var args = testCaseOrdererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage("Assembly-level test case orderer '{0}' threw '{1}' during construction: {2}", args[0], innerEx.GetType().FullName, innerEx.StackTrace)); } } var testCollectionOrdererAttribute = TestAssembly.Assembly.GetCustomAttributes(typeof(TestCollectionOrdererAttribute)).SingleOrDefault(); if (testCollectionOrdererAttribute != null) { try { var testCollectionOrderer = ExtensibilityPointFactory.GetTestCollectionOrderer(DiagnosticMessageSink, testCollectionOrdererAttribute); if (testCollectionOrderer != null) { TestCollectionOrderer = testCollectionOrderer; } else { var args = testCollectionOrdererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage("Could not find type '{0}' in {1} for assembly-level test collection orderer", args[0], args[1])); } } catch (Exception ex) { var innerEx = ex.Unwrap(); var args = testCollectionOrdererAttribute.GetConstructorArguments().Cast <string>().ToList(); DiagnosticMessageSink.OnMessage(new DiagnosticMessage("Assembly-level test collection orderer '{0}' threw '{1}' during construction: {2}", args[0], innerEx.GetType().FullName, innerEx.StackTrace)); } } initialized = true; }