-
-
Notifications
You must be signed in to change notification settings - Fork 729
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 #4283 from Marusyk/rmarusyk/4282
Add DotNetAddReference alias for dotnet add reference command
- Loading branch information
Showing
6 changed files
with
414 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Reference/Add/DotNetReferenceAdderFixture.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,23 @@ | ||
// 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.Reference.Add; | ||
using Cake.Core.IO; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Reference.Add | ||
{ | ||
internal sealed class DotNetReferenceAdderFixture : DotNetFixture<DotNetReferenceAddSettings> | ||
{ | ||
public string Project { get; set; } | ||
|
||
public IEnumerable<FilePath> ProjectReferences { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetReferenceAdder(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Add(Project, ProjectReferences, Settings); | ||
} | ||
} | ||
} |
159 changes: 159 additions & 0 deletions
159
src/Cake.Common.Tests/Unit/Tools/DotNet/Reference/Add/DotNetReferenceAdderTests.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,159 @@ | ||
// 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; | ||
using Cake.Common.Tests.Fixtures.Tools.DotNet.Reference.Add; | ||
using Cake.Common.Tools.DotNet; | ||
using Cake.Core.IO; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Reference.Add | ||
{ | ||
public sealed class DotNetReferenceAdderTests | ||
{ | ||
public sealed class TheAddMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./test/unit.tests.csproj" }; | ||
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 DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./test/unit.tests.csproj" }; | ||
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 DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./test/unit.tests.csproj" }; | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_ProjectReferences_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "projectReferences"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_ProjectReferences_Is_Empty() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = Array.Empty<FilePath>(); | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "projectReferences"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Not_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" }; | ||
fixture.Project = null; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("add reference \"/Working/lib1.csproj\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_All_Project_References() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj", "./lib2/*.csproj" }; | ||
fixture.Project = null; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("add reference \"/Working/lib1.csproj\" \"/Working/lib2/*.csproj\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" }; | ||
fixture.Project = "ToDo.csproj"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("add \"ToDo.csproj\" reference \"/Working/lib1.csproj\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceAdderFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" }; | ||
fixture.Project = "ToDo.csproj"; | ||
fixture.Settings.Framework = "net7.0"; | ||
fixture.Settings.Interactive = true; | ||
fixture.Settings.Verbosity = DotNetVerbosity.Diagnostic; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
var expected = "add \"ToDo.csproj\" reference \"/Working/lib1.csproj\" --framework net7.0 --interactive --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
23 changes: 23 additions & 0 deletions
23
src/Cake.Common/Tools/DotNet/Reference/Add/DotNetReferenceAddSettings.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,23 @@ | ||
// 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.Reference.Add | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetReferenceAdder" />. | ||
/// </summary> | ||
public sealed class DotNetReferenceAddSettings : DotNetSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets a specific framework. | ||
/// </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. Available since .NET Core 3.0 SDK. | ||
/// </summary> | ||
public bool Interactive { get; set; } | ||
} | ||
} |
Oops, something went wrong.