Skip to content

Add test #40548

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 10, 2024
Merged

Add test #40548

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 @@ -168,9 +168,10 @@ protected CommandResult InstallWorkload(string workloadName)
return result;
}

protected WorkloadSet GetRollback()
protected WorkloadSet GetRollback(string directory = null)
{
var result = VM.CreateRunCommand("dotnet", "workload", "update", "--print-rollback")
.WithWorkingDirectory(directory)
.WithIsReadOnly(true)
.Execute();

Expand Down
55 changes: 55 additions & 0 deletions src/Tests/dotnet-MsiInstallation.Tests/WorkloadSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,51 @@ public void UpdateToWorkloadSetVersionWithManifestsNotAvailable()
GetWorkloadVersion().Should().Be(workloadVersionBeforeUpdate);
}

[Fact]
public void UpdateWorkloadSetViaGlobalJson()
{
InstallSdk();

var versionToUpdateTo = "8.0.300-preview.0.24217.2";
var directory = "C:\\SdkTesting";

string originalVersion = GetWorkloadVersion();

var rollback = GetRollback(directory);

VM.WriteFile("C:\\SdkTesting\\global.json", @$"{{""sdk"":{{""workloadVersion"":""{versionToUpdateTo}""}}}}").Execute().Should().Pass();

GetWorkloadVersion(directory).Should().Be(versionToUpdateTo);

// The version should have changed but not yet the manifests. Since we expect both, getting the rollback should fail.
var result = VM.CreateRunCommand("dotnet", "workload", "update", "--print-rollback")
.WithWorkingDirectory(directory)
.WithIsReadOnly(true)
.Execute();

result.Should().Fail();
result.StdErr.Should().Contain("FileNotFoundException");
result.StdErr.Should().Contain(versionToUpdateTo);

AddNuGetSource(@"C:\SdkTesting\workloadsets", directory);

VM.CreateRunCommand("dotnet", "workload", "update").WithWorkingDirectory(directory).Execute().Should().Pass();

GetRollback(directory).Should().NotBe(rollback);
}

string GetWorkloadVersion(string workingDirectory = null)
{
var result = VM.CreateRunCommand("dotnet", "workload", "--version")
.WithWorkingDirectory(workingDirectory)
.WithIsReadOnly(true)
.Execute();

result.Should().Pass();

return result.StdOut;
}

string GetUpdateMode()
{
var result = VM.CreateRunCommand("dotnet", "workload", "config", "--update-mode")
Expand All @@ -223,5 +268,15 @@ string GetUpdateMode()

return result.StdOut;
}

void AddNuGetSource(string source, string directory = null)
{
VM.CreateRunCommand("dotnet", "nuget", "add", "source", source)
.WithWorkingDirectory(directory)
.WithDescription($"Add {source} to NuGet.config")
.Execute()
.Should()
.Pass();
}
}
}
Loading