Skip to content

Commit 3463fdf

Browse files
authored
Merge pull request #1580 from paulvanbrenk/testAdapterRegKey
Test adapter reg key
2 parents af12467 + 848fa92 commit 3463fdf

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Common/Product/TestAdapter/VsProjectExtensions.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Diagnostics;
6+
using Microsoft.NodejsTools;
67
using Microsoft.VisualStudio;
8+
using Microsoft.VisualStudio.Shell;
79
using Microsoft.VisualStudio.Shell.Flavor;
810
using Microsoft.VisualStudio.Shell.Interop;
911
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
@@ -79,6 +81,14 @@ private static string GetAggregateProjectTypeGuids(this IVsProject project)
7981
/// </summary>
8082
public static bool IsTestProject(this IVsProject project, Guid projectGuid)
8183
{
84+
// Overload IsTestProject method to check if we should use this test adapter
85+
// at all. This is much less error prone than adding this check to all locations
86+
// where this method is called.
87+
if (!IsTestAdapaterEnabled())
88+
{
89+
return false;
90+
}
91+
8292
ValidateArg.NotNull(project, "project");
8393

8494
var projectTypeGuids = project.GetAggregateProjectTypeGuids();
@@ -87,6 +97,27 @@ public static bool IsTestProject(this IVsProject project, Guid projectGuid)
8797
return (projectTypeGuids.IndexOf(projectGuid.ToString(), StringComparison.OrdinalIgnoreCase) >= 0);
8898
}
8999

100+
private static bool checkedRegistryForTestAdapterEnabled = false;
101+
private static bool registryValueForTestAdapterEnabled = true;
102+
103+
public static bool IsTestAdapaterEnabled()
104+
{
105+
if (!checkedRegistryForTestAdapterEnabled)
106+
{
107+
using (var nodeKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings, true).CreateSubKey(NodejsConstants.BaseRegistryKey))
108+
using (var optionsKey = nodeKey.CreateSubKey("Options"))
109+
using (var categoryKey = optionsKey.CreateSubKey("testing"))
110+
{
111+
// If the value is set to something we disable this testadapter
112+
registryValueForTestAdapterEnabled = string.IsNullOrEmpty(categoryKey.GetValue("testadapter") as string);
113+
}
114+
115+
checkedRegistryForTestAdapterEnabled = true;
116+
}
117+
118+
return registryValueForTestAdapterEnabled;
119+
}
120+
90121
/// <summary>
91122
/// Gets the project home directory.
92123
/// </summary>

0 commit comments

Comments
 (0)