Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Make the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Steele committed Jul 23, 2017
1 parent 5995aff commit 1cbc2cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion NuKeeper.Tests/Nuget/Api/ApiPackageLookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public async Task WellKnownPackageName_ShouldReturnResult()
Assert.That(package.Identity.Id, Is.EqualTo("Newtonsoft.Json"));
}


[Test]
public async Task AmbigousPackageName_ShouldReturnCorrectResult()
{
Expand Down
26 changes: 13 additions & 13 deletions NuKeeper/NuGet/Api/ApiPackageLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
Expand All @@ -11,18 +12,21 @@ namespace NuKeeper.NuGet.Api
{
public class ApiPackageLookup : IApiPackageLookup
{
private readonly ILogger _logger = new ConsoleLogger();

public async Task<IPackageSearchMetadata> LookupLatest(string packageName)
{
var versions = await Lookup(packageName);
return versions.FirstOrDefault();
return versions
.OrderByDescending(p => p?.Identity?.Version)
.FirstOrDefault();
}

private async Task<IEnumerable<IPackageSearchMetadata>> Lookup(string packageName)
{
var sourceRepository = BuildSourceRepository();
var searchResource = await sourceRepository.GetResourceAsync<PackageSearchResource>();

return await SearchForPackages(searchResource, packageName);
var metadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
return await FindPackage(metadataResource, packageName);
}

private static SourceRepository BuildSourceRepository()
Expand All @@ -35,15 +39,11 @@ private static SourceRepository BuildSourceRepository()
return new SourceRepository(packageSource, providers);
}

private static async Task<IEnumerable<IPackageSearchMetadata>> SearchForPackages(PackageSearchResource searchResource, string packageName)
{
var logger = new ConsoleLogger();
var filter = new SearchFilter(false);

var packages = await searchResource
.SearchAsync(packageName, filter, 0, 10, logger, CancellationToken.None);

return packages;
private async Task<IEnumerable<IPackageSearchMetadata>> FindPackage(
PackageMetadataResource metadataResource, string packageName)
{
return await metadataResource
.GetMetadataAsync(packageName, false, false, _logger, CancellationToken.None);
}
}
}

0 comments on commit 1cbc2cd

Please sign in to comment.