Esempio n. 1
0
        public async Task ExtractSpecStyleCopAnalyzers()
        {
            var package = new NuGetPackageId("StyleCop.Analyzers", "1.1.118");

            byte[] specContent;
            using (var content = TempFile.OpenResource(GetType(), "NuGetApiTest.StyleCop.Analyzers.1.1.118.nupkg"))
            {
                specContent = await _sut.ExtractSpecAsync(package, await content.ToArrayAsync(CancellationToken.None), CancellationToken.None);
            }

            var spec = _sut.ParseSpec(new MemoryStream(specContent));

            spec.ShouldNotBeNull();
            spec.Id.ShouldBe("StyleCop.Analyzers");
            spec.Version.ShouldBe("1.1.118");
            spec.PackageHRef.ShouldBe("https://www.nuget.org/packages/StyleCop.Analyzers/1.1.118");
            spec.Description.ShouldBe("An implementation of StyleCop's rules using Roslyn analyzers and code fixes");
            spec.Authors.ShouldBe("Sam Harwell et. al.");
            spec.Copyright.ShouldBe("Copyright 2015 Tunnel Vision Laboratories, LLC");

            spec.License.ShouldNotBeNull();
            spec.License.Type.ShouldBe("expression");
            spec.License.Value.ShouldBe("Apache-2.0");
            spec.LicenseUrl.ShouldBe("https://licenses.nuget.org/Apache-2.0");

            spec.Repository.ShouldBeNull();

            spec.ProjectUrl.ShouldBe("https://github.com/DotNetAnalyzers/StyleCopAnalyzers");
        }
Esempio n. 2
0
        public async Task <byte[]> DownloadPackageAsync(NuGetPackageId package, bool allowToUseLocalCache, CancellationToken token)
        {
            if (allowToUseLocalCache)
            {
                var path = GetLocalCachePath(package);
                if (path != null)
                {
                    return(LoadPackageFromLocalCache(path, package.Name, package.Version));
                }
            }

            var url = GetPackageUri(package);

            using (var client = HttpClientFactory())
                using (var response = await client.GetAsync(url, token))
                {
                    if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(null);
                    }

                    await response.AssertStatusCodeOk();

                    using (var stream = await response.Content.ReadAsStreamAsync())
                    {
                        return(await stream.ToArrayAsync(token));
                    }
                }
        }
Esempio n. 3
0
        public async Task DownloadPackageStyleCopAnalyzersFromLocalCache()
        {
            var package = new NuGetPackageId("StyleCop.Analyzers", "1.1.118");

            var file = await _sut.DownloadPackageAsync(package, true, CancellationToken.None);

            file.ShouldNotBeNull();
        }
Esempio n. 4
0
            public TargetPackage(string fullName, JObject content)
            {
                _content = content;
                var index = fullName.IndexOf('/');

                Id = new NuGetPackageId(fullName.Substring(0, index), fullName.Substring(index + 1));

                var runtime = content.Value <JObject>("runtime");

                _ignoreByRuntime = runtime == null || runtime.Properties().All(i => i.Name.EndsWithIgnoreCase("/_._"));
            }
Esempio n. 5
0
        public async Task <byte[]> ExtractSpecAsync(NuGetPackageId package, byte[] packageContent, CancellationToken token)
        {
            packageContent.AssertNotNull(nameof(packageContent));

            var fileName = "{0}.nuspec".FormatWith(package.Name);
            var result   = await LoadFileContentAsync(packageContent, fileName, token);

            if (result == null)
            {
                throw new InvalidOperationException(fileName + " not found in the package.");
            }

            return(result);
        }
Esempio n. 6
0
        public async Task DownloadPackageStyleCopAnalyzersFromWeb()
        {
            var package = new NuGetPackageId("StyleCop.Analyzers", "1.1.118");

            _mockHttp
            .When(HttpMethod.Get, NuGetApi.Host + "/v3-flatcontainer/stylecop.analyzers/1.1.118/stylecop.analyzers.1.1.118.nupkg")
            .Respond(
                MediaTypeNames.Application.Octet,
                TempFile.OpenResource(GetType(), "NuGetApiTest.StyleCop.Analyzers.1.1.118.nupkg"));

            var file = await _sut.DownloadPackageAsync(package, false, CancellationToken.None);

            file.ShouldNotBeNull();
        }
Esempio n. 7
0
        private static string GetLocalCachePath(NuGetPackageId package)
        {
            string path;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                path = Path.Combine(
                    Environment.GetEnvironmentVariable("USERPROFILE"),
                    @".nuget\packages",
                    package.Name,
                    package.Version);
            }
            else
            {
                path = Path.Combine(
                    @"~/.nuget/packages",
                    package.Name,
                    package.Version);
            }

            return(Directory.Exists(path) ? path : null);
        }
Esempio n. 8
0
 private static Uri GetPackageUri(NuGetPackageId package) => new Uri(
     new Uri(Host),
     "v3-flatcontainer/{0}/{1}/{0}.{1}.nupkg".FormatWith(package.Name.ToLowerInvariant(), package.Version.ToLowerInvariant()));