Skip to content

Commit

Permalink
Adapter to honour CollectSourceInformation Flag and not DesignMode (#211
Browse files Browse the repository at this point in the history
)

* Adapter to honour CollectSourceInformation Flag and not DesignMode

* PR comments
  • Loading branch information
jayaranigarg authored Jun 28, 2017
1 parent e924c3c commit c2cda47
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ internal virtual void DiscoverTestsInSource(

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

var navigationSessions = new Dictionary<string, object>();
try
{
if (isDesignMode)
if (shouldCollectSourceInformation)
{
navigationSessions.Add(source, PlatformServiceProvider.Instance.FileOperations.CreateNavigationSession(source));
}
Expand All @@ -96,7 +96,7 @@ internal void SendTestCases(string source, IEnumerable<UnitTestElement> testElem
object testNavigationSession;
var testCase = testElement.ToTestCase();

if (isDesignMode)
if (shouldCollectSourceInformation)
{
string testSource = testElement.TestMethod.DeclaringAssemblyName ?? source;

Expand Down
1 change: 0 additions & 1 deletion src/Adapter/MSTest.CoreAdapter/MSTestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public void DiscoverTests(

// Populate the runsettings.
MSTestSettings.PopulateSettings(discoveryContext);
RunConfigurationSettings.PopulateSettings(discoveryContext);

// Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter.
if (MSTestSettings.IsLegacyScenario(logger))
Expand Down
1 change: 0 additions & 1 deletion src/Adapter/MSTest.CoreAdapter/MSTestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrame

// Populate the runsettings.
MSTestSettings.PopulateSettings(runContext);
RunConfigurationSettings.PopulateSettings(runContext);

// Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter.
if (MSTestSettings.IsLegacyScenario(frameworkHandle))
Expand Down
29 changes: 29 additions & 0 deletions src/Adapter/MSTest.CoreAdapter/MSTestSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class MSTestSettings
/// </summary>
private static MSTestSettings currentSettings;

/// <summary>
/// Member variable for RunConfiguration settings
/// </summary>
private static RunConfigurationSettings runConfigurationSettings;

/// <summary>
/// Initializes a new instance of the <see cref="MSTestSettings"/> class.
/// </summary>
Expand Down Expand Up @@ -66,6 +71,27 @@ private set
}
}

/// <summary>
/// Gets the current configuration settings.
/// </summary>
public static RunConfigurationSettings RunConfigurationSettings
{
get
{
if (runConfigurationSettings == null)
{
runConfigurationSettings = new RunConfigurationSettings();
}

return runConfigurationSettings;
}

private set
{
runConfigurationSettings = value;
}
}

/// <summary>
/// Gets a value indicating whether capture debug traces.
/// </summary>
Expand Down Expand Up @@ -113,6 +139,8 @@ public static void PopulateSettings(MSTestSettings settings)
/// </param>
public static void PopulateSettings(IDiscoveryContext context)
{
RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(context);

if (context == null || context.RunSettings == null || string.IsNullOrEmpty(context.RunSettings.SettingsXml))
{
// This will contain default adapter settings
Expand Down Expand Up @@ -198,6 +226,7 @@ internal static MSTestSettings GetSettings(string runsettingsXml, string setting
internal static void Reset()
{
MSTestSettings.CurrentSettings = null;
MSTestSettings.RunConfigurationSettings = null;
}

/// <summary>
Expand Down
67 changes: 16 additions & 51 deletions src/Adapter/MSTest.CoreAdapter/RunConfigurationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,49 @@ public class RunConfigurationSettings
/// </summary>
public const string SettingsName = "RunConfiguration";

/// <summary>
/// Member variable for RunConfiguration settings
/// </summary>
private static RunConfigurationSettings configurationSettings;

/// <summary>
/// Initializes a new instance of the <see cref="RunConfigurationSettings"/> class.
/// </summary>
public RunConfigurationSettings()
{
this.DesignMode = true;
this.CollectSourceInformation = true;
}

/// <summary>
/// Gets the current settings.
/// Gets a value indicating whether source information needs to be collected or not.
/// </summary>
public static RunConfigurationSettings ConfigurationSettings
{
get
{
if (configurationSettings == null)
{
configurationSettings = new RunConfigurationSettings();
}

return configurationSettings;
}

private set
{
configurationSettings = value;
}
}

/// <summary>
/// Gets a value indicating whether designMode is on(IDE scenario) or off(CLI scenario).
/// </summary>
public bool DesignMode { get; private set; }
public bool CollectSourceInformation { get; private set; }

/// <summary>
/// Populate adapter settings from the context
/// </summary>
/// <param name="context">
/// The discovery context that contains the runsettings.
/// </param>
public static void PopulateSettings(IDiscoveryContext context)
/// <returns>Populated RunConfigurationSettings from the discovery context.</returns>
public static RunConfigurationSettings PopulateSettings(IDiscoveryContext context)
{
if (context == null || context.RunSettings == null || string.IsNullOrEmpty(context.RunSettings.SettingsXml))
{
// This will contain default adapter settings
ConfigurationSettings = new RunConfigurationSettings();
return;
// This will contain default configuration settings
return new RunConfigurationSettings();
}

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

if (settings != null)
{
ConfigurationSettings = settings;
return;
return settings;
}

ConfigurationSettings = new RunConfigurationSettings();
return new RunConfigurationSettings();
}

/// <summary>
/// Gets the adapter specific settings from the xml.
/// Gets the configuration settings from the xml.
/// </summary>
/// <param name="runsettingsXml"> The xml with the settings passed from the test platform. </param>
/// <param name="settingName"> The name of the adapter settings to fetch - Its either MSTest or MSTestV2 </param>
/// <param name="settingName"> The name of the settings to fetch.</param>
/// <returns> The settings if found. Null otherwise. </returns>
internal static RunConfigurationSettings GetSettings(string runsettingsXml, string settingName)
{
Expand Down Expand Up @@ -118,14 +91,6 @@ internal static RunConfigurationSettings GetSettings(string runsettingsXml, stri
return null;
}

/// <summary>
/// Resets any settings loaded.
/// </summary>
internal static void Reset()
{
RunConfigurationSettings.ConfigurationSettings = null;
}

/// <summary>
/// Convert the parameter xml to TestSettings
/// </summary>
Expand All @@ -139,12 +104,12 @@ private static RunConfigurationSettings ToSettings(XmlReader reader)
//
// <Runsettings>
// <RunConfiguration>
// <DesignMode>true</DesignMode>
// <CollectSourceInformation>true</CollectSourceInformation>
// </RunConfiguration>
// </Runsettings>
RunConfigurationSettings settings = new RunConfigurationSettings();

// Read the first element in the section which is either "MSTest"/"MSTestV2"
// Read the first element in the section
reader.ReadToNextElement();

if (!reader.IsEmptyElement)
Expand All @@ -157,13 +122,13 @@ private static RunConfigurationSettings ToSettings(XmlReader reader)
string elementName = reader.Name.ToUpperInvariant();
switch (elementName)
{
case "DESIGNMODE":
case "COLLECTSOURCEINFORMATION":
{
if (bool.TryParse(reader.ReadInnerXml(), out result))
{
settings.DesignMode = result;
settings.CollectSourceInformation = result;
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo(
"DesignMode value Found : {0} ",
"CollectSourceInformation value Found : {0} ",
result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ public void SendTestCasesShouldSendAllTestCaseData()
}

[TestMethodV1]
public void SendTestCasesShouldSendTestCasesWithoutNavigationDataWhenDesignModeIsFalse()
public void SendTestCasesShouldSendTestCasesWithoutNavigationDataWhenCollectSourceInformationIsFalse()
{
string settingsXml =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<RunSettings>
<RunConfiguration>
<ResultsDirectory>.\TestResults</ResultsDirectory>
<DesignMode>false</DesignMode>
<CollectSourceInformation>false</CollectSourceInformation>
</RunConfiguration>
</RunSettings>";

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

// Act
RunConfigurationSettings.PopulateSettings(mockDiscoveryContext.Object);
MSTestSettings.PopulateSettings(mockDiscoveryContext.Object);
this.unitTestDiscoverer.SendTestCases(Source, this.testElements, this.mockTestCaseDiscoverySink.Object);

// Assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void RunTestsWithSourcesShouldNotExecuteTestsIfTestSettingsIsGiven()
}

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

Assert.IsTrue(RunConfigurationSettings.ConfigurationSettings.DesignMode);
Assert.IsTrue(MSTestSettings.RunConfigurationSettings.CollectSourceInformation);
}

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

Assert.IsFalse(RunConfigurationSettings.ConfigurationSettings.DesignMode);
Assert.IsFalse(MSTestSettings.RunConfigurationSettings.CollectSourceInformation);
}
}
}
Loading

0 comments on commit c2cda47

Please sign in to comment.