How to use GetDiscoverers method of Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery.DiscovererEnumerator class

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery.DiscovererEnumerator.GetDiscoverers

DiscovererEnumerator.cs

Source:DiscovererEnumerator.cs Github

copy

Full Screen

...273 IEnumerable<string> sources,274 IMessageLogger logger,275 IAssemblyProperties assemblyProperties)276 {277 var allDiscoverers = GetDiscoverers(extensionAssembly, throwOnError: true);278 if (allDiscoverers == null || !allDiscoverers.Any())279 {280 var sourcesString = string.Join(" ", sources);281 // No discoverer available, log a warning282 logger.SendMessage(283 TestMessageLevel.Warning,284 string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.TestRunFailed_NoDiscovererFound_NoTestsAreAvailableInTheSources, sourcesString));285 return null;286 }287 IDictionary<AssemblyType, IList<string>> assemblyTypeToSoucesMap = null;288 var result = new Dictionary<LazyExtension<ITestDiscoverer, ITestDiscovererCapabilities>, IEnumerable<string>>();289 var sourcesForWhichNoDiscovererIsAvailable = new List<string>(sources);290 foreach (var discoverer in allDiscoverers)291 {292 var sourcesToCheck = sources;293 if (discoverer.Metadata.AssemblyType == AssemblyType.Native ||294 discoverer.Metadata.AssemblyType == AssemblyType.Managed)295 {296 assemblyTypeToSoucesMap = assemblyTypeToSoucesMap ?? GetAssemblyTypeToSoucesMap(sources, assemblyProperties);297 sourcesToCheck = assemblyTypeToSoucesMap[AssemblyType.None].Concat(assemblyTypeToSoucesMap[discoverer.Metadata.AssemblyType]);298 }299 // Find the sources which this discoverer can look at. 300 // Based on whether it is registered for a matching file extension or no file extensions at all.301 var matchingSources = (from source in sourcesToCheck302 where303 (discoverer.Metadata.FileExtension == null304 || discoverer.Metadata.FileExtension.Contains(305 Path.GetExtension(source),306 StringComparer.OrdinalIgnoreCase))307 select source).ToList(); // ToList is required to actually execute the query 308 // Update the source list for which no matching source is available.309 if (matchingSources.Any())310 {311 sourcesForWhichNoDiscovererIsAvailable =312 sourcesForWhichNoDiscovererIsAvailable.Except(matchingSources, StringComparer.OrdinalIgnoreCase)313 .ToList();314 result.Add(discoverer, matchingSources);315 }316 }317 if (EqtTrace.IsWarningEnabled && sourcesForWhichNoDiscovererIsAvailable != null)318 {319 foreach (var source in sourcesForWhichNoDiscovererIsAvailable)320 {321 // Log a warning to logfile, not to the "default logger for discovery time messages".322 EqtTrace.Warning(323 "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.",324 source);325 }326 }327 return result;328 }329 /// <summary>330 /// Get assembly type to sources map.331 /// </summary>332 /// <param name="sources">Sources.</param>333 /// <param name="assemblyType">Assembly type.</param>334 /// <returns>Sources with mathcing assembly type.</returns>335 private static IDictionary<AssemblyType, IList<string>> GetAssemblyTypeToSoucesMap(IEnumerable<string> sources, IAssemblyProperties assemblyProperties)336 {337 var assemblyTypeToSoucesMap = new Dictionary<AssemblyType, IList<string>>()338 {339 { AssemblyType.Native, new List<string>()},340 { AssemblyType.Managed, new List<string>()},341 { AssemblyType.None, new List<string>()}342 };343 if (sources != null && sources.Any())344 {345 foreach (string source in sources)346 {347 var sourcesList = IsAssembly(source) ?348 assemblyTypeToSoucesMap[assemblyProperties.GetAssemblyType(source)] :349 assemblyTypeToSoucesMap[AssemblyType.None];350 sourcesList.Add(source);351 }352 }353 return assemblyTypeToSoucesMap;354 }355 /// <summary>356 /// Finds if a file is an assembly or not.357 /// </summary>358 /// <param name="filePath">File path.</param>359 /// <returns>True if file is an assembly.</returns>360 private static bool IsAssembly(string filePath)361 {362 var fileExtension = Path.GetExtension(filePath);363 return ".dll".Equals(fileExtension, StringComparison.OrdinalIgnoreCase) ||364 ".exe".Equals(fileExtension, StringComparison.OrdinalIgnoreCase);365 }366 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]367 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design",368 "CA1006:DoNotNestGenericTypesInMemberSignatures")]369 private static IEnumerable<LazyExtension<ITestDiscoverer, ITestDiscovererCapabilities>> GetDiscoverers(370 string extensionAssembly,371 bool throwOnError)372 {373 try374 {375 if (string.IsNullOrEmpty(extensionAssembly) || string.Equals(extensionAssembly, ObjectModel.Constants.UnspecifiedAdapterPath))376 {377 // full discovery.378 return TestDiscoveryExtensionManager.Create().Discoverers;379 }380 else381 {382 return TestDiscoveryExtensionManager.GetDiscoveryExtensionManager(extensionAssembly).Discoverers;383 }...

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;9{10 {11 static void Main(string[] args)12 {13 var discovererEnumerator = new DiscovererEnumerator();14 var discoverers = discovererEnumerator.GetDiscoverers();15 foreach (var discoverer in discoverers)16 {17 Console.WriteLine(discoverer.Key);18 }19 }20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;28using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;29using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;30{31 {32 static void Main(string[] args)33 {34 var discovererEnumerator = new DiscovererEnumerator();35 var extensions = discovererEnumerator.GetExtensions();36 foreach (var extension in extensions)37 {38 Console.WriteLine(extension);39 }40 }41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;49using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;50using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;51{52 {53 static void Main(string[] args)54 {55 var discovererEnumerator = new DiscovererEnumerator();56 var extensions = discovererEnumerator.GetExtensions();57 foreach (var extension in extensions)58 {59 Console.WriteLine(extension);60 }61 }62 }63}64using System;65using System.Collections.Generic;66using System.Linq;67using System.Text;68using System.Threading.Tasks;69using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;70using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;71using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;72{

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;9{10 {11 static void Main(string[] args)12 {13 var discovererEnumerator = new DiscovererEnumerator();14 var discoverers = discovererEnumerator.GetDiscoverers();15 foreach (var discoverer in discoverers)16 {17 Console.WriteLine(discoverer);18 }19 }20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;28using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;29using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;30{31 {32 static void Main(string[] args)33 {34 var discovererEnumerator = new DiscovererEnumerator();35 var extensions = discovererEnumerator.GetExtensions();36 foreach (var extension in extensions)37 {38 Console.WriteLine(extension);39 }40 }41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;49using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;50using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;51{52 {53 static void Main(string[] args)54 {55 var discovererEnumerator = new DiscovererEnumerator();56 var extensions = discovererEnumerator.GetExtensions();57 foreach (var extension in extensions)58 {59 Console.WriteLine(extension);60 }61 }62 }63}64using System;65using System.Collections.Generic;66using System.Linq;67using System.Text;68using System.Threading.Tasks;69using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;70using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;71using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;72{

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;9{10 {11 static void Main(string[] args)12 {13 var discovererEnumerator = new DiscovererEnumerator();14 var discoverers = discovererEnumerator.GetDiscoverers();15 Console.WriteLine(discoverers.Count);16 Console.ReadLine();17 }18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;26using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;27using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;28{29 {30 static void Main(string[] args)31 {32 var executorEnumerator = new ExecutorEnumerator();33 var executors = executorEnumerator.GetExecutor("executorUri");34 Console.WriteLine(executors.Count);35 Console.ReadLine();36 }37 }38}39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using System.Threading.Tasks;44using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution;45using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;46using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;47{48 {49 static void Main(string[] args)50 {51 var executorEnumerator = new ExecutorEnumerator();52 var executors = executorEnumerator.GetExecutors();53 Console.WriteLine(executors.Count);54 Console.ReadLine();55 }56 }57}58using System;59using System.Collections.Generic;60using System.Linq;61using System.Text;62using System.Threading.Tasks;63using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Engine;64using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;65using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;66{67 {68 static void Main(string[] args)69 {70 var engineExtensions = new EngineExtensions();

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 static void Main(string[] args)11 {12 DiscovererEnumerator discovererEnumerator = new DiscovererEnumerator();13 IEnumerable<LazyExtension<ITestDiscoverer, ITestDiscovererCapabilities>> discoverers = discovererEnumerator.GetDiscoverers();14 foreach (var discoverer in discoverers)

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 static void Main(string[] args)11 {12 var discovererEnumerator = new DiscovererEnumerator();13 var discoverers = discovererEnumerator.GetDiscoverers();14 foreach (var discoverer in discoverers)15 {16 Console.WriteLine("Discoverer: " + discoverer.Key);17 foreach (var fileExtension in discoverer.Value)18 {19 Console.WriteLine("File Extension: " + fileExtension);20 }21 }22 Console.ReadLine();23 }24 }25}

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1using System;2using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;4using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;5{6 {7 static void Main(string[] args)8 {9 var discovererEnumerator = new DiscovererEnumerator();10 var discoverers = discovererEnumerator.GetDiscoverers(true);11 foreach (var discoverer in discoverers)12 {13 Console.WriteLine(discoverer.Value.Value);14 }15 }16 }17}18using System;19using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;20using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;21using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;22{23 {24 static void Main(string[] args)25 {26 var discovererEnumerator = new DiscovererEnumerator();27 var discoverers = discovererEnumerator.GetDiscoverers(true);28 foreach (var discoverer in discoverers)29 {30 var extension = discovererEnumerator.GetExtension(discoverer.Key);31 Console.WriteLine(extension);32 }33 }34 }35}36using System;37using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;38using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;39using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;40{41 {42 static void Main(string[] args)43 {44 var discovererEnumerator = new DiscovererEnumerator();45 var discoverers = discovererEnumerator.GetDiscoverers(true);46 foreach (var discoverer in discoverers)47 {48 var extension = discovererEnumerator.GetExtension(discoverer.Key);49 Console.WriteLine(extension);50 }51 }52 }53}54using System;55using System.Collections.Generic;56using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;57using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;58using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;59{60 {61 static void Main(string[] args)62 {63 var discovererEnumerator = new DiscovererEnumerator();

Full Screen

Full Screen

GetDiscoverers

Using AI Code Generation

copy

Full Screen

1var discoverers = DiscovererEnumerator.GetDiscoverers();2foreach(var discoverer in discoverers)3{4 Console.WriteLine(discoverer.Key);5 Console.WriteLine(discoverer.Value);6}7var runners = DiscovererEnumerator.GetRunners();8foreach(var runner in runners)9{10 Console.WriteLine(runner.Key);11 Console.WriteLine(runner.Value);12}13var defaultDiscoverer = DiscovererEnumerator.GetDefaultDiscoverer();14Console.WriteLine(defaultDiscoverer);15var defaultRunner = DiscovererEnumerator.GetDefaultRunner();16Console.WriteLine(defaultRunner);17var extensions = DiscovererEnumerator.GetTestPlatformExtensions();18foreach(var extension in extensions)19{20 Console.WriteLine(extension.Key);21 Console.WriteLine(extension.Value);22}23var defaultExtension = DiscovererEnumerator.GetDefaultTestPlatformExtension();24Console.WriteLine(defaultExtension);25var extensions = DiscovererEnumerator.GetTestPlatformExtensions();26foreach(var extension in extensions)27{28 Console.WriteLine(extension.Key);29 Console.WriteLine(extension.Value);30}31var defaultExtension = DiscovererEnumerator.GetDefaultTestPlatformExtension();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful