forked from cake-build/cake
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cake-buildGH-3482) Add alias for dotnet workload list command
* fixes cake-build#3857
- Loading branch information
Showing
6 changed files
with
388 additions
and
3 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Workload/List/DotNetWorkloadListerFixture.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,45 @@ | ||
// 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.List; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Workload.List | ||
{ | ||
internal sealed class DotNetWorkloadListerFixture : DotNetFixture<DotNetWorkloadListSettings> | ||
{ | ||
public IEnumerable<DotNetWorkloadListItem> Workloads { get; set; } | ||
|
||
public void GivenInstalledWorkloadsResult() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] | ||
{ | ||
"Installed Workload Ids Manifest Version Installation Source", | ||
"--------------------------------------------------------------------------------------", | ||
"maui-ios 6.0.312/6.0.300 VS 17.3.32804.467, VS 17.4.32804.182", | ||
"maui-windows 6.0.312/6.0.300 VS 17.3.32804.467, VS 17.4.32804.182", | ||
"android 32.0.301/6.0.300 VS 17.3.32804.467, VS 17.4.32804.182", | ||
"", | ||
"Use `dotnet workload search` to find additional workloads to install." | ||
}); | ||
} | ||
|
||
public void GivenEmptyInstalledWorkloadsResult() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] | ||
{ | ||
"Installed Workload Ids Manifest Version Installation Source", | ||
"---------------------------------------------------------------------", | ||
"", | ||
"Use `dotnet workload search` to find additional workloads to install." | ||
}); | ||
} | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetWorkloadLister(FileSystem, Environment, ProcessRunner, Tools); | ||
Workloads = tool.List(Settings); | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
src/Cake.Common.Tests/Unit/Tools/DotNet/Workload/List/DotNetWorkloadListTests.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,119 @@ | ||
// 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.List; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Workload.List | ||
{ | ||
public sealed class DotNetWorkloadListTests | ||
{ | ||
public sealed class TheWorkloadListMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadListerFixture(); | ||
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 DotNetWorkloadListerFixture(); | ||
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_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadListerFixture(); | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Verbosity_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadListerFixture(); | ||
fixture.Settings.Verbosity = Common.Tools.DotNet.DotNetVerbosity.Normal; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("workload list --verbosity normal", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Correct_List_Of_Workloads() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadListerFixture(); | ||
fixture.GivenInstalledWorkloadsResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Collection(fixture.Workloads, | ||
item => | ||
{ | ||
Assert.Equal(item.Id, "maui-ios"); | ||
Assert.Equal(item.ManifestVersion, "6.0.312/6.0.300"); | ||
Assert.Equal(item.InstallationSource, "VS 17.3.32804.467, VS 17.4.32804.182"); | ||
}, | ||
item => | ||
{ | ||
Assert.Equal(item.Id, "maui-windows"); | ||
Assert.Equal(item.ManifestVersion, "6.0.312/6.0.300"); | ||
Assert.Equal(item.InstallationSource, "VS 17.3.32804.467, VS 17.4.32804.182"); | ||
}, | ||
item => | ||
{ | ||
Assert.Equal(item.Id, "android"); | ||
Assert.Equal(item.ManifestVersion, "32.0.301/6.0.300"); | ||
Assert.Equal(item.InstallationSource, "VS 17.3.32804.467, VS 17.4.32804.182"); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Empty_List_Of_Workloads() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadListerFixture(); | ||
fixture.GivenEmptyInstalledWorkloadsResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Empty(fixture.Workloads); | ||
} | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/Cake.Common/Tools/DotNet/Workload/List/DotNetWorkloadListItem.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,40 @@ | ||
// 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.List | ||
{ | ||
/// <summary> | ||
/// An item as returned by <see cref="DotNetWorkloadLister"/>. | ||
/// </summary> | ||
public sealed class DotNetWorkloadListItem | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DotNetWorkloadListItem" /> class. | ||
/// </summary> | ||
/// <param name="id">The workload Id.</param> | ||
/// <param name="manifestVersion">The workload manifest version.</param> | ||
/// <param name="installationSource">The workload installation source.</param> | ||
public DotNetWorkloadListItem(string id, string manifestVersion, string installationSource) | ||
{ | ||
Id = id; | ||
ManifestVersion = manifestVersion; | ||
InstallationSource = installationSource; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the workload ID. | ||
/// </summary> | ||
public string Id { get; } | ||
|
||
/// <summary> | ||
/// Gets the manifest version of the workload as string. | ||
/// </summary> | ||
public string ManifestVersion { get; } | ||
|
||
/// <summary> | ||
/// Gets the installation source of the workload as string. | ||
/// </summary> | ||
public string InstallationSource { get; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Cake.Common/Tools/DotNet/Workload/List/DotNetWorkloadListSettings.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.List | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetWorkloadLister" />. | ||
/// </summary> | ||
public sealed class DotNetWorkloadListSettings : DotNetSettings | ||
{ | ||
} | ||
} |
Oops, something went wrong.