Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix runtime config tests #5137

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
// 2) making sure we still make the project executable (and so we actually do get runtimeconfig unless the user tries hard to not make the test and EXE).
var suffix = _targetFramework.Version == "1.0.0.0" ? "latest" : $"{new Version(_targetFramework.Version).Major}.{new Version(_targetFramework.Version).Minor}";
var testhostRuntimeConfig = Path.Combine(Path.GetDirectoryName(testHostNextToRunner)!, $"testhost-{suffix}.runtimeconfig.json");
if (!File.Exists(testhostRuntimeConfig))
if (!_fileHelper.Exists(testhostRuntimeConfig))
{
testhostRuntimeConfig = Path.Combine(Path.GetDirectoryName(testHostNextToRunner)!, $"testhost-latest.runtimeconfig.json");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,15 @@ public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunner
// we can't put in a "default" value, and we don't have other way to determine if this provided value is the
// runtime default or the actual value that user provided, so right now the default will use the latest, instead
// or the more correct 1.0, it should be okay, as that version is not supported anymore anyway
[DataRow("netcoreapp3.1", "3.1")]
[DataRow("net5.0", "5.0")]
[DataRow("netcoreapp3.1", "3.1", true)]
[DataRow("net5.0", "5.0", true)]

// net6.0 is currently the latest released version, but it still has it's own runtime config, it is not the same as
// "latest" which means the latest you have on system. So if you have only 5.0 SDK then net6.0 will fail because it can't find net6.0,
// but latest would use net5.0 because that is the latest one on your system.
[DataRow("net6.0", "6.0")]
public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunnerIfTesthostDllIsNoFoundAndDepsFileNotFoundWithTheCorrectTfm(string tfm, string suffix)
[DataRow("net6.0", "6.0", true)]
[DataRow("net6.0", "latest", false)]
public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunnerIfTesthostDllIsNoFoundAndDepsFileNotFoundWithTheCorrectTfm(string tfm, string suffix, bool runtimeConfigExists)
{
// Absolute path to the source directory
var sourcePath = Path.Combine(_temp, "test.dll");
Expand All @@ -687,6 +688,8 @@ public void GetTestHostProcessStartInfoShouldIncludeTestHostPathNextToTestRunner
var testhostNextToRunner = Path.Combine(here, "testhost.dll");
_mockFileHelper.Setup(ph => ph.Exists(testhostNextToRunner)).Returns(true);

_mockFileHelper.Setup(ph => ph.Exists(It.Is<string>(s => s.Contains($"{suffix}.runtimeconfig.json")))).Returns(runtimeConfigExists);

_dotnetHostManager.Initialize(_mockMessageLogger.Object, $"<RunSettings><RunConfiguration><TargetFrameworkVersion>{tfm}</TargetFrameworkVersion></RunConfiguration></RunSettings>");
var startInfo = _dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, _defaultConnectionInfo);

Expand Down