예제 #1
0
        public async Task V2FeedParser_DownloadFromInvalidUrl()
        {
            // Arrange
            var randomName = Guid.NewGuid().ToString();
            var repo       = Repository.Factory.GetCoreV3(TestServers.NuGetV2);

            var httpSource = HttpSource.Create(repo);

            V2FeedParser parser = new V2FeedParser(httpSource, TestServers.NuGetV2);

            // Act
            using (var packagesFolder = TestDirectory.Create())
                using (var cacheContext = new SourceCacheContext())
                {
                    Exception ex = await Assert.ThrowsAsync <FatalProtocolException>(
                        async() => await parser.DownloadFromUrl(
                            new PackageIdentity("not-found", new NuGetVersion("6.2.0")),
                            new Uri($"https://www.{randomName}.org/api/v2/"),
                            new PackageDownloadContext(cacheContext),
                            packagesFolder,
                            NullLogger.Instance,
                            CancellationToken.None));

                    // Assert
                    Assert.NotNull(ex);
                    Assert.Equal($"Error downloading 'not-found.6.2.0' from 'https://www.{randomName}.org/api/v2/'.", ex.Message);
                }
        }
예제 #2
0
        public async Task V2FeedParser_DownloadFromUrlInvalidId()
        {
            // Arrange
            var repo = Repository.Factory.GetCoreV3(TestServers.NuGetV2);

            var httpSource = HttpSource.Create(repo);

            V2FeedParser parser = new V2FeedParser(httpSource, TestServers.NuGetV2);

            // Act
            using (var packagesFolder = TestDirectory.Create())
                using (var cacheContext = new SourceCacheContext())
                {
                    var actual = await parser.DownloadFromUrl(
                        new PackageIdentity("not-found", new NuGetVersion("6.2.0")),
                        new Uri($@"{TestServers.NuGetV2}/package/not-found/6.2.0"),
                        new PackageDownloadContext(cacheContext),
                        packagesFolder,
                        NullLogger.Instance,
                        CancellationToken.None);

                    // Assert
                    Assert.NotNull(actual);
                    Assert.Equal(DownloadResourceResultStatus.NotFound, actual.Status);
                }
        }
예제 #3
0
        public async Task V2FeedParser_DownloadFromUrl()
        {
            // Arrange
            var repo = Repository.Factory.GetCoreV3("https://www.nuget.org/api/v2/");

            var httpSource = HttpSource.Create(repo);

            var parser = new V2FeedParser(httpSource, "https://www.nuget.org/api/v2/");

            // Act & Assert
            using (var packagesFolder = TestDirectory.Create())
                using (var cacheContext = new SourceCacheContext())
                    using (var downloadResult = await parser.DownloadFromUrl(
                               new PackageIdentity("WindowsAzure.Storage", new NuGetVersion("6.2.0")),
                               new Uri("https://www.nuget.org/api/v2/package/WindowsAzure.Storage/6.2.0"),
                               new PackageDownloadContext(cacheContext),
                               packagesFolder,
                               NullLogger.Instance,
                               CancellationToken.None))
                    {
                        var packageReader = downloadResult.PackageReader;
                        var files         = packageReader.GetFiles();

                        Assert.Equal(11, files.Count());
                    }
        }