/// <summary> /// Retrieve dependency package metadata for a package. /// </summary> /// <remarks> /// If a package has a large number of dependencies this method can be long running. /// Use the IgnoreAuthors filter on the request object to filter out unwanted dependencies. /// </remarks> /// <param name="request">Get dependencies request.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task <IList <IPackageSearchMetadata> > GetDependenciesAsync(GetDependenciesRequest request, CancellationToken cancellationToken = default) { if (request == null) { throw new ArgumentNullException(nameof(request)); } await SetQueryRootPackage(request, cancellationToken); var list = new List <IPackageSearchMetadata>(); if (request.RootPackage == null) { return(list); } if (request.AddRootPackageToResults) { list.Add(request.RootPackage); } await AddDependencies(list, request, request.RootPackage, cancellationToken); return(list); }
public async Task WhenPackageHasSingleDependency_ThenReturnPackage() { var query = new GetDependenciesRequest("ByteDev.Crypto", "5.0.2", NuGetFrameworkFactory.CreateStandard("2.0")); var result = await _sut.GetDependenciesAsync(query); Assert.That(result.Single().Identity.ToString(), Is.EqualTo("ByteDev.Encoding.1.0.0")); }
public async Task WhenPackageHasNoDependencies_ThenReturnEmpty() { var query = new GetDependenciesRequest("ByteDev.Strings", "4.1.0", NuGetFrameworkFactory.CreateStandard("2.0")); var result = await _sut.GetDependenciesAsync(query); Assert.That(result, Is.Empty); }
public async Task WhenPackageHasTwoDependencies_ThenReturnPackages() { var query = new GetDependenciesRequest("ByteDev.Hibp", "3.0.0", NuGetFrameworkFactory.CreateStandard("2.0")); var result = await _sut.GetDependenciesAsync(query); Assert.That(result.First().Identity.ToString(), Is.EqualTo("ByteDev.Common.7.0.0")); Assert.That(result.Second().Identity.ToString(), Is.EqualTo("Newtonsoft.Json.11.0.2")); }
private async Task SetQueryRootPackage(GetDependenciesRequest request, CancellationToken cancellationToken) { if (request.Package == null) { request.RootPackage = await GetAsync(request.PackageId, request.PackageVersion, cancellationToken); } else { request.RootPackage = request.Package; } }
public async Task WhenPackageHasMultipleDependencies_ThenReturnPackages() { var query = new GetDependenciesRequest("ByteDev.Testing.NUnit", "1.1.0", NuGetFrameworkFactory.CreateStandard("2.0")); query.IgnoreAuthors.Add("Microsoft"); var result = await _sut.GetDependenciesAsync(query); Assert.That(result.First().Identity.ToString(), Is.EqualTo("ByteDev.Crypto.5.0.2")); Assert.That(result.Second().Identity.ToString(), Is.EqualTo("ByteDev.Encoding.1.0.0")); Assert.That(result.Third().Identity.ToString(), Is.EqualTo("NUnit.3.12.0")); }
public async Task WhenAddingRoot_ThenAddRootPackage() { var nuGetFramework = NuGetFrameworkFactory.CreateFramework("4.5"); var query = new GetDependenciesRequest("Moq", "4.14.5", nuGetFramework) { AddRootPackageToResults = true }; query.IgnoreAuthors.Add("Microsoft"); var result = await _sut.GetDependenciesAsync(query); Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result.First().Identity.ToString(), Is.EqualTo("Moq.4.14.5")); Assert.That(result.Second().Identity.ToString(), Is.EqualTo("Castle.Core.4.4.0")); }
private async Task AddDependencies(List <IPackageSearchMetadata> list, GetDependenciesRequest request, IPackageSearchMetadata package, CancellationToken cancellationToken) { foreach (var dependencyGroup in package.DependencySets.Where(x => x.TargetFramework == request.DependencyTarget)) { foreach (var dependencyPackage in dependencyGroup.Packages.OrderBy(p => p.Id)) { var p = await GetAsync(dependencyPackage.Id, dependencyPackage.VersionRange.MinVersion.ToString(), cancellationToken); if (!p.Authors.ContainsAny(request.IgnoreAuthors)) { list.Add(p); await AddDependencies(list, request, p, cancellationToken); } } } }
public override Task <GetDependenciesResponse> GetDependencies(GetDependenciesRequest request, ServerCallContext context) { //return base.GetDependencies(request, context); return(null); }