-
-
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 search command
- Loading branch information
Showing
6 changed files
with
201 additions
and
2 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Workload/Search/DotNetWorkloadSearcherFixture.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,19 @@ | ||
// 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.Tools.DotNet.Workload.Search; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Workload.Search | ||
{ | ||
internal sealed class DotNetWorkloadSearcherFixture : DotNetFixture<DotNetWorkloadSearchSettings> | ||
{ | ||
public string SearchString { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetWorkloadSearcher(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Search(SearchString); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/Cake.Common.Tests/Unit/Tools/DotNet/Workload/Search/DotNetWorkloadSearchTests.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,58 @@ | ||
// 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.Search; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Workload.Search | ||
{ | ||
public sealed class DotNetWorkloadSearchTests | ||
{ | ||
public sealed class TheWorkloadSearchMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadSearcherFixture(); | ||
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 DotNetWorkloadSearcherFixture(); | ||
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_SearchString_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetWorkloadSearcherFixture(); | ||
fixture.SearchString = "maui"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("workload search maui", 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
13 changes: 13 additions & 0 deletions
13
src/Cake.Common/Tools/DotNet/Workload/Search/DotNetWorkloadSearchSettings.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.Search | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetWorkloadSearcher" />. | ||
/// </summary> | ||
public sealed class DotNetWorkloadSearchSettings : DotNetSettings | ||
{ | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/Cake.Common/Tools/DotNet/Workload/Search/DotNetWorkloadSearcher.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,55 @@ | ||
// 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.Core; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tooling; | ||
|
||
namespace Cake.Common.Tools.DotNet.Workload.Search | ||
{ | ||
/// <summary> | ||
/// .NET workloads searcher. | ||
/// </summary> | ||
public sealed class DotNetWorkloadSearcher : DotNetTool<DotNetWorkloadSearchSettings> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DotNetWorkloadSearcher" /> 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 DotNetWorkloadSearcher( | ||
IFileSystem fileSystem, | ||
ICakeEnvironment environment, | ||
IProcessRunner processRunner, | ||
IToolLocator tools) : base(fileSystem, environment, processRunner, tools) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Lists the latest available version of the .NET SDK and .NET Runtime, for each feature band. | ||
/// </summary> | ||
/// <param name="searchString">The workload ID to search for, or part of it.</param> | ||
public void Search(string searchString) | ||
{ | ||
var settings = new DotNetWorkloadSearchSettings(); | ||
RunCommand(settings, GetArguments(searchString, settings)); | ||
} | ||
|
||
private ProcessArgumentBuilder GetArguments(string searchString, DotNetWorkloadSearchSettings settings) | ||
{ | ||
var builder = CreateArgumentBuilder(settings); | ||
|
||
builder.Append("workload search"); | ||
|
||
if (!string.IsNullOrEmpty(searchString)) | ||
{ | ||
builder.Append(searchString); | ||
} | ||
|
||
return builder; | ||
} | ||
} | ||
} |
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