/// <summary> /// Gets test extensions from a given assembly. /// </summary> /// <param name="assembly">Assembly to check for test extension availability</param> /// <param name="pluginInfos">Test extensions collection to add to.</param> /// <typeparam name="TPluginInfo"> /// Type of Test Plugin Information. /// </typeparam> /// <typeparam name="TExtension"> /// Type of Extensions. /// </typeparam> private void GetTestExtensionsFromAssembly <TPluginInfo, TExtension>(Assembly assembly, Dictionary <string, TPluginInfo> pluginInfos) where TPluginInfo : TestPluginInformation { Debug.Assert(assembly != null, "null assembly"); Debug.Assert(pluginInfos != null, "null pluginInfos"); IEnumerable <Type> types; Type extension = typeof(TExtension); try { types = TypesToLoadUtilities.GetTypesToLoad(assembly); if (!types.Any()) { types = assembly.GetTypes().Where(type => type.GetTypeInfo().IsClass&& !type.GetTypeInfo().IsAbstract); } } catch (ReflectionTypeLoadException e) { EqtTrace.Warning("TestPluginDiscoverer: Failed to get types from assembly '{0}'. Skipping test extension scan for this assembly. Error: {1}", assembly.FullName, e.ToString()); if (e.LoaderExceptions != null) { foreach (var ex in e.LoaderExceptions) { EqtTrace.Warning("LoaderExceptions: {0}", ex); } } return; } if (types != null && types.Any()) { foreach (var type in types) { GetTestExtensionFromType(type, extension, pluginInfos); } } }
public void TypesToLoadAttributeTests() { var environment = new IntegrationTestEnvironment(); var extensionsDirectory = environment.ExtensionsDirectory; var extensionsToVerify = new Dictionary <string, string[]> { { "Microsoft.TestPlatform.Extensions.EventLogCollector.dll", new[] { "Microsoft.TestPlatform.Extensions.EventLogCollector.EventLogDataCollector" } }, { "Microsoft.TestPlatform.Extensions.BlameDataCollector.dll", new[] { "Microsoft.TestPlatform.Extensions.BlameDataCollector.BlameLogger", "Microsoft.TestPlatform.Extensions.BlameDataCollector.BlameCollector" } }, { "Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger.dll", new[] { "Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger" } }, { "Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.dll", new[] { "Microsoft.VisualStudio.TestPlatform.Extensions.TrxLogger.TrxLogger" } }, { "Microsoft.TestPlatform.TestHostRuntimeProvider.dll", new[] { "Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DefaultTestHostManager", "Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager" } } }; foreach (var extension in extensionsToVerify.Keys) { var assemblyFile = Path.Combine(extensionsDirectory, extension); var assembly = Assembly.LoadFrom(assemblyFile); var expected = extensionsToVerify[extension]; var actual = TypesToLoadUtilities.GetTypesToLoad(assembly).Select(i => i.FullName).ToArray(); CollectionAssert.AreEquivalent(expected, actual, $"Specified types using TypesToLoadAttribute in \"{extension}\" assembly doesn't match the expected."); } }