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.
Merge pull request cake-build#4320 from paulomorgado/DotNetSearchPackage
Add .NET package search to Cake scripts
- Loading branch information
Showing
8 changed files
with
619 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/Cake.Common.Tests/Fixtures/Tools/DotNet/Package/Search/DotNetPackageSearcherFixture.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,52 @@ | ||
// 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.Package.Search; | ||
|
||
namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Package.Search | ||
{ | ||
internal class DotNetPackageSearcherFixture : DotNetFixture<DotNetPackageSearchSettings> | ||
{ | ||
public string SearchTerm { get; set; } | ||
|
||
public IEnumerable<DotNetPackageSearchItem> Result { get; private set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DotNetPackageSearcher(FileSystem, Environment, ProcessRunner, Tools); | ||
Result = tool.Search(SearchTerm, Settings); | ||
} | ||
|
||
internal void GivenNormalPackageResult() | ||
{ | ||
ProcessRunner.Process.SetStandardOutput(new string[] | ||
{ | ||
"{", | ||
" \"version\": 2,", | ||
" \"problems\": [],", | ||
" \"searchResult\": [", | ||
" {", | ||
" \"sourceName\": \"nuget.org\",", | ||
" \"packages\": [", | ||
" {", | ||
" \"id\": \"Cake\",", | ||
" \"latestVersion\": \"0.22.2\"", | ||
" },", | ||
" {", | ||
" \"id\": \"Cake.Core\",", | ||
" \"latestVersion\": \"0.22.2\"", | ||
" },", | ||
" {", | ||
" \"id\": \"Cake.CoreCLR\",", | ||
" \"latestVersion\": \"0.22.2\"", | ||
" }", | ||
" ]", | ||
" }", | ||
" ]", | ||
"}", | ||
}); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Cake.Common.Tests/Unit/Tools/DotNet/Package/Search/DotNetPackageSearchSettingsTests.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,51 @@ | ||
using Cake.Common.Tools.DotNet.Package.Search; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Package.Search | ||
{ | ||
public sealed class DotNetPackageSearchSettingsTests | ||
{ | ||
public sealed class TheConstructor | ||
{ | ||
[Fact] | ||
public void Should_Set_ExactMatch_To_False_By_Default() | ||
{ | ||
// Given, When | ||
var settings = new DotNetPackageSearchSettings(); | ||
|
||
// Then | ||
Assert.False(settings.ExactMatch); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Take_To_Null_By_Default() | ||
{ | ||
// Given, When | ||
var settings = new DotNetPackageSearchSettings(); | ||
|
||
// Then | ||
Assert.Null(settings.Take); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Skip_To_Null_By_Default() | ||
{ | ||
// Given, When | ||
var settings = new DotNetPackageSearchSettings(); | ||
|
||
// Then | ||
Assert.Null(settings.Skip); | ||
} | ||
|
||
[Fact] | ||
public void Should_Set_Prerelease_To_False_By_Default() | ||
{ | ||
// Given, When | ||
var settings = new DotNetPackageSearchSettings(); | ||
|
||
// Then | ||
Assert.False(settings.Prerelease); | ||
} | ||
} | ||
} | ||
} |
173 changes: 173 additions & 0 deletions
173
src/Cake.Common.Tests/Unit/Tools/DotNet/Package/Search/DotNetPackageSearcherTests.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,173 @@ | ||
// 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.Search; | ||
using Cake.Common.Tools.DotNet; | ||
using Cake.Testing; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit.Tools.DotNet.Package.Search | ||
{ | ||
public sealed class DotNetPackageSearcherTests | ||
{ | ||
public sealed class TheSearchMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.Settings = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
AssertEx.IsArgumentNullException(result, "settings"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Mandatory_Arguments() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_ExactMatch_To_Arguments_If_True() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.Settings.ExactMatch = true; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --exact-match --verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Prerelease_To_Arguments_If_True() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.Settings.Prerelease = true; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --prerelease --verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Take_To_Arguments_If_True() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.Settings.Take = 10; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --take 10 --verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Skip_To_Arguments_If_True() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.Settings.Skip = 10; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --skip 10 --verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Sources_To_Arguments_If_Set() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.Settings.Sources = new[] { "A", "B", "C", }; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --source \"A\" --source \"B\" --source \"C\" --verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_ConfigFile_To_Arguments_If_Set() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.Settings.ConfigFile = "./nuget.config"; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("package search \"Cake\" --configfile \"/Working/nuget.config\" " + | ||
"--verbosity normal --format json", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Return_Correct_List_Of_DotNetPackageSearchItems() | ||
{ | ||
// Given | ||
var fixture = new DotNetPackageSearcherFixture(); | ||
fixture.SearchTerm = "Cake"; | ||
fixture.GivenNormalPackageResult(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Collection(fixture.Result, | ||
item => | ||
{ | ||
Assert.Equal(item.Name, "Cake"); | ||
Assert.Equal(item.Version, "0.22.2"); | ||
}, | ||
item => | ||
{ | ||
Assert.Equal(item.Name, "Cake.Core"); | ||
Assert.Equal(item.Version, "0.22.2"); | ||
}, | ||
item => | ||
{ | ||
Assert.Equal(item.Name, "Cake.CoreCLR"); | ||
Assert.Equal(item.Version, "0.22.2"); | ||
}); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.