diff --git a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMAction.cs b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMAction.cs index 34ca1f806ebf..9a7cb527cca7 100644 --- a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMAction.cs +++ b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMAction.cs @@ -124,6 +124,26 @@ protected override SerializedVMAction SerializeDerivedProperties() } } + class VMMoveFolderAction : VMAction + { + public string SourcePath { get; set; } + public string TargetPath { get; set; } + + public VMMoveFolderAction(VirtualMachine vm) : base(vm) + { + } + + protected override SerializedVMAction SerializeDerivedProperties() + { + return new SerializedVMAction + { + Type = VMActionType.MoveFolderOnVM, + SourcePath = SourcePath, + TargetPath = TargetPath, + }; + } + } + class VMWriteFileAction : VMAction { public string TargetPath { get; set; } @@ -168,6 +188,7 @@ enum VMActionType RunCommand, CopyFileToVM, CopyFolderToVM, + MoveFolderOnVM, WriteFileToVM, GetRemoteDirectory, GetRemoteFile, @@ -190,10 +211,10 @@ class SerializedVMAction // Applies to RunCommand public string WorkingDirectory { get; set; } - // Applies to CopyFileToVM, CopyFolderToVM, WriteFileToVM, GetRemoteDirectory, GetRemoteFile + // Applies to CopyFileToVM, CopyFolderToVM, MoveFolderOnVM, WriteFileToVM, GetRemoteDirectory, GetRemoteFile public string TargetPath { get; set; } - // Applies to CopyFileToVM, CopyFolderToVM + // Applies to CopyFileToVM, CopyFolderToVM, MoveFolderOnVM public string SourcePath { get; set; } // Applies to CopyFileToVM, CopyFolderToVM @@ -222,6 +243,8 @@ public string GetDescription() return $"Copy file to VM: {SourcePath} -> {TargetPath}"; case VMActionType.CopyFolderToVM: return $"Copy folder to VM: {SourcePath} -> {TargetPath}"; + case VMActionType.MoveFolderOnVM: + return $"Move folder {SourcePath} -> {TargetPath}"; case VMActionType.WriteFileToVM: return $"Write file to VM: {TargetPath}"; case VMActionType.GetRemoteDirectory: diff --git a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs index ea73e4c54f41..89b3a2054617 100644 --- a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs +++ b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VMTestBase.cs @@ -76,21 +76,48 @@ protected void DeployStage2Sdk() Log.WriteLine($"Deploying SDK from {TestContext.Current.ToolsetUnderTest.SdkFolderUnderTest} to {installedSdkFolder} on VM."); - var vmVersionFilePath = Path.Combine(installedSdkFolder, ".version"); - - var existingVersionFileContents = VM.GetRemoteFile(vmVersionFilePath).ReadAllText().Split(Environment.NewLine); - var newVersionFileContents = File.ReadAllLines(Path.Combine(TestContext.Current.ToolsetUnderTest.SdkFolderUnderTest, ".version")); - newVersionFileContents[1] = existingVersionFileContents[1]; - // TODO: It would be nice if the description included the date/time of the SDK build, to distinguish different snapshots VM.CreateActionGroup("Deploy Stage 2 SDK", VM.CopyFolder(TestContext.Current.ToolsetUnderTest.SdkFolderUnderTest, installedSdkFolder), - VM.WriteFile(vmVersionFilePath, string.Join(Environment.NewLine, newVersionFileContents))) + ChangeVersionFileContents(SdkInstallerVersion)) .Execute() .Should() .Pass(); } + protected void ChangeSdkVersion(string oldVersion, string newVersion) + { + var oldSdkFolder = $@"c:\Program Files\dotnet\sdk\{oldVersion}"; + var newSdkFolder = $@"c:\Program Files\dotnet\sdk\{newVersion}"; + + new VMMoveFolderAction(VM) + { + SourcePath = oldSdkFolder, + TargetPath = newSdkFolder + } + .WithDescription($"Change SDK version to {newVersion}") + .Execute().Should().Pass(); + + ChangeVersionFileContents(newVersion) + .WithDescription("Update .version file") + .Execute() + .Should() + .Pass(); + + } + + private VMWriteFileAction ChangeVersionFileContents(string sdkVersion) + { + var installedSdkFolder = $@"c:\Program Files\dotnet\sdk\{sdkVersion}"; + var vmVersionFilePath = Path.Combine(installedSdkFolder, ".version"); + + var newVersionFileContents = File.ReadAllLines(Path.Combine(TestContext.Current.ToolsetUnderTest.SdkFolderUnderTest, ".version")); + newVersionFileContents[1] = sdkVersion; + + return VM.WriteFile(vmVersionFilePath, string.Join(Environment.NewLine, newVersionFileContents)); + + } + protected string GetInstalledSdkVersion() { var command = VM.CreateRunCommand("dotnet", "--version"); diff --git a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VirtualMachine.cs b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VirtualMachine.cs index b075df512e4a..ac2496bf64a9 100644 --- a/src/Tests/dotnet-MsiInstallation.Tests/Framework/VirtualMachine.cs +++ b/src/Tests/dotnet-MsiInstallation.Tests/Framework/VirtualMachine.cs @@ -299,6 +299,14 @@ VMActionResult Run(SerializedVMAction action) return VMActionResult.Success(); } + else if (action.Type == VMActionType.MoveFolderOnVM) + { + var sourceSharePath = VMPathToSharePath(action.SourcePath); + var targetSharePath = VMPathToSharePath(action.TargetPath); + Directory.Move(sourceSharePath, targetSharePath); + + return VMActionResult.Success(); + } else if (action.Type == VMActionType.WriteFileToVM) { var targetSharePath = VMPathToSharePath(action.TargetPath);