-
-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add alias for dotnet workload install command
- Loading branch information
Showing
5 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...ake.Common.Tests/Fixtures/Tools/DotNet/Workload/Install/DotNetWorkloadInstallerFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using Cake.Common.Tools.DotNet.Workload.Install; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Workload.Install | ||
{ | ||
internal sealed class DotNetWorkloadInstallerFixture : DotNetFixture<DotNetWorkloadInstallSettings> | ||
{ | ||
public IEnumerable<string> WorkloadIds { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetWorkloadInstaller(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Install(WorkloadIds, Settings); | ||
} | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
src/Cake.Common.Tests/Unit/Tools/DotNet/Workload/Install/DotNetWorkloadInstallTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Cake.Common.Tests.Fixtures.Tools.DotNet.Workload.Install; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Workload.Install | ||
{ | ||
public sealed class DotNetWorkloadInstallTests | ||
{ | ||
public sealed class TheWorkloadInstallMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = new string[] { "maui" }; | ||
fixture.GivenProcessCannotStart(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsCakeException(result, ".NET CLI: Process was not started."); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = new string[] { "maui" }; | ||
fixture.GivenProcessExitsWithCode(1); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsCakeException(result, ".NET CLI: Process returned an error (exit code 1)."); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_WorkloadIds_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = new string[] { "maui-android", "maui-ios" }; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("workload install maui-android maui-ios", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_WorkloadIds_Is_Empty() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = new string[] { }; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "workloadIds"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_WorkloadIds_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "workloadIds"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = new string[] { "maui" }; | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadInstallerFixture(); | ||
fixture.WorkloadIds = new string[] { "maui" }; | ||
fixture.Settings.ConfigFile = "./nuget.config"; | ||
fixture.Settings.DisableParallel = true; | ||
fixture.Settings.IgnoreFailedSources = true; | ||
fixture.Settings.IncludePreviews = true; | ||
fixture.Settings.Interactive = true; | ||
fixture.Settings.NoCache = true; | ||
fixture.Settings.SkipManifestUpdate = true; | ||
fixture.Settings.Source.Add("http://www.nuget.org/api/v2/package"); | ||
fixture.Settings.Source.Add("http://www.symbolserver.org/"); | ||
fixture.Settings.TempDir = "./src/project"; | ||
fixture.Settings.Verbosity = Common.Tools.DotNet.DotNetVerbosity.Diagnostic; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
var expected = "workload install maui --configfile \"/Working/nuget.config\" --disable-parallel --ignore-failed-sources --include-previews --interactive --no-cache --skip-manifest-update"; | ||
expected += " --source \"http://www.nuget.org/api/v2/package\" --source \"http://www.symbolserver.org/\" --temp-dir \"/Working/src/project\" --verbosity diagnostic"; | ||
Assert.Equal(expected, result.Args); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/Cake.Common/Tools/DotNet/Workload/Install/DotNetWorkloadInstallSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using Cake.Core.IO; | ||
|
||
namespace Cake.Common.Tools.DotNet.Workload.Install | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetWorkloadInstaller" />. | ||
/// </summary> | ||
public sealed class DotNetWorkloadInstallSettings : DotNetSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets the NuGet configuration file (nuget.config) to use. | ||
/// </summary> | ||
public FilePath ConfigFile { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to prevent restoring multiple projects in parallel. | ||
/// </summary> | ||
public bool DisableParallel { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to treat package source failures as warnings. | ||
/// </summary> | ||
public bool IgnoreFailedSources { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to allow prerelease workload manifests. | ||
/// </summary> | ||
public bool IncludePreviews { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action. | ||
/// For example, to complete authentication. | ||
/// </summary> | ||
public bool Interactive { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to do not cache packages and http requests. | ||
/// </summary> | ||
public bool NoCache { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to skip updating the workload manifests. | ||
/// The workload manifests define what assets and versions need to be installed for each workload. | ||
/// </summary> | ||
public bool SkipManifestUpdate { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the URI of the NuGet package source to use. | ||
/// This setting overrides all of the sources specified in the nuget.config files. | ||
/// </summary> | ||
public ICollection<string> Source { get; set; } = new List<string>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the temporary directory used to download and extract NuGet packages (must be secure). | ||
/// </summary> | ||
public DirectoryPath TempDir { get; set; } | ||
} | ||
} |
Oops, something went wrong.