diff --git a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs index d53cf471be04..dd11aeb112a0 100644 --- a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs +++ b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs @@ -66,26 +66,11 @@ protected void InstallSdk(bool deployStage2 = true) .Should() .Pass(); - var sdkTestingDir = VM.GetRemoteDirectory(@"c:\SdkTesting"); - List runtimeInstallers = new List(); - string installerPrefix = "dotnet-runtime-"; - string installerSuffix = "-win-x64.exe"; - foreach (var file in sdkTestingDir.Files.Select(Path.GetFileName)) - { - if (file.StartsWith(installerPrefix) && file.EndsWith(installerSuffix)) - { - runtimeInstallers.Add(file); - } - } + VM.CreateRunCommand($@"c:\SdkTesting\{SdkInstallerFileName}", "/quiet") + .WithDescription($"Install SDK {SdkInstallerVersion}") + .Execute().Should().Pass(); - VM.CreateActionGroup($"Install SDK {SdkInstallerVersion}", - [ - VM.CreateRunCommand($@"c:\SdkTesting\{SdkInstallerFileName}", "/quiet"), - ..runtimeInstallers.Select(i => VM.CreateRunCommand($@"c:\SdkTesting\{i}", "/quiet")) - ]) - .Execute() - .Should() - .Pass(); + if (deployStage2) { @@ -109,6 +94,27 @@ protected void DeployStage2Sdk() return; } + + // Install any runtimes that are in the c:\SdkTesting directory, to support using older baseline SDK versions with a newer stage 2 + var sdkTestingDir = VM.GetRemoteDirectory(@"c:\SdkTesting"); + List runtimeInstallers = new List(); + string installerPrefix = "dotnet-runtime-"; + string installerSuffix = "-win-x64.exe"; + foreach (var file in sdkTestingDir.Files.Select(Path.GetFileName)) + { + if (file.StartsWith(installerPrefix) && file.EndsWith(installerSuffix)) + { + runtimeInstallers.Add(file); + } + } + + if (runtimeInstallers.Any()) + { + VM.CreateActionGroup($"Install .NET runtime(s)", + runtimeInstallers.Select(i => VM.CreateRunCommand($@"c:\SdkTesting\{i}", "/quiet")).ToArray()) + .Execute().Should().Pass(); + } + var result = VM.CreateRunCommand("dotnet", "--version") .WithIsReadOnly(true) .Execute(); diff --git a/src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs b/src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs index 109de42139aa..a42b6f263f43 100644 --- a/src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs +++ b/src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.DotNet.MsiInstallerTests.Framework; using Microsoft.NET.Sdk.WorkloadManifestReader; @@ -17,8 +18,24 @@ public class WorkloadSetTests : VMTestBase { readonly string SdkTestingDirectory = @"C:\SdkTesting"; + + Lazy> _testWorkloadSetVersions; + string WorkloadSetVersion1 => _testWorkloadSetVersions.Value.GetValueOrDefault("version1", "8.0.300-preview.0.24178.1"); + string WorkloadSetVersion2 => _testWorkloadSetVersions.Value.GetValueOrDefault("version2", "8.0.300-preview.0.24217.2"); + string WorkloadSetPreviousBandVersion => _testWorkloadSetVersions.Value.GetValueOrDefault("previousbandversion", "8.0.204"); + public WorkloadSetTests(ITestOutputHelper log) : base(log) { + _testWorkloadSetVersions = new Lazy>(() => + { + var versionsFile = VM.GetRemoteFile(@"c:\SdkTesting\workloadsets\testworkloadsetversions.json"); + if (!versionsFile.Exists) + { + return new Dictionary(); + } + + return JsonSerializer.Deserialize>(versionsFile.ReadAllText()); + }); } [Fact] @@ -91,7 +108,7 @@ public void UpdateWithWorkloadSets() newRollback.ManifestVersions.Should().NotBeEquivalentTo(rollbackAfterUpdate.ManifestVersions); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion2); } [Fact] @@ -113,10 +130,19 @@ public void UpdateInWorkloadSetModeWithNoAvailableWorkloadSet() GetWorkloadVersion().Should().Be(updatedWorkloadVersion); } - [Theory] - [InlineData("8.0.300-preview.0.24178.1")] - [InlineData("8.0.204")] - public void UpdateToSpecificWorkloadSetVersion(string versionToInstall) + [Fact] + public void UpdateToSpecificWorkloadSetVersion() + { + UpdateToWorkloadSetVersion(WorkloadSetVersion1); + } + + [Fact] + public void UpdateToPreviousBandWorkloadSetVersion() + { + UpdateToWorkloadSetVersion(WorkloadSetPreviousBandVersion); + } + + private void UpdateToWorkloadSetVersion(string versionToInstall) { InstallSdk(); @@ -148,7 +174,7 @@ public void UpdateToSpecificWorkloadSetVersion(string versionToInstall) .Should() .Pass(); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion2); } [Fact] @@ -207,7 +233,7 @@ public void UpdateToWorkloadSetVersionWithManifestsNotAvailable() var workloadVersionBeforeUpdate = GetWorkloadVersion(); - VM.CreateRunCommand("dotnet", "workload", "update", "--version", @"8.0.300-preview.0.24217.2", "--source", @"c:\SdkTesting\workloadsets") + VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion2, "--source", @"c:\SdkTesting\workloadsets") .Execute() .Should() .Fail(); @@ -225,7 +251,7 @@ void SetupWorkloadSetInGlobalJson(out WorkloadSet originalRollback) { InstallSdk(); - var versionToUpdateTo = "8.0.300-preview.0.24217.2"; + var versionToUpdateTo = WorkloadSetVersion2; string originalVersion = GetWorkloadVersion(); @@ -286,7 +312,7 @@ public void InstallWithVersionAndSkipManifestUpdate() { InstallSdk(); - VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--skip-manifest-update", "--version", "8.0.300-preview.0.24178.1") + VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--skip-manifest-update", "--version", WorkloadSetVersion1) .Execute().Should().Fail() .And.HaveStdErrContaining("--skip-manifest-update") .And.HaveStdErrContaining("--sdk-version"); @@ -300,17 +326,17 @@ public void InstallWithVersionWhenPinned() AddNuGetSource(@"c:\SdkTesting\WorkloadSets"); string originalVersion = GetWorkloadVersion(); - originalVersion.Should().NotBe("8.0.300-preview.0.24178.1"); + originalVersion.Should().NotBe(WorkloadSetVersion1); - VM.CreateRunCommand("dotnet", "workload", "update", "--version", "8.0.300-preview.0.24178.1") + VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion1) .Execute().Should().Pass(); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion1); - VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--version", "8.0.300-preview.0.24217.2") + VM.CreateRunCommand("dotnet", "workload", "install", "aspire", "--version", WorkloadSetVersion2) .Execute().Should().Pass(); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion2); } [Fact] @@ -321,18 +347,18 @@ public void InstallWithGlobalJsonWhenPinned() //AddNuGetSource(@"c:\SdkTesting\WorkloadSets"); string originalVersion = GetWorkloadVersion(); - originalVersion.Should().NotBe("8.0.300-preview.0.24178.1"); + originalVersion.Should().NotBe(WorkloadSetVersion1); - VM.CreateRunCommand("dotnet", "workload", "update", "--version", "8.0.300-preview.0.24178.1") + VM.CreateRunCommand("dotnet", "workload", "update", "--version", WorkloadSetVersion1) .Execute().Should().Pass(); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion1); VM.CreateRunCommand("dotnet", "workload", "install", "aspire") .WithWorkingDirectory(SdkTestingDirectory) .Execute().Should().Pass(); - GetWorkloadVersion(SdkTestingDirectory).Should().Be("8.0.300-preview.0.24217.2"); + GetWorkloadVersion(SdkTestingDirectory).Should().Be(WorkloadSetVersion2); GetRollback(SdkTestingDirectory).Should().NotBe(originalRollback); @@ -346,22 +372,28 @@ public void UpdateShouldNotPinWorkloadSet() AddNuGetSource(@"c:\SdkTesting\WorkloadSets"); + var packageVersion = WorkloadSet.WorkloadSetVersionToWorkloadSetPackageVersion(WorkloadSetVersion2, out var sdkFeatureBand); + // Rename latest workload set so it won't be installed - VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.nupkg", $"Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.bak") + VM.CreateActionGroup($"Disable {WorkloadSetVersion2}", + VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.nupkg", $"Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.bak"), + VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.nupkg", $"Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.bak")) .Execute().Should().Pass(); VM.CreateRunCommand("dotnet", "workload", "update") .Execute().Should().Pass(); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24178.1"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion1); // Bring latest workload set version back, so installing workload should update to it - VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.bak", $"Microsoft.NET.Workloads.8.0.300-preview.*.24217.2.nupkg") + VM.CreateActionGroup($"Enable {WorkloadSetVersion2}", + VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.bak", $"Microsoft.NET.Workloads.{sdkFeatureBand}.{packageVersion}.nupkg"), + VM.CreateRunCommand("cmd", "/c", "ren", @$"c:\SdkTesting\WorkloadSets\Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.bak", $"Microsoft.NET.Workloads.{sdkFeatureBand}.*.{packageVersion}.nupkg")) .Execute().Should().Pass(); InstallWorkload("aspire", skipManifestUpdate: false); - GetWorkloadVersion().Should().Be("8.0.300-preview.0.24217.2"); + GetWorkloadVersion().Should().Be(WorkloadSetVersion2); } [Fact]