-
-
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.
Add DotNetRemoveReference alias for dotnet remove reference command
- Loading branch information
1 parent
86ad011
commit 7614074
Showing
6 changed files
with
406 additions
and
5 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...Cake.Common.Tests/Fixtures/Tools/DotNet/Reference/Remove/DotNetReferenceRemoverFixture.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.Remove; | ||
using Cake.Core.IO; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Reference.Remove | ||
{ | ||
internal sealed class DotNetReferenceRemoverFixture : DotNetFixture<DotNetReferenceRemoveSettings> | ||
{ | ||
public string Project { get; set; } | ||
|
||
public IEnumerable<FilePath> ProjectReferences { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetReferenceRemover(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Remove(Project, ProjectReferences, Settings); | ||
} | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
src/Cake.Common.Tests/Unit/Tools/DotNet/Reference/Remove/DotNetReferenceRemoverTests.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,158 @@ | ||
// 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.Remove; | ||
using Cake.Common.Tools.DotNet; | ||
using Cake.Core.IO; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Reference.Remove | ||
{ | ||
public sealed class DotNetReferenceRemoverTests | ||
{ | ||
public sealed class TheRemoveMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceRemoverFixture(); | ||
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 DotNetReferenceRemoverFixture(); | ||
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 DotNetReferenceRemoverFixture(); | ||
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 DotNetReferenceRemoverFixture(); | ||
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 DotNetReferenceRemoverFixture(); | ||
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 DotNetReferenceRemoverFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" }; | ||
fixture.Project = null; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("remove reference \"/Working/lib1.csproj\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_All_Project_References() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceRemoverFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj", "./lib2/*.csproj" }; | ||
fixture.Project = null; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("remove reference \"/Working/lib1.csproj\" \"/Working/lib2/*.csproj\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceRemoverFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" }; | ||
fixture.Project = "ToDo.csproj"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("remove \"ToDo.csproj\" reference \"/Working/lib1.csproj\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceRemoverFixture(); | ||
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" }; | ||
fixture.Project = "ToDo.csproj"; | ||
fixture.Settings.Framework = "net7.0"; | ||
fixture.Settings.Verbosity = DotNetVerbosity.Diagnostic; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
var expected = "remove \"ToDo.csproj\" reference \"/Working/lib1.csproj\" --framework net7.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
17 changes: 17 additions & 0 deletions
17
src/Cake.Common/Tools/DotNet/Reference/Remove/DotNetReferenceRemoveSettings.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,17 @@ | ||
// 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.Remove | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetReferenceRemover" />. | ||
/// </summary> | ||
public sealed class DotNetReferenceRemoveSettings : DotNetSettings | ||
{ | ||
/// <summary> | ||
/// Gets or sets a specific framework. | ||
/// </summary> | ||
public string Framework { get; set; } | ||
} | ||
} |
Oops, something went wrong.