-
-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for dotnet nuget delete inline with Tooling v1.0 #1533
- Loading branch information
Showing
5 changed files
with
428 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/Cake.Common.Tests/Fixtures/Tools/DotNetCore/NuGet/Delete/DotNetCoreDeleterFixture.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 Cake.Common.Tools.DotNetCore.NuGet.Delete; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNetCore.NuGet.Delete | ||
{ | ||
internal sealed class DotNetCoreDeleterFixture : DotNetCoreFixture<DotNetCoreNuGetDeleteSettings> | ||
{ | ||
public string PackageName { get; set; } | ||
public string PackageVersion { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetCoreNuGetDeleter(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Delete(PackageName, PackageVersion, Settings); | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
src/Cake.Common.Tests/Unit/Tools/DotNetCore/NuGet/Delete/DotNetCoreDeleterTests.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,135 @@ | ||
// 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.DotNetCore.NuGet.Delete; | ||
using Cake.Common.Tools.DotNetCore.NuGet.Delete; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNetCore.NuGet.Delete | ||
{ | ||
public sealed class DotNetCoreDeleterTests | ||
{ | ||
public sealed class TheDeleteMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Should_Not_Throw_If_PackageName_Is_Empty(string packageName) | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.PackageName = packageName; | ||
fixture.Settings = new DotNetCoreNuGetDeleteSettings(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("nuget delete", result.Args); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
public void Should_Not_Throw_If_PackageVersion_Is_Empty(string packageVersion) | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.PackageName = "name"; | ||
fixture.PackageVersion = packageVersion; | ||
fixture.Settings = new DotNetCoreNuGetDeleteSettings(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("nuget delete name", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.GivenProcessCannotStart(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsCakeException(result, ".NET Core CLI: Process was not started."); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.GivenProcessExitsWithCode(1); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
Assert.IsCakeException(result, ".NET Core CLI: Process returned an error (exit code 1)."); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
const string packageName = "name"; | ||
const string packageVersion = "1.2.3"; | ||
const string source = "http://www.nuget.org/api/v2/package"; | ||
const string apiKey = "key1234"; | ||
|
||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.Settings.Source = source; | ||
fixture.Settings.NonInteractive = true; | ||
fixture.Settings.ApiKey = apiKey; | ||
fixture.Settings.ForceEnglishOutput = true; | ||
fixture.PackageName = packageName; | ||
fixture.PackageVersion = packageVersion; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal(string.Format("nuget delete {0} {1} --source \"{2}\" --non-interactive --api-key \"{3}\" --force-english-output", packageName, packageVersion, source, apiKey), result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Host_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetCoreDeleterFixture(); | ||
fixture.Settings.DiagnosticOutput = true; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("--diagnostics nuget delete", 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
37 changes: 37 additions & 0 deletions
37
src/Cake.Common/Tools/DotNetCore/NuGet/Delete/DotNetCoreNuGetDeleteSettings.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,37 @@ | ||
// 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.DotNetCore.NuGet.Delete | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetCoreNuGetDeleter" />. | ||
/// </summary> | ||
public sealed class DotNetCoreNuGetDeleteSettings : DotNetCoreSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating the server URL. | ||
/// </summary> | ||
/// <remarks> | ||
/// Supported URLs for nuget.org include http://www.nuget.org, http://www.nuget.org/api/v3, | ||
/// and http://www.nuget.org/api/v2/package. For private feeds, substitute the host name | ||
/// (for example, %hostname%/api/v3). | ||
/// </remarks> | ||
public string Source { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to prompt for user input or confirmations. | ||
/// </summary> | ||
public bool NonInteractive { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating the API key for the server. | ||
/// </summary> | ||
public string ApiKey { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to force command-line output in English. | ||
/// </summary> | ||
public bool ForceEnglishOutput { get; set; } | ||
} | ||
} |
Oops, something went wrong.