public void GetFeedType_WithUnknownSource_ReturnsFileSystemUnknown()
        {
            // Arrange & Act
            var type = FeedTypeUtility.GetFeedType(new PackageSource("\\blah"));

            // Assert
            Assert.Equal(FeedType.FileSystemUnknown, type);
        }
        public void FeedTypeUtility_VerifyBadSourceIsUnknown2()
        {
            // Arrange & Act
            var type = FeedTypeUtility.GetFeedType(new PackageSource("$|. \n\t"));

            // Assert
            Assert.Equal(FeedType.FileSystemUnknown, type);
        }
        public void GetFeedType_WithIllegalPathCharacters_ReturnsFileSystemUnknown()
        {
            // Arrange & Act
            var type = FeedTypeUtility.GetFeedType(new PackageSource("$|. \n\t"));

            // Assert
            Assert.Equal(FeedType.FileSystemUnknown, type);
        }
        public void GetFeedType_WithRelativePath_ReturnsFileSystemUnknown(string source)
        {
            // Arrange & Act
            var type = FeedTypeUtility.GetFeedType(new PackageSource(source));

            // Assert
            Assert.Equal(FeedType.FileSystemUnknown, type);
        }
        public void FeedTypeUtility_VerifyRelativePathIsUnknown(string source)
        {
            // Arrange & Act
            var type = FeedTypeUtility.GetFeedType(new PackageSource(source));

            // Assert
            Assert.Equal(FeedType.FileSystemUnknown, type);
        }
        public void GetFeedType_WithEmptyDirectory_ReturnsFileSystemUnknown()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange & Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
        public void FeedTypeUtility_EmptyDirectoryIsUnknownType()
        {
            using (var root = TestFileSystemUtility.CreateRandomTestFolder())
            {
                // Arrange & Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
        public void FeedTypeUtility_NupkgAtRootIsV2_FileUri()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(UriUtility.CreateSourceUri(root).AbsoluteUri));

                // Assert
                Assert.Equal(FeedType.FileSystemV2, type);
            }
        }
        public void FeedTypeUtility_NupkgAtInvalidLocationIsUnknown()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a", "b", "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
            public override Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
            {
                DownloadResource resource = null;

                if ((FeedTypeUtility.GetFeedType(source.PackageSource) & FeedType.HttpV2) != FeedType.None)
                {
                    var httpSource = HttpSource.Create(source);
                    var parser     = new V2FeedParser(httpSource, source.PackageSource);

                    resource = new DownloadResourceV2FeedPrivate(parser, httpSource);
                }

                return(Task.FromResult(new Tuple <bool, INuGetResource>(resource != null, resource)));
            }
        public void FeedTypeUtility_NupkgOnlyInVersionFolderIsUnknown()
        {
            using (var root = TestFileSystemUtility.CreateRandomTestFolder())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
        public void FeedTypeUtility_NupkgAtRootIsV2()
        {
            using (var root = TestFileSystemUtility.CreateRandomTestFolder())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemV2, type);
            }
        }
        public void GetFeedType_WithNupkgOnlyInVersionFolder_ReturnsFileSystemUnknown()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
        public void GetFeedType_WithFileSystemV2LayoutAndFileUri_ReturnsFileSystemV2()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(UriUtility.CreateSourceUri(root).AbsoluteUri));

                // Assert
                Assert.Equal(FeedType.FileSystemV2, type);
            }
        }
        public void GetFeedType_WithRandomFilesInRoot_ReturnsFileSystemUnknown()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a.txt"));
                CreateFile(Path.Combine(root, "a", "a.txt"));
                CreateFile(Path.Combine(root, "a", "b", "a.txt"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
        public void FeedTypeUtility_RandomFilesInRootIsUnknownType()
        {
            using (var root = TestFileSystemUtility.CreateRandomTestFolder())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a.txt"));
                CreateFile(Path.Combine(root, "a", "a.txt"));
                CreateFile(Path.Combine(root, "a", "b", "a.txt"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemUnknown, type);
            }
        }
        public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
        {
            DependencyInfoResource DependencyInfoResourceV2 = null;

            if (FeedTypeUtility.GetFeedType(source.PackageSource) == FeedType.FileSystem)
            {
                var v2repo = await GetRepository(source, token);

                if (v2repo != null)
                {
                    DependencyInfoResourceV2 = new DependencyInfoResourceV2(v2repo, source);
                }
            }

            return(Tuple.Create <bool, INuGetResource>(DependencyInfoResourceV2 != null, DependencyInfoResourceV2));
        }
        public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
        {
            MetadataResource resource = null;

            if (FeedTypeUtility.GetFeedType(source.PackageSource) == FeedType.FileSystem)
            {
                var v2repo = await GetRepository(source, token);

                if (v2repo != null)
                {
                    resource = new MetadataResourceV2(v2repo);
                }
            }

            return(new Tuple <bool, INuGetResource>(resource != null, resource));
        }
        public void FeedTypeUtility_NupkgInVersionFolderIsV3_FileUri()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg.sha512"));
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.nuspec"));
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(UriUtility.CreateSourceUri(root).AbsoluteUri));

                // Assert
                Assert.Equal(FeedType.FileSystemV3, type);
            }
        }
        public void GetFeedType_WithBothFileSystemV2AndV3Layouts_ReturnsFileSystemV2()
        {
            using (var root = TestDirectory.Create())
            {
                // Arrange
                CreateFile(Path.Combine(root, "a.1.0.0.nupkg"));
                CreateFile(Path.Combine(root, "a", "a.1.0.0.nupkg"));
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg"));

                // Act
                var type = FeedTypeUtility.GetFeedType(new PackageSource(root));

                // Assert
                Assert.Equal(FeedType.FileSystemV2, type);
            }
        }
        public void GetFeedType_WithFileSystemV3LayoutAndFeedTypePackageSource_ReturnsFeedTypePackageSourceFeedType()
        {
            using (var root = TestDirectory.Create())
            {
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg.sha512"));
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.nuspec"));
                CreateFile(Path.Combine(root, "a", "1.0.0", "a.1.0.0.nupkg"));

                var feedTypes = new[] { FeedType.FileSystemV2, FeedType.FileSystemV3, FeedType.FileSystemUnknown };

                foreach (var expectedFeedType in feedTypes)
                {
                    var packageSource = new FeedTypePackageSource(root, expectedFeedType);

                    var actualFeedType = FeedTypeUtility.GetFeedType(packageSource);

                    Assert.Equal(expectedFeedType, actualFeedType);
                }
            }
        }
 public void GetFeedType_WithV3HttpSources_ReturnsHttpV3(string source)
 {
     Assert.Equal(FeedType.HttpV3, FeedTypeUtility.GetFeedType(new PackageSource(source)));
 }
 public void FeedTypeUtility_HttpSourcesV3(string source)
 {
     Assert.Equal(FeedType.HttpV3, FeedTypeUtility.GetFeedType(new PackageSource(source)));
 }