From 7c640d111ca47983ae5c2327dfb3670ff8e31040 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Mon, 15 May 2017 13:53:53 -0700 Subject: [PATCH 1/2] Add regkey to disable the testadapter. --- .../TestAdapter/VsProjectExtensions.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Common/Product/TestAdapter/VsProjectExtensions.cs b/Common/Product/TestAdapter/VsProjectExtensions.cs index f79e96dfe..4e786f0de 100644 --- a/Common/Product/TestAdapter/VsProjectExtensions.cs +++ b/Common/Product/TestAdapter/VsProjectExtensions.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using Microsoft.NodejsTools; using Microsoft.VisualStudio; +using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Flavor; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -79,6 +81,11 @@ private static string GetAggregateProjectTypeGuids(this IVsProject project) /// public static bool IsTestProject(this IVsProject project, Guid projectGuid) { + if (!IsTestAdapaterEnabled()) + { + return false; + } + ValidateArg.NotNull(project, "project"); var projectTypeGuids = project.GetAggregateProjectTypeGuids(); @@ -87,6 +94,21 @@ public static bool IsTestProject(this IVsProject project, Guid projectGuid) return (projectTypeGuids.IndexOf(projectGuid.ToString(), StringComparison.OrdinalIgnoreCase) >= 0); } + public static bool IsTestAdapaterEnabled() + { + using (var nodeKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings, true).CreateSubKey(NodejsConstants.BaseRegistryKey)) + { + using (var optionsKey = nodeKey.CreateSubKey("Options")) + { + using (var categoryKey = optionsKey.CreateSubKey("testing")) + { + // If the value is set to something we disable this testadapter + return string.IsNullOrEmpty(categoryKey.GetValue("testadapter") as string); + } + } + } + } + /// /// Gets the project home directory. /// From 848fa92ea1cebc9831a71a8e015cc845d1a2b805 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 16 May 2017 15:07:49 -0700 Subject: [PATCH 2/2] PR Feedback --- .../TestAdapter/VsProjectExtensions.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Common/Product/TestAdapter/VsProjectExtensions.cs b/Common/Product/TestAdapter/VsProjectExtensions.cs index 4e786f0de..0df65b0da 100644 --- a/Common/Product/TestAdapter/VsProjectExtensions.cs +++ b/Common/Product/TestAdapter/VsProjectExtensions.cs @@ -81,6 +81,9 @@ private static string GetAggregateProjectTypeGuids(this IVsProject project) /// public static bool IsTestProject(this IVsProject project, Guid projectGuid) { + // Overload IsTestProject method to check if we should use this test adapter + // at all. This is much less error prone than adding this check to all locations + // where this method is called. if (!IsTestAdapaterEnabled()) { return false; @@ -94,19 +97,25 @@ public static bool IsTestProject(this IVsProject project, Guid projectGuid) return (projectTypeGuids.IndexOf(projectGuid.ToString(), StringComparison.OrdinalIgnoreCase) >= 0); } + private static bool checkedRegistryForTestAdapterEnabled = false; + private static bool registryValueForTestAdapterEnabled = true; + public static bool IsTestAdapaterEnabled() { - using (var nodeKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings, true).CreateSubKey(NodejsConstants.BaseRegistryKey)) + if (!checkedRegistryForTestAdapterEnabled) { + using (var nodeKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings, true).CreateSubKey(NodejsConstants.BaseRegistryKey)) using (var optionsKey = nodeKey.CreateSubKey("Options")) + using (var categoryKey = optionsKey.CreateSubKey("testing")) { - using (var categoryKey = optionsKey.CreateSubKey("testing")) - { - // If the value is set to something we disable this testadapter - return string.IsNullOrEmpty(categoryKey.GetValue("testadapter") as string); - } + // If the value is set to something we disable this testadapter + registryValueForTestAdapterEnabled = string.IsNullOrEmpty(categoryKey.GetValue("testadapter") as string); } + + checkedRegistryForTestAdapterEnabled = true; } + + return registryValueForTestAdapterEnabled; } ///