Skip to content

Commit c2cda47

Browse files
authored
Adapter to honour CollectSourceInformation Flag and not DesignMode (#211)
* Adapter to honour CollectSourceInformation Flag and not DesignMode * PR comments
1 parent e924c3c commit c2cda47

File tree

8 files changed

+79
-87
lines changed

8 files changed

+79
-87
lines changed

src/Adapter/MSTest.CoreAdapter/Discovery/UnitTestDiscoverer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ internal virtual void DiscoverTestsInSource(
8181

8282
internal void SendTestCases(string source, IEnumerable<UnitTestElement> testElements, ITestCaseDiscoverySink discoverySink)
8383
{
84-
var isDesignMode = RunConfigurationSettings.ConfigurationSettings.DesignMode;
84+
var shouldCollectSourceInformation = MSTestSettings.RunConfigurationSettings.CollectSourceInformation;
8585

8686
var navigationSessions = new Dictionary<string, object>();
8787
try
8888
{
89-
if (isDesignMode)
89+
if (shouldCollectSourceInformation)
9090
{
9191
navigationSessions.Add(source, PlatformServiceProvider.Instance.FileOperations.CreateNavigationSession(source));
9292
}
@@ -96,7 +96,7 @@ internal void SendTestCases(string source, IEnumerable<UnitTestElement> testElem
9696
object testNavigationSession;
9797
var testCase = testElement.ToTestCase();
9898

99-
if (isDesignMode)
99+
if (shouldCollectSourceInformation)
100100
{
101101
string testSource = testElement.TestMethod.DeclaringAssemblyName ?? source;
102102

src/Adapter/MSTest.CoreAdapter/MSTestDiscoverer.cs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public void DiscoverTests(
4747

4848
// Populate the runsettings.
4949
MSTestSettings.PopulateSettings(discoveryContext);
50-
RunConfigurationSettings.PopulateSettings(discoveryContext);
5150

5251
// Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter.
5352
if (MSTestSettings.IsLegacyScenario(logger))

src/Adapter/MSTest.CoreAdapter/MSTestExecutor.cs

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrame
7676

7777
// Populate the runsettings.
7878
MSTestSettings.PopulateSettings(runContext);
79-
RunConfigurationSettings.PopulateSettings(runContext);
8079

8180
// Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter.
8281
if (MSTestSettings.IsLegacyScenario(frameworkHandle))

src/Adapter/MSTest.CoreAdapter/MSTestSettings.cs

+29
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public class MSTestSettings
3333
/// </summary>
3434
private static MSTestSettings currentSettings;
3535

36+
/// <summary>
37+
/// Member variable for RunConfiguration settings
38+
/// </summary>
39+
private static RunConfigurationSettings runConfigurationSettings;
40+
3641
/// <summary>
3742
/// Initializes a new instance of the <see cref="MSTestSettings"/> class.
3843
/// </summary>
@@ -66,6 +71,27 @@ private set
6671
}
6772
}
6873

74+
/// <summary>
75+
/// Gets the current configuration settings.
76+
/// </summary>
77+
public static RunConfigurationSettings RunConfigurationSettings
78+
{
79+
get
80+
{
81+
if (runConfigurationSettings == null)
82+
{
83+
runConfigurationSettings = new RunConfigurationSettings();
84+
}
85+
86+
return runConfigurationSettings;
87+
}
88+
89+
private set
90+
{
91+
runConfigurationSettings = value;
92+
}
93+
}
94+
6995
/// <summary>
7096
/// Gets a value indicating whether capture debug traces.
7197
/// </summary>
@@ -113,6 +139,8 @@ public static void PopulateSettings(MSTestSettings settings)
113139
/// </param>
114140
public static void PopulateSettings(IDiscoveryContext context)
115141
{
142+
RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(context);
143+
116144
if (context == null || context.RunSettings == null || string.IsNullOrEmpty(context.RunSettings.SettingsXml))
117145
{
118146
// This will contain default adapter settings
@@ -198,6 +226,7 @@ internal static MSTestSettings GetSettings(string runsettingsXml, string setting
198226
internal static void Reset()
199227
{
200228
MSTestSettings.CurrentSettings = null;
229+
MSTestSettings.RunConfigurationSettings = null;
201230
}
202231

203232
/// <summary>

src/Adapter/MSTest.CoreAdapter/RunConfigurationSettings.cs

+16-51
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,49 @@ public class RunConfigurationSettings
1919
/// </summary>
2020
public const string SettingsName = "RunConfiguration";
2121

22-
/// <summary>
23-
/// Member variable for RunConfiguration settings
24-
/// </summary>
25-
private static RunConfigurationSettings configurationSettings;
26-
2722
/// <summary>
2823
/// Initializes a new instance of the <see cref="RunConfigurationSettings"/> class.
2924
/// </summary>
3025
public RunConfigurationSettings()
3126
{
32-
this.DesignMode = true;
27+
this.CollectSourceInformation = true;
3328
}
3429

3530
/// <summary>
36-
/// Gets the current settings.
31+
/// Gets a value indicating whether source information needs to be collected or not.
3732
/// </summary>
38-
public static RunConfigurationSettings ConfigurationSettings
39-
{
40-
get
41-
{
42-
if (configurationSettings == null)
43-
{
44-
configurationSettings = new RunConfigurationSettings();
45-
}
46-
47-
return configurationSettings;
48-
}
49-
50-
private set
51-
{
52-
configurationSettings = value;
53-
}
54-
}
55-
56-
/// <summary>
57-
/// Gets a value indicating whether designMode is on(IDE scenario) or off(CLI scenario).
58-
/// </summary>
59-
public bool DesignMode { get; private set; }
33+
public bool CollectSourceInformation { get; private set; }
6034

6135
/// <summary>
6236
/// Populate adapter settings from the context
6337
/// </summary>
6438
/// <param name="context">
6539
/// The discovery context that contains the runsettings.
6640
/// </param>
67-
public static void PopulateSettings(IDiscoveryContext context)
41+
/// <returns>Populated RunConfigurationSettings from the discovery context.</returns>
42+
public static RunConfigurationSettings PopulateSettings(IDiscoveryContext context)
6843
{
6944
if (context == null || context.RunSettings == null || string.IsNullOrEmpty(context.RunSettings.SettingsXml))
7045
{
71-
// This will contain default adapter settings
72-
ConfigurationSettings = new RunConfigurationSettings();
73-
return;
46+
// This will contain default configuration settings
47+
return new RunConfigurationSettings();
7448
}
7549

7650
var settings = GetSettings(context.RunSettings.SettingsXml, SettingsName);
7751

7852
if (settings != null)
7953
{
80-
ConfigurationSettings = settings;
81-
return;
54+
return settings;
8255
}
8356

84-
ConfigurationSettings = new RunConfigurationSettings();
57+
return new RunConfigurationSettings();
8558
}
8659

8760
/// <summary>
88-
/// Gets the adapter specific settings from the xml.
61+
/// Gets the configuration settings from the xml.
8962
/// </summary>
9063
/// <param name="runsettingsXml"> The xml with the settings passed from the test platform. </param>
91-
/// <param name="settingName"> The name of the adapter settings to fetch - Its either MSTest or MSTestV2 </param>
64+
/// <param name="settingName"> The name of the settings to fetch.</param>
9265
/// <returns> The settings if found. Null otherwise. </returns>
9366
internal static RunConfigurationSettings GetSettings(string runsettingsXml, string settingName)
9467
{
@@ -118,14 +91,6 @@ internal static RunConfigurationSettings GetSettings(string runsettingsXml, stri
11891
return null;
11992
}
12093

121-
/// <summary>
122-
/// Resets any settings loaded.
123-
/// </summary>
124-
internal static void Reset()
125-
{
126-
RunConfigurationSettings.ConfigurationSettings = null;
127-
}
128-
12994
/// <summary>
13095
/// Convert the parameter xml to TestSettings
13196
/// </summary>
@@ -139,12 +104,12 @@ private static RunConfigurationSettings ToSettings(XmlReader reader)
139104
//
140105
// <Runsettings>
141106
// <RunConfiguration>
142-
// <DesignMode>true</DesignMode>
107+
// <CollectSourceInformation>true</CollectSourceInformation>
143108
// </RunConfiguration>
144109
// </Runsettings>
145110
RunConfigurationSettings settings = new RunConfigurationSettings();
146111

147-
// Read the first element in the section which is either "MSTest"/"MSTestV2"
112+
// Read the first element in the section
148113
reader.ReadToNextElement();
149114

150115
if (!reader.IsEmptyElement)
@@ -157,13 +122,13 @@ private static RunConfigurationSettings ToSettings(XmlReader reader)
157122
string elementName = reader.Name.ToUpperInvariant();
158123
switch (elementName)
159124
{
160-
case "DESIGNMODE":
125+
case "COLLECTSOURCEINFORMATION":
161126
{
162127
if (bool.TryParse(reader.ReadInnerXml(), out result))
163128
{
164-
settings.DesignMode = result;
129+
settings.CollectSourceInformation = result;
165130
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo(
166-
"DesignMode value Found : {0} ",
131+
"CollectSourceInformation value Found : {0} ",
167132
result);
168133
}
169134

test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/UnitTestDiscovererTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ public void SendTestCasesShouldSendAllTestCaseData()
152152
}
153153

154154
[TestMethodV1]
155-
public void SendTestCasesShouldSendTestCasesWithoutNavigationDataWhenDesignModeIsFalse()
155+
public void SendTestCasesShouldSendTestCasesWithoutNavigationDataWhenCollectSourceInformationIsFalse()
156156
{
157157
string settingsXml =
158158
@"<?xml version=""1.0"" encoding=""utf-8""?>
159159
<RunSettings>
160160
<RunConfiguration>
161161
<ResultsDirectory>.\TestResults</ResultsDirectory>
162-
<DesignMode>false</DesignMode>
162+
<CollectSourceInformation>false</CollectSourceInformation>
163163
</RunConfiguration>
164164
</RunSettings>";
165165

@@ -174,7 +174,7 @@ public void SendTestCasesShouldSendTestCasesWithoutNavigationDataWhenDesignModeI
174174
mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(this.mockRunSettings.Object);
175175

176176
// Act
177-
RunConfigurationSettings.PopulateSettings(mockDiscoveryContext.Object);
177+
MSTestSettings.PopulateSettings(mockDiscoveryContext.Object);
178178
this.unitTestDiscoverer.SendTestCases(Source, this.testElements, this.mockTestCaseDiscoverySink.Object);
179179

180180
// Assert

test/UnitTests/MSTest.CoreAdapter.Unit.Tests/MSTestExecutorTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void RunTestsWithSourcesShouldNotExecuteTestsIfTestSettingsIsGiven()
9191
}
9292

9393
[TestMethod]
94-
public void RunTestsWithSourcesShouldSetDefaultDesignModeAsTrue()
94+
public void RunTestsWithSourcesShouldSetDefaultCollectSourceInformationAsTrue()
9595
{
9696
var sources = new List<string> { Assembly.GetExecutingAssembly().Location };
9797
string runSettingxml =
@@ -101,11 +101,11 @@ public void RunTestsWithSourcesShouldSetDefaultDesignModeAsTrue()
101101
this.mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
102102
this.mstestExecutor.RunTests(sources, this.mockRunContext.Object, this.mockFrameworkHandle.Object);
103103

104-
Assert.IsTrue(RunConfigurationSettings.ConfigurationSettings.DesignMode);
104+
Assert.IsTrue(MSTestSettings.RunConfigurationSettings.CollectSourceInformation);
105105
}
106106

107107
[TestMethod]
108-
public void RunTestsWithSourcesShouldSetDesignModeAsFalseIfSpecifiedInRunSettings()
108+
public void RunTestsWithSourcesShouldSetCollectSourceInformationAsFalseIfSpecifiedInRunSettings()
109109
{
110110
var sources = new List<string> { Assembly.GetExecutingAssembly().Location };
111111
string runSettingxml =
@@ -118,7 +118,7 @@ public void RunTestsWithSourcesShouldSetDesignModeAsFalseIfSpecifiedInRunSetting
118118
this.mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
119119
this.mstestExecutor.RunTests(sources, this.mockRunContext.Object, this.mockFrameworkHandle.Object);
120120

121-
Assert.IsFalse(RunConfigurationSettings.ConfigurationSettings.DesignMode);
121+
Assert.IsFalse(MSTestSettings.RunConfigurationSettings.CollectSourceInformation);
122122
}
123123
}
124124
}

0 commit comments

Comments
 (0)