-
-
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 uninstall command
- Loading branch information
Showing
5 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...Common.Tests/Fixtures/Tools/DotNet/Workload/Uninstall/DotNetWorkloadUninstallerFixture.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.Uninstall; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Workload.Uninstall | ||
{ | ||
internal sealed class DotNetWorkloadUninstallerFixture : DotNetFixture<DotNetWorkloadUninstallSettings> | ||
{ | ||
public IEnumerable<string> WorkloadIds { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetWorkloadUninstaller(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Uninstall(WorkloadIds); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/Cake.Common.Tests/Unit/Tools/DotNet/Workload/Uninstall/DotNetWorkloadUninstallTests.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,88 @@ | ||
// 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.Uninstall; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Workload.Uninstall | ||
{ | ||
public sealed class DotNetWorkloadUninstallTests | ||
{ | ||
public sealed class TheWorkloadSearchMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadUninstallerFixture(); | ||
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 DotNetWorkloadUninstallerFixture(); | ||
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 DotNetWorkloadUninstallerFixture(); | ||
fixture.WorkloadIds = new string[] { "maui-android", "maui-ios" }; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("workload uninstall maui-android maui-ios", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_WorkloadIds_Is_Empty() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadUninstallerFixture(); | ||
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 DotNetWorkloadUninstallerFixture(); | ||
fixture.WorkloadIds = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "workloadIds"); | ||
} | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/Cake.Common/Tools/DotNet/Workload/Uninstall/DotNetWorkloadUninstallSettings.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,13 @@ | ||
// 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. | ||
|
||
namespace Cake.Common.Tools.DotNet.Workload.Uninstall | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetWorkloadUninstaller" />. | ||
/// </summary> | ||
public sealed class DotNetWorkloadUninstallSettings : DotNetSettings | ||
{ | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/Cake.Common/Tools/DotNet/Workload/Uninstall/DotNetWorkloadUninstaller.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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cake.Core; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
|
||
namespace Cake.Common.Tools.DotNet.Workload.Uninstall | ||
{ | ||
/// <summary> | ||
/// .NET workloads uninstaller. | ||
/// </summary> | ||
public sealed class DotNetWorkloadUninstaller : DotNetTool<DotNetWorkloadUninstallSettings> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DotNetWorkloadUninstaller" /> class. | ||
/// </summary> | ||
/// <param name="fileSystem">The file system.</param> | ||
/// <param name="environment">The environment.</param> | ||
/// <param name="processRunner">The process runner.</param> | ||
/// <param name="tools">The tool locator.</param> | ||
public DotNetWorkloadUninstaller( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IProcessRunner processRunner, | ||
IToolLocator tools) : base(fileSystem, environment, processRunner, tools) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Uninstalls one or more workloads. | ||
/// </summary> | ||
/// <param name="workloadIds">The workload ID or multiple IDs to uninstall.</param> | ||
public void Uninstall(IEnumerable<string> workloadIds) | ||
{ | ||
if (workloadIds == null || !workloadIds.Any()) | ||
{ | ||
throw new ArgumentNullException(nameof(workloadIds)); | ||
} | ||
|
||
var settings = new DotNetWorkloadUninstallSettings(); | ||
RunCommand(settings, GetArguments(workloadIds, settings)); | ||
} | ||
|
||
private ProcessArgumentBuilder GetArguments(IEnumerable<string> workloadIds, DotNetWorkloadUninstallSettings settings) | ||
{ | ||
var builder = CreateArgumentBuilder(settings); | ||
|
||
builder.Append("workload uninstall"); | ||
|
||
if (workloadIds != null && workloadIds.Any()) | ||
{ | ||
builder.Append(string.Join(" ", workloadIds)); | ||
} | ||
|
||
return builder; | ||
} | ||
} | ||
} |