-
-
Notifications
You must be signed in to change notification settings - Fork 741
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 #4369 from Marusyk/rmarusyk/4353
Add DotNetListReference alias for dotnet list reference command
- Loading branch information
Showing
6 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Reference/List/DotNetReferenceListerFixture.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,42 @@ | ||
// 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.List; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Reference.List | ||
{ | ||
internal sealed class DotNetReferenceListerFixture : DotNetFixture<DotNetReferenceListSettings> | ||
{ | ||
public string Project { get; set; } | ||
|
||
public IEnumerable<string> References { get; set; } | ||
|
||
public void GivenProjectReferencesResult() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] | ||
{ | ||
"Project reference(s)", | ||
"--------------------", | ||
"..\\..\\Common\\Common.AspNetCore\\Common.AspNetCore.csproj", | ||
"..\\..\\Common\\Common.Messaging\\Common.Messaging.csproj", | ||
"..\\..\\Common\\Common.Utilities\\Common.Utilities.csproj" | ||
}); | ||
} | ||
|
||
public void GivenEmptyProjectReferencesResult() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] | ||
{ | ||
"There are no Project to Project references in project C:\\Cake\\Cake.Core\\." | ||
}); | ||
} | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetReferenceLister(FileSystem, Environment, ProcessRunner, Tools); | ||
References = tool.List(Project, Settings); | ||
} | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
src/Cake.Common.Tests/Unit/Tools/DotNet/Reference/List/DotNetReferenceListerTests.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,144 @@ | ||
// 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.Reference.List; | ||
using Cake.Common.Tools.DotNet; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Reference.List | ||
{ | ||
public sealed class DotNetReferenceListerTests | ||
{ | ||
public sealed class TheListMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Process_Was_Not_Started() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceListerFixture(); | ||
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 DotNetReferenceListerFixture(); | ||
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 DotNetReferenceListerFixture(); | ||
fixture.Settings = null; | ||
fixture.GivenDefaultToolDoNotExist(); | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Not_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceListerFixture(); | ||
fixture.Project = null; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("list reference", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Project_Argument() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceListerFixture(); | ||
fixture.Project = "ToDo.csproj"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("list \"ToDo.csproj\" reference", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Additional_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceListerFixture(); | ||
fixture.Project = "ToDo.csproj"; | ||
fixture.Settings.Verbosity = DotNetVerbosity.Diagnostic; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
var expected = "list \"ToDo.csproj\" reference --verbosity diagnostic"; | ||
Assert.Equal(expected, result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Correct_List_Of_References() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceListerFixture(); | ||
fixture.GivenProjectReferencesResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Collection(fixture.References, | ||
item => | ||
{ | ||
Assert.Equal(item, "..\\..\\Common\\Common.AspNetCore\\Common.AspNetCore.csproj"); | ||
}, | ||
item => | ||
{ | ||
Assert.Equal(item, "..\\..\\Common\\Common.Messaging\\Common.Messaging.csproj"); | ||
}, | ||
item => | ||
{ | ||
Assert.Equal(item, "..\\..\\Common\\Common.Utilities\\Common.Utilities.csproj"); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Empty_List_Of_References() | ||
{ | ||
// Given | ||
var fixture = new DotNetReferenceListerFixture(); | ||
fixture.GivenEmptyProjectReferencesResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Empty(fixture.References); | ||
} | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/Cake.Common/Tools/DotNet/Reference/List/DotNetReferenceListSettings.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,13 @@ | ||
// 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.List | ||
{ | ||
/// <summary> | ||
/// Contains settings used by <see cref="DotNetReferenceLister" />. | ||
/// </summary> | ||
public sealed class DotNetReferenceListSettings : DotNetSettings | ||
{ | ||
} | ||
} |
Oops, something went wrong.