private static IList<TestData> Explore(IEnumerable<string> sources, ILogger frameworkLogger) { try { var testDriver = GetTestDriver(frameworkLogger); var tests = new List<TestData>(); var messageConsumer = new MessageConsumer() .Handle<TestDiscoveredMessage>(message => { if (message.Test.IsTestCase) tests.Add(message.Test); }) .Handle<AnnotationDiscoveredMessage>(message => message.Annotation.Log(frameworkLogger, true)); var loader = new ReflectionOnlyAssemblyLoader(); var assemblyInfos = sources.Select(source => LoadAssembly(source, loader)).Where(assembly => assembly != null).ToList(); var testExplorationOptions = new TestExplorationOptions(); testDriver.Describe(loader.ReflectionPolicy, assemblyInfos, testExplorationOptions, messageConsumer, NullProgressMonitor.CreateInstance()); return ResetCollectionForExposedTests(tests) ? null : tests; } catch (Exception ex) { frameworkLogger.Log(LogSeverity.Error, "Gallio failed to load tests", ex); return null; } }
public void FallsBackOnNativelyLoadableAssemblies() { ReflectionOnlyAssemblyLoader loader = new ReflectionOnlyAssemblyLoader(); Assembly nativeAssembly = typeof(ReflectionOnlyAssemblyLoader).Assembly; IAssemblyInfo assembly = loader.ReflectionPolicy.LoadAssembly(nativeAssembly.GetName()); Assert.AreEqual(AssemblyUtils.GetAssemblyLocalPath(nativeAssembly), assembly.Path); }
public void LoadsAssembliesFromHintPathPreferentially() { ReflectionOnlyAssemblyLoader loader = new ReflectionOnlyAssemblyLoader(); string binDir = Path.GetDirectoryName(AssemblyUtils.GetAssemblyLocalPath(typeof(ReflectionOnlyAssemblyLoader).Assembly)); loader.AddHintDirectory("non-existent-folder-is-ignored-without-sideeffects"); loader.AddHintDirectory(binDir); IAssemblyInfo assembly = loader.ReflectionPolicy.LoadAssembly(new AssemblyName("Gallio")); // would ordinarily be loaded from somewhere else Assert.StartsWith(assembly.Path, binDir); }
public override ICollection Load(string location, ProjectData projectData, IWarningHandler warningHandler) { // Skip loading if the extension is not fully initalized unless we are not // running in Visual Studio (because we are running in MSTest instead). if (!TipShellExtension.IsInitialized && ShellEnvironment.IsRunningInVisualStudio) return EmptyArray<TestElement>.Instance; // Explore the tests. ITestFrameworkManager testFrameworkManager = RuntimeAccessor.ServiceLocator.Resolve<ITestFrameworkManager>(); WarningLogger logger = new WarningLogger(warningHandler); ReflectionOnlyAssemblyLoader loader = new ReflectionOnlyAssemblyLoader(); loader.AddHintDirectory(Path.GetDirectoryName(location)); IAssemblyInfo assembly = loader.ReflectionPolicy.LoadAssemblyFrom(location); var testFrameworkSelector = new TestFrameworkSelector() { Filter = testFrameworkHandle => testFrameworkHandle.Id != "MSTestAdapter.TestFramework", FallbackMode = TestFrameworkFallbackMode.Approximate }; ITestDriver driver = testFrameworkManager.GetTestDriver(testFrameworkSelector, logger); TestExplorationOptions testExplorationOptions = new TestExplorationOptions(); ArrayList tests = new ArrayList(); MessageConsumer messageConsumer = new MessageConsumer() .Handle<TestDiscoveredMessage>(message => { if (message.Test.IsTestCase) tests.Add(GallioTestElementFactory.CreateTestElement(message.Test, location, projectData)); }) .Handle<AnnotationDiscoveredMessage>(message => { message.Annotation.Log(logger, true); }); driver.Describe(loader.ReflectionPolicy, new ICodeElementInfo[] { assembly }, testExplorationOptions, messageConsumer, NullProgressMonitor.CreateInstance()); return tests; }
private static ICodeElementInfo LoadAssembly(string source, ReflectionOnlyAssemblyLoader loader) { loader.AddHintDirectory(Path.GetDirectoryName(source)); return loader.ReflectionPolicy.LoadAssemblyFrom(source); }
public void AddHintDirectoryThrowsWhenPathIsNull() { ReflectionOnlyAssemblyLoader loader = new ReflectionOnlyAssemblyLoader(); Assert.Throws<ArgumentNullException>(delegate { loader.AddHintDirectory(null); }); }