internal DiscovererEnumerator(IRequestData requestData, DiscoveryResultCache discoveryResultCache, ITestPlatformEventSource testPlatformEventSource) { this.discoveryResultCache = discoveryResultCache; this.testPlatformEventSource = testPlatformEventSource; this.requestData = requestData; this.assemblyProperties = new AssemblyProperties(); }
/// <summary> /// Initializes a new instance of the <see cref="DiscovererEnumerator"/> class. /// </summary> /// <param name="requestData">The request data for providing discovery services and data.</param> /// <param name="discoveryResultCache"> The discovery result cache. </param> /// <param name="testPlatformEventSource">Telemetry events receiver</param> /// <param name="assemblyProperties">Information on the assemblies being discovered</param> /// <param name="token">Cancellation Token to abort discovery</param> public DiscovererEnumerator(IRequestData requestData, DiscoveryResultCache discoveryResultCache, ITestPlatformEventSource testPlatformEventSource, IAssemblyProperties assemblyProperties, CancellationToken token) { // Added this to make class testable, needed a PEHeader mocked Instance this.discoveryResultCache = discoveryResultCache; this.testPlatformEventSource = testPlatformEventSource; this.requestData = requestData; this.assemblyProperties = assemblyProperties; this.cancellationToken = token; }
public AssemblyPropertiesTests() { this.assemblyProperties = new AssemblyProperties(); }
/// <summary> /// Get assembly type to sources map. /// </summary> /// <param name="sources">Sources.</param> /// <param name="assemblyType">Assembly type.</param> /// <returns>Sources with mathcing assembly type.</returns> private static IDictionary <AssemblyType, IList <string> > GetAssemblyTypeToSoucesMap(IEnumerable <string> sources, IAssemblyProperties assemblyProperties) { var assemblyTypeToSoucesMap = new Dictionary <AssemblyType, IList <string> >() { { AssemblyType.Native, new List <string>() }, { AssemblyType.Managed, new List <string>() }, { AssemblyType.None, new List <string>() } }; if (sources != null && sources.Any()) { foreach (string source in sources) { var sourcesList = IsAssembly(source) ? assemblyTypeToSoucesMap[assemblyProperties.GetAssemblyType(source)] : assemblyTypeToSoucesMap[AssemblyType.None]; sourcesList.Add(source); } } return(assemblyTypeToSoucesMap); }
/// <summary> /// Get the discoverers matching with the parameter sources /// </summary> /// <param name="extensionAssembly"> The extension assembly. </param> /// <param name="sources"> The sources. </param> /// <param name="logger"> The logger instance. </param> /// <returns> The map between an extension type and a source. </returns> internal static Dictionary <LazyExtension <ITestDiscoverer, ITestDiscovererCapabilities>, IEnumerable <string> > GetDiscovererToSourcesMap( string extensionAssembly, IEnumerable <string> sources, IMessageLogger logger, IAssemblyProperties assemblyProperties) { var allDiscoverers = GetDiscoverers(extensionAssembly, throwOnError: true); if (allDiscoverers == null || !allDiscoverers.Any()) { var sourcesString = string.Join(" ", sources); // No discoverer available, log a warning logger.SendMessage( TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestRunFailed_NoDiscovererFound_NoTestsAreAvailableInTheSources, sourcesString)); return(null); } IDictionary <AssemblyType, IList <string> > assemblyTypeToSoucesMap = null; var result = new Dictionary <LazyExtension <ITestDiscoverer, ITestDiscovererCapabilities>, IEnumerable <string> >(); var sourcesForWhichNoDiscovererIsAvailable = new List <string>(sources); foreach (var discoverer in allDiscoverers) { var sourcesToCheck = sources; if (discoverer.Metadata.AssemblyType == AssemblyType.Native || discoverer.Metadata.AssemblyType == AssemblyType.Managed) { assemblyTypeToSoucesMap = assemblyTypeToSoucesMap ?? GetAssemblyTypeToSoucesMap(sources, assemblyProperties); sourcesToCheck = assemblyTypeToSoucesMap[AssemblyType.None].Concat(assemblyTypeToSoucesMap[discoverer.Metadata.AssemblyType]); } // Find the sources which this discoverer can look at. // Based on whether it is registered for a matching file extension or no file extensions at all. var matchingSources = (from source in sourcesToCheck where (discoverer.Metadata.FileExtension == null || discoverer.Metadata.FileExtension.Contains( Path.GetExtension(source), StringComparer.OrdinalIgnoreCase)) select source).ToList(); // ToList is required to actually execute the query // Update the source list for which no matching source is available. if (matchingSources.Any()) { sourcesForWhichNoDiscovererIsAvailable = sourcesForWhichNoDiscovererIsAvailable.Except(matchingSources, StringComparer.OrdinalIgnoreCase) .ToList(); result.Add(discoverer, matchingSources); } } if (EqtTrace.IsWarningEnabled && sourcesForWhichNoDiscovererIsAvailable != null) { foreach (var source in sourcesForWhichNoDiscovererIsAvailable) { // Log a warning to logfile, not to the "default logger for discovery time messages". EqtTrace.Warning( "No test discoverer is registered to perform discovery for the type of test source '{0}'. Register a test discoverer for this source type and try again.", source); } } return(result); }