forked from cake-build/cake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DotNetAddPackage alias for dotnet add package command (cake-build…
…#4195) * Add DotNetAddPackage alias for dotnet add package command * Add an integration test for DotNetAddPackage alias * Add an integration test for DotNetAddPackage alias * Change the package in integration test for DotNetAddPackage alias
- Loading branch information
Showing
6 changed files
with
433 additions
and
1 deletion.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Package/Add/DotNetPackageAdderFixture.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,21 @@ | ||
// 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.Add; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Package.Add | ||
{ | ||
internal sealed class DotNetPackageAdderFixture : DotNetFixture<DotNetPackageAddSettings> | ||
{ | ||
public string PackageName { get; set; } | ||
|
||
public string Project { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetPackageAdder(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Add(PackageName, Project, Settings); | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
src/Cake.Common.Tests/Unit/Tools/DotNet/Package/Add/DotNetPackageAdderTests.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.Package.Add; | ||
using Cake.Common.Tests.Fixtures.Tools.DotNet.SDKCheck; | ||
using Cake.Common.Tests.Fixtures.Tools.DotNet.Workload.Restore; | ||
using Cake.Common.Tools.DotNet; | ||
using Cake.Common.Tools.DotNet.Package.Add; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Package.Add | ||
{ | ||
public sealed class DotNetPackageAdderTests | ||
{ | ||
public sealed class TheAddMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageAdderFixture(); | ||
fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; | ||
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 DotNetPackageAdderFixture(); | ||
fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; | ||
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 DotNetPackageAdderFixture(); | ||
fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_PackageName_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageAdderFixture(); | ||
fixture.PackageName = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "packageName"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageAdderFixture(); | ||
fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; | ||
fixture.Project = "ToDo.csproj"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("add \"ToDo.csproj\" package Microsoft.AspNetCore.StaticFiles", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageAdderFixture(); | ||
fixture.PackageName = "Microsoft.AspNetCore.StaticFiles"; | ||
fixture.Settings.Framework = "net7.0"; | ||
fixture.Settings.Interactive = true; | ||
fixture.Settings.NoRestore = true; | ||
fixture.Settings.PackageDirectory = "./src/project"; | ||
fixture.Settings.Prerelease = true; | ||
fixture.Settings.Source = "http://www.nuget.org/api/v2/package"; | ||
fixture.Settings.Version = "1.0.0"; | ||
fixture.Settings.Verbosity = DotNetVerbosity.Diagnostic; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
var expected = "add package Microsoft.AspNetCore.StaticFiles --framework net7.0 --interactive --no-restore --package-directory \"/Working/src/project\" --prerelease --source \"http://www.nuget.org/api/v2/package\" --version \"1.0.0\" --verbosity diagnostic"; | ||
Assert.Equal(expected, 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
54 changes: 54 additions & 0 deletions
54
src/Cake.Common/Tools/DotNet/Package/Add/DotNetPackageAddSettings.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,54 @@ | ||
// 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.IO; | ||
|
||
namespace Cake.Common.Tools.DotNet.Package.Add | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetPackageAdder" />. | ||
/// </summary> | ||
public sealed class DotNetPackageAddSettings : DotNetSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets a specific framework to compile. | ||
/// </summary> | ||
public string Framework { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action. | ||
/// For example, to complete authentication. | ||
/// </summary> | ||
public bool Interactive { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to not do implicit NuGet package restore. | ||
/// This makes run faster, but requires restore to be done before run is executed. | ||
/// </summary> | ||
public bool NoRestore { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the directory path where to restore the packages. | ||
/// The default package restore location is %userprofile%\.nuget\packages on Windows and ~/.nuget/packages on macOS and Linux. | ||
/// </summary> | ||
public DirectoryPath PackageDirectory { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to allow installation of prerelease packages. | ||
/// Available since .NET Core 5 SDK. | ||
/// </summary> | ||
public bool Prerelease { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the URI of the NuGet package source to use during the restore operation. | ||
/// </summary> | ||
public string Source { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the version of the package to install. | ||
/// If none specified, the latest will be used. | ||
/// </summary> | ||
public string Version { get; set; } | ||
} | ||
} |
Oops, something went wrong.