/// <inheritdoc /> public void Describe(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { if (reflectionPolicy == null) { throw new ArgumentNullException("reflectionPolicy"); } if (codeElements == null || codeElements.Contains(null)) { throw new ArgumentNullException("codeElements"); } if (testExplorationOptions == null) { throw new ArgumentNullException("testExplorationOptions"); } if (messageSink == null) { throw new ArgumentNullException("messageSink"); } if (progressMonitor == null) { throw new ArgumentNullException("progressMonitor"); } DescribeImpl(reflectionPolicy, codeElements, testExplorationOptions, messageSink, progressMonitor); }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { InitializeExplorerIfNeeded(reflectionPolicy); IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly != null) { bool skipChildren = !(codeElement is IAssemblyInfo); if (BuildAssemblyTest(assembly, skipChildren)) { foreach (IPatternScope scope in evaluator.GetScopes(assembly)) { scope.PopulateDeferredComponents(null); } assemblies[assembly] = true; } else { ITypeInfo type = ReflectionUtils.GetType(codeElement); if (type != null) { foreach (IPatternScope scope in evaluator.GetScopes(assembly)) { scope.PopulateDeferredComponents(type); } } } } }
/// <summary> /// Creates a test model builder. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/> is null.</exception> public ReflectionOnlyTestModelBuilder(IReflectionPolicy reflectionPolicy) { if (reflectionPolicy == null) throw new ArgumentNullException("reflectionPolicy"); this.reflectionPolicy = reflectionPolicy; }
protected override IList <TestPart> GetTestPartsImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { bool copied = false; IList <TestPart> combinedTestParts = null; ForEachDriver(testFrameworkManager.SelectTestFrameworksForCodeElementsImpl( testFrameworkHandles, testFrameworkFallbackMode, testFrameworkOptions, new[] { codeElement }), (driver, items, driverCount) => { IList <TestPart> testParts = driver.GetTestParts(reflectionPolicy, codeElement); if (testParts.Count != 0) { if (combinedTestParts == null) { combinedTestParts = testParts; } else { if (!copied) { combinedTestParts = new List <TestPart>(combinedTestParts); copied = true; } GenericCollectionUtils.AddAll(testParts, combinedTestParts); } } return(false); }); return(combinedTestParts ?? EmptyArray <TestPart> .Instance); }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { InitializeExplorerIfNeeded(reflectionPolicy); IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly != null) { bool skipChildren = ! (codeElement is IAssemblyInfo); if (BuildAssemblyTest(assembly, skipChildren)) { foreach (IPatternScope scope in evaluator.GetScopes(assembly)) scope.PopulateDeferredComponents(null); assemblies[assembly] = true; } else { ITypeInfo type = ReflectionUtils.GetType(codeElement); if (type != null) { foreach (IPatternScope scope in evaluator.GetScopes(assembly)) scope.PopulateDeferredComponents(type); } } } }
/// <inheritdoc /> protected override void DescribeImpl(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask("Describing unsupported tests.", Math.Max(codeElements.Count, 1))) { PublishTestModelFromCodeElements(codeElements, messageSink, progressMonitor); } }
/// <inheritdoc /> protected override void DescribeImpl(IReflectionPolicy reflectionPolicy, IList<ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask("Describing unsupported tests.", Math.Max(codeElements.Count, 1))) { PublishTestModelFromCodeElements(codeElements, messageSink, progressMonitor); } }
/// <inheritdoc /> sealed protected override void DescribeImpl(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask(string.Format("Describing {0} tests.", FrameworkName), 100)) { progressMonitor.SetStatus("Building the test model."); GenerateTestModel(reflectionPolicy, codeElements, messageSink); } }
private void Describe(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, ConsumerAdapter consumerAdapter) { var testDriver = CreateTestDriver(); var testExplorationOptions = new TestExplorationOptions(); testDriver.Describe(reflectionPolicy, codeElements, testExplorationOptions, consumerAdapter, NullProgressMonitor.CreateInstance()); }
/// <inheritdoc /> public IList<TestPart> GetTestParts(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { if (reflectionPolicy == null) throw new ArgumentNullException("reflectionPolicy"); if (codeElement == null) throw new ArgumentNullException("codeElement"); return GetTestPartsImpl(reflectionPolicy, codeElement); }
/// <summary> /// Creates a test model builder. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/> is null.</exception> public ReflectionOnlyTestModelBuilder(IReflectionPolicy reflectionPolicy) { if (reflectionPolicy == null) { throw new ArgumentNullException("reflectionPolicy"); } this.reflectionPolicy = reflectionPolicy; }
/// <summary> /// Explores tests defined by the specified code element and populates the explorer's test model. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <param name="codeElement">The code element.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/>, /// <paramref name="codeElement"/> is null.</exception> public void Explore(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { if (reflectionPolicy == null) throw new ArgumentNullException("reflectionPolicy"); if (codeElement == null) throw new ArgumentNullException("codeElement"); ExploreImpl(reflectionPolicy, codeElement); }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly == null) { return; } try { MbUnit2TestExplorerEngine engine; if (!assemblyTestExplorerEngines.TryGetValue(assembly, out engine)) { Assembly loadedAssembly = assembly.Resolve(false); if (Reflector.IsUnresolved(loadedAssembly)) { engine = new MbUnit2ReflectiveTestExplorerEngine(TestModel, assembly); } else { engine = new MbUnit2NativeTestExplorerEngine(TestModel, loadedAssembly); } assemblyTestExplorerEngines.Add(assembly, engine); bool skipChildren = !(codeElement is IAssemblyInfo); engine.ExploreAssembly(skipChildren, unresolvedDependencies); for (int i = 0; i < unresolvedDependencies.Count; i++) { foreach (var entry in assemblyTestExplorerEngines) { if (entry.Key.FullName == unresolvedDependencies[i].Value) { unresolvedDependencies[i].Key.AddDependency(entry.Value.GetAssemblyTest()); unresolvedDependencies.RemoveAt(i--); break; } } } } ITypeInfo type = ReflectionUtils.GetType(codeElement); if (type != null) { engine.ExploreType(type); } } catch (Exception ex) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly, "An exception was thrown while exploring an MbUnit v2 test assembly.", ex)); } }
private void InitializeExplorerIfNeeded(IReflectionPolicy reflectionPolicy) { if (testModelBuilder != null) { return; } testModelBuilder = new DefaultTestModelBuilder(reflectionPolicy, (PatternTestModel)TestModel); evaluator = new DefaultPatternEvaluator(testModelBuilder, DeclarativePatternResolver.Instance); }
/// <summary> /// Creates a test model builder. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <param name="testModel">The underlying test model.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/> /// or <paramref name="testModel"/> is null.</exception> public DefaultTestModelBuilder(IReflectionPolicy reflectionPolicy, PatternTestModel testModel) { if (reflectionPolicy == null) throw new ArgumentNullException("reflectionPolicy"); if (testModel == null) throw new ArgumentNullException("testModel"); this.reflectionPolicy = reflectionPolicy; this.testModel = testModel; rootTestBuilder = new DefaultTestBuilder(this, testModel.RootTest); }
/// <inheritdoc /> public IList <TestPart> GetTestParts(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { if (reflectionPolicy == null) { throw new ArgumentNullException("reflectionPolicy"); } if (codeElement == null) { throw new ArgumentNullException("codeElement"); } return(GetTestPartsImpl(reflectionPolicy, codeElement)); }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly != null) { Version frameworkVersion = GetFrameworkVersion(assembly); if (frameworkVersion != null) { GetAssemblyTest(assembly, TestModel.RootTest, frameworkVersion); } } }
/// <summary> /// Explores tests defined by the specified code element and populates the explorer's test model. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <param name="codeElement">The code element.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/>, /// <paramref name="codeElement"/> is null.</exception> public void Explore(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { if (reflectionPolicy == null) { throw new ArgumentNullException("reflectionPolicy"); } if (codeElement == null) { throw new ArgumentNullException("codeElement"); } ExploreImpl(reflectionPolicy, codeElement); }
protected override void DescribeImpl(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, Gallio.Runtime.ProgressMonitoring.IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask("Describing tests.", 1)) { ForEachDriver(testFrameworkManager.SelectTestFrameworksForCodeElementsImpl( testFrameworkHandles, testFrameworkFallbackMode, testFrameworkOptions, codeElements), (driver, items, driverCount) => { driver.Describe(reflectionPolicy, items, testExplorationOptions, messageSink, progressMonitor.CreateSubProgressMonitor(1.0 / driverCount)); return(false); }); } }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly == null) return; try { MbUnit2TestExplorerEngine engine; if (! assemblyTestExplorerEngines.TryGetValue(assembly, out engine)) { Assembly loadedAssembly = assembly.Resolve(false); if (Reflector.IsUnresolved(loadedAssembly)) engine = new MbUnit2ReflectiveTestExplorerEngine(TestModel, assembly); else engine = new MbUnit2NativeTestExplorerEngine(TestModel, loadedAssembly); assemblyTestExplorerEngines.Add(assembly, engine); bool skipChildren = !(codeElement is IAssemblyInfo); engine.ExploreAssembly(skipChildren, unresolvedDependencies); for (int i = 0; i < unresolvedDependencies.Count; i++) { foreach (var entry in assemblyTestExplorerEngines) { if (entry.Key.FullName == unresolvedDependencies[i].Value) { unresolvedDependencies[i].Key.AddDependency(entry.Value.GetAssemblyTest()); unresolvedDependencies.RemoveAt(i--); break; } } } } ITypeInfo type = ReflectionUtils.GetType(codeElement); if (type != null) { engine.ExploreType(type); } } catch (Exception ex) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly, "An exception was thrown while exploring an MbUnit v2 test assembly.", ex)); } }
/// <inheritdoc /> public void Describe(IReflectionPolicy reflectionPolicy, IList<ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { if (reflectionPolicy == null) throw new ArgumentNullException("reflectionPolicy"); if (codeElements == null || codeElements.Contains(null)) throw new ArgumentNullException("codeElements"); if (testExplorationOptions == null) throw new ArgumentNullException("testExplorationOptions"); if (messageSink == null) throw new ArgumentNullException("messageSink"); if (progressMonitor == null) throw new ArgumentNullException("progressMonitor"); DescribeImpl(reflectionPolicy, codeElements, testExplorationOptions, messageSink, progressMonitor); }
private TestModel GenerateTestModel(IReflectionPolicy reflectionPolicy, IEnumerable <ICodeElementInfo> codeElements, IMessageSink messageSink) { using (TestExplorer testExplorer = CreateTestExplorer()) { foreach (var codeElement in codeElements) { testExplorer.Explore(reflectionPolicy, codeElement); } testExplorer.Finish(); TestModelSerializer.PublishTestModel(testExplorer.TestModel, messageSink); return(testExplorer.TestModel); } }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); Version frameworkVersion = GetFrameworkVersion(assembly); if (frameworkVersion != null) { ITypeInfo type = ReflectionUtils.GetType(codeElement); Test assemblyTest = GetAssemblyTest(assembly, TestModel.RootTest, frameworkVersion, type == null); if (type != null) { TryGetTypeTest(type, assemblyTest); } } }
/// <summary> /// Creates a test model builder. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <param name="testModel">The underlying test model.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/> /// or <paramref name="testModel"/> is null.</exception> public DefaultTestModelBuilder(IReflectionPolicy reflectionPolicy, PatternTestModel testModel) { if (reflectionPolicy == null) { throw new ArgumentNullException("reflectionPolicy"); } if (testModel == null) { throw new ArgumentNullException("testModel"); } this.reflectionPolicy = reflectionPolicy; this.testModel = testModel; rootTestBuilder = new DefaultTestBuilder(this, testModel.RootTest); }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly == null) { return; } try { NUnitTestExplorerEngine engine; if (!assemblyTestExplorerEngines.TryGetValue(assembly, out engine)) { Assembly loadedAssembly = assembly.Resolve(false); if (Reflector.IsUnresolved(loadedAssembly)) { engine = new NUnitReflectiveTestExplorerEngine(TestModel, assembly); } else { engine = new NUnitNativeTestExplorerEngine(TestModel, loadedAssembly); } assemblyTestExplorerEngines.Add(assembly, engine); bool skipChildren = !(codeElement is IAssemblyInfo); engine.ExploreAssembly(skipChildren); } ITypeInfo type = ReflectionUtils.GetType(codeElement); if (type != null) { engine.ExploreType(type); } } catch (Exception ex) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly, "An exception was thrown while exploring an NUnit test assembly.", ex)); } }
protected override void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { IAssemblyInfo assembly = ReflectionUtils.GetAssembly(codeElement); if (assembly == null) return; try { NUnitTestExplorerEngine engine; if (!assemblyTestExplorerEngines.TryGetValue(assembly, out engine)) { Assembly loadedAssembly = assembly.Resolve(false); if (Reflector.IsUnresolved(loadedAssembly)) engine = new NUnitReflectiveTestExplorerEngine(TestModel, assembly); else engine = new NUnitNativeTestExplorerEngine(TestModel, loadedAssembly); assemblyTestExplorerEngines.Add(assembly, engine); bool skipChildren = !(codeElement is IAssemblyInfo); engine.ExploreAssembly(skipChildren); } ITypeInfo type = ReflectionUtils.GetType(codeElement); if (type != null) { engine.ExploreType(type); } } catch (Exception ex) { TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly, "An exception was thrown while exploring an NUnit test assembly.", ex)); } }
protected override IList <TestPart> GetTestPartsImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { var evaluator = CreateReflectionOnlyPatternEvaluator(reflectionPolicy); return(evaluator.GetTestParts(codeElement, GetAutomaticPattern(codeElement))); }
private void Describe(IReflectionPolicy reflectionPolicy, IList<ICodeElementInfo> codeElements, ConsumerAdapter consumerAdapter) { var testDriver = CreateTestDriver(); var testExplorationOptions = new TestExplorationOptions(); testDriver.Describe(reflectionPolicy, codeElements, testExplorationOptions, consumerAdapter, NullProgressMonitor.CreateInstance()); }
/// <summary> /// Describes tests via reflection over code elements. /// </summary> /// <remarks> /// <para> /// The default implementation does nothing. Subclasses may override to enable tests /// to be described via reflection only. This is required for ReSharper integration. /// </para> /// </remarks> /// <param name="reflectionPolicy">The reflection policy, not null.</param> /// <param name="codeElements">The enumeration of code elements, usually <see cref="ITypeInfo" /> /// and <see cref="IAssemblyInfo" /> objects, that might contain tests to be described, not null.</param> /// <param name="testExplorationOptions">The test exploration options, not null.</param> /// <param name="messageSink">The message sink to receive test exploration messages, not null.</param> /// <param name="progressMonitor">The progress monitor, not null.</param> protected virtual void DescribeImpl(IReflectionPolicy reflectionPolicy, IList <ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { }
/// <summary> /// Explores tests defined by the specified code element and populates the explorer's test model. /// </summary> /// <param name="reflectionPolicy">The reflection policy, not null.</param> /// <param name="codeElement">The code element, not null.</param> protected abstract void ExploreImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement);
/// <summary> /// Gets the test parts represented by a code element. /// </summary> /// <remarks> /// <para> /// The default implementation always returns an empty array. Subclasses may override /// this method to provide information about code elements that represent tests. /// </para> /// </remarks> /// <param name="reflectionPolicy">The reflection policy, not null.</param> /// <param name="codeElement">The code element, not null.</param> /// <returns>The test parts, or an empty array if none.</returns> protected virtual IList <TestPart> GetTestPartsImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { return(EmptyArray <TestPart> .Instance); }
private static IPatternEvaluator CreateReflectionOnlyPatternEvaluator(IReflectionPolicy reflectionPolicy) { var testModelBuilder = new ReflectionOnlyTestModelBuilder(reflectionPolicy); return new DefaultPatternEvaluator(testModelBuilder, DeclarativePatternResolver.Instance); }
/// <summary> /// Gets the test parts represented by a code element. /// </summary> /// <remarks> /// <para> /// The default implementation always returns an empty array. Subclasses may override /// this method to provide information about code elements that represent tests. /// </para> /// </remarks> /// <param name="reflectionPolicy">The reflection policy, not null.</param> /// <param name="codeElement">The code element, not null.</param> /// <returns>The test parts, or an empty array if none.</returns> protected virtual IList<TestPart> GetTestPartsImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { return EmptyArray<TestPart>.Instance; }
/// <inheritdoc /> protected override sealed void DescribeImpl(IReflectionPolicy reflectionPolicy, IList<ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { using (progressMonitor.BeginTask(string.Format("Describing {0} tests.", FrameworkName), 100)) { progressMonitor.SetStatus("Building the test model."); GenerateTestModel(reflectionPolicy, codeElements, messageSink); } }
private static IPatternEvaluator CreateReflectionOnlyPatternEvaluator(IReflectionPolicy reflectionPolicy) { var testModelBuilder = new ReflectionOnlyTestModelBuilder(reflectionPolicy); return(new DefaultPatternEvaluator(testModelBuilder, DeclarativePatternResolver.Instance)); }
protected override IList<TestPart> GetTestPartsImpl(IReflectionPolicy reflectionPolicy, ICodeElementInfo codeElement) { var evaluator = CreateReflectionOnlyPatternEvaluator(reflectionPolicy); return evaluator.GetTestParts(codeElement, GetAutomaticPattern(codeElement)); }
private TestModel GenerateTestModel(IReflectionPolicy reflectionPolicy, IEnumerable<ICodeElementInfo> codeElements, IMessageSink messageSink) { using (TestExplorer testExplorer = CreateTestExplorer()) { foreach (var codeElement in codeElements) testExplorer.Explore(reflectionPolicy, codeElement); testExplorer.Finish(); TestModelSerializer.PublishTestModel(testExplorer.TestModel, messageSink); return testExplorer.TestModel; } }
/// <summary> /// Describes tests via reflection over code elements. /// </summary> /// <remarks> /// <para> /// The default implementation does nothing. Subclasses may override to enable tests /// to be described via reflection only. This is required for ReSharper integration. /// </para> /// </remarks> /// <param name="reflectionPolicy">The reflection policy, not null.</param> /// <param name="codeElements">The enumeration of code elements, usually <see cref="ITypeInfo" /> /// and <see cref="IAssemblyInfo" /> objects, that might contain tests to be described, not null.</param> /// <param name="testExplorationOptions">The test exploration options, not null.</param> /// <param name="messageSink">The message sink to receive test exploration messages, not null.</param> /// <param name="progressMonitor">The progress monitor, not null.</param> protected virtual void DescribeImpl(IReflectionPolicy reflectionPolicy, IList<ICodeElementInfo> codeElements, TestExplorationOptions testExplorationOptions, IMessageSink messageSink, IProgressMonitor progressMonitor) { }
private void InitializeExplorerIfNeeded(IReflectionPolicy reflectionPolicy) { if (testModelBuilder != null) return; testModelBuilder = new DefaultTestModelBuilder(reflectionPolicy, (PatternTestModel)TestModel); evaluator = new DefaultPatternEvaluator(testModelBuilder, DeclarativePatternResolver.Instance); }