From 36d115f989a7289736ef7c0a1270782dd71d2e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 9 Jul 2024 14:49:52 +0200 Subject: [PATCH] Fix runtime config tests --- .../Hosting/DotnetTestHostManager.cs | 2 +- .../Hosting/DotnetTestHostManagerTests.cs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 89c019556b..70c9481a8f 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -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"); } diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index 130e3b4b6c..af5ee66ec3 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -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"); @@ -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(s => s.Contains($"{suffix}.runtimeconfig.json")))).Returns(runtimeConfigExists); + _dotnetHostManager.Initialize(_mockMessageLogger.Object, $"{tfm}"); var startInfo = _dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, _defaultConnectionInfo);