Skip to content

Commit

Permalink
Do not force .NET4.5 in case legacy test settings are provided (micro…
Browse files Browse the repository at this point in the history
…soft#2545)

* Do not force .NET4.5 in case legacy test settings are provided

* Net core app

* Fix runconfig

* Default platform
  • Loading branch information
nohwnd committed Sep 24, 2020
1 parent 3796564 commit 65c1fd3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
12 changes: 1 addition & 11 deletions src/Microsoft.TestPlatform.Utilities/MSTestSettingsUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ public static class MSTestSettingsUtilities
/// Settings file which need to be imported. The file extension of the settings file will be specified by <paramref name="SettingsFileExtension"/> property.
/// </param>
/// <param name="defaultRunSettings"> Input RunSettings document to which settings file need to be imported. </param>
/// <param name="architecture"> The architecture. </param>
/// <param name="frameworkVersion"> The framework Version. </param>
/// <returns> Updated RunSetting Xml document with imported settings. </returns>
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = "XmlDocument.XmlResolver is not available in core. Suppress until fxcop issue is fixed.")]
public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSettings, Architecture architecture, FrameworkVersion frameworkVersion)
public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSettings)
{
ValidateArg.NotNull(settingsFile, "settingsFile");
ValidateArg.NotNull(defaultRunSettings, "defaultRunSettings");
Expand All @@ -57,14 +55,6 @@ public static XmlDocument Import(string settingsFile, XmlDocument defaultRunSett
var doc = new XmlDocument();
var runConfigurationNode = doc.CreateElement(Constants.RunConfigurationSettingsName);

var targetPlatformNode = doc.CreateElement("TargetPlatform");
targetPlatformNode.InnerXml = architecture.ToString();
runConfigurationNode.AppendChild(targetPlatformNode);

var targetFrameworkVersionNode = doc.CreateElement("TargetFrameworkVersion");
targetFrameworkVersionNode.InnerXml = frameworkVersion.ToString();
runConfigurationNode.AppendChild(targetFrameworkVersionNode);

defaultRunSettings.DocumentElement.PrependChild(defaultRunSettings.ImportNode(runConfigurationNode, true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private XmlDocument GetRunSettingsDocument(string runSettingsFile)
else
{
runSettingsDocument = XmlRunSettingsUtilities.CreateDefaultRunSettings();
runSettingsDocument = MSTestSettingsUtilities.Import(runSettingsFile, runSettingsDocument, Architecture.X86, FrameworkVersion.Framework45);
runSettingsDocument = MSTestSettingsUtilities.Import(runSettingsFile, runSettingsDocument);
}

return runSettingsDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Microsoft.TestPlatform.Utilities.Tests

using Microsoft.VisualStudio.TestPlatform.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VisualStudio.TestPlatform.ObjectModel;
using MSTest.TestFramework.AssertExtensions;

[TestClass]
Expand Down Expand Up @@ -49,9 +48,7 @@ public void ImportShouldThrowIfNotLegacySettingsFile()
() =>
MSTestSettingsUtilities.Import(
"C:\\temp\\r.runsettings",
xmlDocument,
Architecture.X86,
FrameworkVersion.Framework45);
xmlDocument);
Assert.That.Throws<XmlException>(action).WithMessage("Unexpected settings file specified.");
}

Expand All @@ -66,9 +63,7 @@ public void ImportShouldThrowIfDefaultRunSettingsIsIncorrect()
() =>
MSTestSettingsUtilities.Import(
"C:\\temp\\r.testsettings",
xmlDocument,
Architecture.X86,
FrameworkVersion.Framework45);
xmlDocument);
Assert.That.Throws<XmlException>(action).WithMessage("Could not find 'RunSettings' node.");
}

Expand All @@ -80,14 +75,18 @@ public void ImportShouldEmbedTestSettingsInformation()
xmlDocument.LoadXml(defaultRunSettingsXml);
var finalxPath = MSTestSettingsUtilities.Import(
"C:\\temp\\r.testsettings",
xmlDocument,
Architecture.X86,
FrameworkVersion.Framework45);
xmlDocument);

var finalSettingsXml = finalxPath.CreateNavigator().OuterXml;

var expectedSettingsXml =
"<RunSettings>\r\n <MSTest>\r\n <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n <ForcedLegacyMode>true</ForcedLegacyMode>\r\n </MSTest>\r\n <RunConfiguration></RunConfiguration>\r\n</RunSettings>";
"<RunSettings>\r\n" +
" <MSTest>\r\n" +
" <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n" +
" <ForcedLegacyMode>true</ForcedLegacyMode>\r\n" +
" </MSTest>\r\n" +
" <RunConfiguration></RunConfiguration>\r\n" +
"</RunSettings>";

Assert.AreEqual(expectedSettingsXml, finalSettingsXml);
}
Expand All @@ -100,14 +99,18 @@ public void ImportShouldEmbedTestSettingsAndDefaultRunConfigurationInformation()
xmlDocument.LoadXml(defaultRunSettingsXml);
var finalxPath = MSTestSettingsUtilities.Import(
"C:\\temp\\r.testsettings",
xmlDocument,
Architecture.X86,
FrameworkVersion.Framework45);
xmlDocument);

var finalSettingsXml = finalxPath.CreateNavigator().OuterXml;

var expectedSettingsXml =
"<RunSettings>\r\n <RunConfiguration>\r\n <TargetPlatform>X86</TargetPlatform>\r\n <TargetFrameworkVersion>Framework45</TargetFrameworkVersion>\r\n </RunConfiguration>\r\n <MSTest>\r\n <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n <ForcedLegacyMode>true</ForcedLegacyMode>\r\n </MSTest>\r\n</RunSettings>";
"<RunSettings>\r\n" +
" <RunConfiguration />\r\n" +
" <MSTest>\r\n" +
" <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n" +
" <ForcedLegacyMode>true</ForcedLegacyMode>\r\n" +
" </MSTest>\r\n" +
"</RunSettings>";

Assert.AreEqual(expectedSettingsXml, finalSettingsXml);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,27 @@ public void InitializeShouldSetActiveRunSettingsForTestSettingsFiles()
// Act.
executor.Initialize(fileName);


// Assert.
Assert.IsNotNull(this.settingsProvider.ActiveRunSettings);
StringAssert.Contains(this.settingsProvider.ActiveRunSettings.SettingsXml, $"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<RunSettings>\r\n <RunConfiguration>\r\n <TargetPlatform>{Constants.DefaultPlatform}</TargetPlatform>\r\n <TargetFrameworkVersion>{Framework.FromString(FrameworkVersion.Framework45.ToString()).Name}</TargetFrameworkVersion>\r\n <ResultsDirectory>{Constants.DefaultResultsDirectory}</ResultsDirectory>\r\n </RunConfiguration>\r\n <MSTest>\r\n <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n <ForcedLegacyMode>true</ForcedLegacyMode>\r\n </MSTest>\r\n <DataCollectionRunSettings>\r\n <DataCollectors />\r\n </DataCollectionRunSettings>\r\n</RunSettings>");

var expected =
$"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" +
$"<RunSettings>\r\n" +
$" <RunConfiguration>\r\n" +
$" <ResultsDirectory>{Constants.DefaultResultsDirectory}</ResultsDirectory>\r\n" +
$" <TargetPlatform>{Constants.DefaultPlatform}</TargetPlatform>\r\n" +
$" <TargetFrameworkVersion>{Framework.DefaultFramework.Name}</TargetFrameworkVersion>\r\n" +
$" </RunConfiguration>\r\n" +
$" <MSTest>\r\n" +
$" <SettingsFile>C:\\temp\\r.testsettings</SettingsFile>\r\n" +
$" <ForcedLegacyMode>true</ForcedLegacyMode>\r\n" +
$" </MSTest>\r\n" +
$" <DataCollectionRunSettings>\r\n" +
$" <DataCollectors />\r\n" +
$" </DataCollectionRunSettings>\r\n" +
$"</RunSettings>";
StringAssert.Contains(this.settingsProvider.ActiveRunSettings.SettingsXml, expected);
}


Expand Down

0 comments on commit 65c1fd3

Please sign in to comment.