-
-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4229 from Marusyk/rmarusyk/4224
Add DotNetListPackage alias for dotnet list package command
- Loading branch information
Showing
15 changed files
with
770 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Package/List/DotNetPackageListerFixture.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,49 @@ | ||
// 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.Package.List; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Package.List | ||
{ | ||
internal sealed class DotNetPackageListerFixture : DotNetFixture<DotNetPackageListSettings> | ||
{ | ||
public string Project { get; set; } | ||
public DotNetPackageList Result { get; set; } | ||
|
||
public void GivenPackgeListResult() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] | ||
{ | ||
"{", | ||
" \"version\": 1,", | ||
" \"parameters\": \"\",", | ||
" \"projects\": [", | ||
" {", | ||
" \"path\": \"src/lib/MyProject.csproj\",", | ||
" \"frameworks\": [", | ||
" {", | ||
" \"framework\": \"netstandard2.0\",", | ||
" \"topLevelPackages\": [", | ||
" {", | ||
" \"id\": \"NETStandard.Library\",", | ||
" \"requestedVersion\": \"[2.0.3, )\",", | ||
" \"resolvedVersion\": \"2.0.3\",", | ||
" \"autoReferenced\": \"true\"", | ||
" }", | ||
" ]", | ||
" }", | ||
" ]", | ||
" }", | ||
" ]", | ||
"}" | ||
}); | ||
} | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetPackageLister(FileSystem, Environment, ProcessRunner, Tools); | ||
Result = tool.List(Project, Settings); | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
src/Cake.Common.Tests/Unit/Tools/DotNet/Package/List/DotNetPackageListerTests.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,118 @@ | ||
// 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.Package.List; | ||
using Cake.Common.Tools.DotNet; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Package.List | ||
{ | ||
public sealed class DotNetPackageListerTests | ||
{ | ||
public sealed class TheListMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageListerFixture(); | ||
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 DotNetPackageListerFixture(); | ||
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 DotNetPackageListerFixture(); | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageListerFixture(); | ||
fixture.Project = "ToDo.csproj"; | ||
fixture.GivenPackgeListResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("list \"ToDo.csproj\" package --format json --output-version 1", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageListerFixture(); | ||
fixture.Settings.ConfigFile = "./nuget.config"; | ||
fixture.Settings.Deprecated = true; | ||
fixture.Settings.Framework = "net7.0"; | ||
fixture.Settings.HighestMinor = true; | ||
fixture.Settings.HighestPatch = true; | ||
fixture.Settings.Prerelease = true; | ||
fixture.Settings.Transitive = true; | ||
fixture.Settings.Interactive = true; | ||
fixture.Settings.Outdated = true; | ||
fixture.Settings.Source.Add("http://www.nuget.org/api/v2/package"); | ||
fixture.Settings.Source.Add("http://www.symbolserver.org/"); | ||
fixture.Settings.Vulnerable = true; | ||
fixture.GivenPackgeListResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
var expected = "list package --config \"/Working/nuget.config\" --deprecated --framework net7.0 --highest-minor --highest-patch --include-prerelease --include-transitive --interactive --outdated "; | ||
expected += "--source \"http://www.nuget.org/api/v2/package\" --source \"http://www.symbolserver.org/\" --vulnerable --format json --output-version 1"; | ||
Assert.Equal(expected, result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Correct_Result() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageListerFixture(); | ||
fixture.GivenPackgeListResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal(1, fixture.Result.Version); | ||
Assert.Contains(fixture.Result.Projects, item => item.Path == "src/lib/MyProject.csproj"); | ||
} | ||
} | ||
} | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageList.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 System.Text.Json.Serialization; | ||
|
||
namespace Cake.Common.Tools.DotNet.Package.List | ||
{ | ||
/// <summary> | ||
/// An result as returned by <see cref="DotNetPackageLister"/>. | ||
/// </summary> | ||
public sealed class DotNetPackageList | ||
{ | ||
/// <summary> | ||
/// Gets the output version. | ||
/// </summary> | ||
[JsonInclude] | ||
public int Version { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the specified parameters. | ||
/// </summary> | ||
[JsonInclude] | ||
public string Parameters { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the problems. | ||
/// </summary> | ||
[JsonInclude] | ||
public IEnumerable<DotNetPackageListProblemItem> Problems { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the used sources. | ||
/// </summary> | ||
[JsonInclude] | ||
public IEnumerable<string> Sources { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the projects. | ||
/// </summary> | ||
[JsonInclude] | ||
public IEnumerable<DotNetPackageListProjectItem> Projects { get; private set; } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListAlternativePackageItem.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,26 @@ | ||
// 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.Text.Json.Serialization; | ||
|
||
namespace Cake.Common.Tools.DotNet.Package.List | ||
{ | ||
/// <summary> | ||
/// The alternative package information. | ||
/// </summary> | ||
public sealed class DotNetPackageListAlternativePackageItem | ||
{ | ||
/// <summary> | ||
/// Gets the alternative package id. | ||
/// </summary> | ||
[JsonInclude] | ||
public string Id { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the alternative package versions. | ||
/// </summary> | ||
[JsonInclude] | ||
public string VersionRange { get; private set; } | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListFrameworkItem.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,33 @@ | ||
// 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 System.Text.Json.Serialization; | ||
|
||
namespace Cake.Common.Tools.DotNet.Package.List | ||
{ | ||
/// <summary> | ||
/// The framework information. | ||
/// </summary> | ||
public sealed class DotNetPackageListFrameworkItem | ||
{ | ||
/// <summary> | ||
/// Gets the framework name. | ||
/// </summary> | ||
[JsonInclude] | ||
public string Framework { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the top-level packages. | ||
/// </summary> | ||
[JsonInclude] | ||
public IEnumerable<DotNetPackageListPackageItem> TopLevelPackages { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets transitive packages. | ||
/// </summary> | ||
[JsonInclude] | ||
public IEnumerable<DotNetPackageListPackageItem> TransitivePackages { get; private set; } | ||
} | ||
} |
Oops, something went wrong.