Beispiel #1
0
        public void FilterDependencyProvidersForLibrary_WhenPackagePatternToSourceMappingIsNotConfiguredReturnsNoProviders_Success()
        {
            var logger = new TestLogger();

            //package source mapping configuration
            Dictionary <string, IReadOnlyList <string> > patterns = new();

            patterns.Add("Source1", new List <string>()
            {
                "y"
            });
            patterns.Add("Source2", new List <string>()
            {
                "z"
            });
            PackageSourceMapping sourceMappingConfiguration = new(patterns);

            var context = new TestRemoteWalkContext(sourceMappingConfiguration, logger);

            // Source1
            var remoteProvider1 = CreateRemoteDependencyProvider("Source1");

            context.RemoteLibraryProviders.Add(remoteProvider1.Object);

            // Source2
            var remoteProvider2 = CreateRemoteDependencyProvider("Source2");

            context.RemoteLibraryProviders.Add(remoteProvider2.Object);

            var libraryRange = new LibraryRange("x", Versioning.VersionRange.None, LibraryDependencyTarget.Package);

            IList <IRemoteDependencyProvider> providers = context.FilterDependencyProvidersForLibrary(libraryRange);

            Assert.Empty(providers);
        }
Beispiel #2
0
        public void FilterDependencyProvidersForLibrary_WhenPackageSourceMappingIsEnabledReturnsOnlyApplicableProviders_Success()
        {
            //package source mapping configuration
            Dictionary <string, IReadOnlyList <string> > patterns = new();

            patterns.Add("Source1", new List <string>()
            {
                "x"
            });
            patterns.Add("Source2", new List <string>()
            {
                "y"
            });
            PackageSourceMapping sourceMappingConfiguration = new(patterns);

            var context = new TestRemoteWalkContext(sourceMappingConfiguration, NullLogger.Instance);

            // Source1
            var remoteProvider1 = CreateRemoteDependencyProvider("Source1");

            context.RemoteLibraryProviders.Add(remoteProvider1.Object);

            // Source2
            var remoteProvider2 = CreateRemoteDependencyProvider("Source2");

            context.RemoteLibraryProviders.Add(remoteProvider2.Object);

            var libraryRange = new LibraryRange("x", Versioning.VersionRange.None, LibraryDependencyTarget.Package);

            IList <IRemoteDependencyProvider> providers = context.FilterDependencyProvidersForLibrary(libraryRange);

            Assert.Equal(1, providers.Count);
            Assert.Equal("Source1", providers[0].Source.Name);
        }
Beispiel #3
0
        public async Task SlowerFeedWinsIfBetterMatchExists()
        {
            // A
            var slowProvider = new TestProvider(TimeSpan.FromSeconds(2));

            slowProvider.AddLibrary(new LibraryIdentity
            {
                Name    = "A",
                Version = new NuGetVersion("1.0.0")
            });

            var fastProvider = new TestProvider(TimeSpan.Zero);

            fastProvider.AddLibrary(new LibraryIdentity
            {
                Name    = "A",
                Version = new NuGetVersion("1.1.0")
            });

            var context = new TestRemoteWalkContext();

            context.RemoteLibraryProviders.Add(slowProvider);
            context.RemoteLibraryProviders.Add(fastProvider);

            var walker = new RemoteDependencyWalker(context);
            var result = await walker.WalkAsync(new LibraryRange
            {
                Name         = "A",
                VersionRange = VersionRange.Parse("1.0.0"),
            },
                                                NuGetFramework.Parse("net45"),
                                                runtimeIdentifier : null,
                                                runtimeGraph : null,
                                                recursive : true);

            Assert.NotNull(result.Item.Data.Match);
            Assert.NotNull(result.Item.Data.Match.Library);
            Assert.Equal("A", result.Item.Data.Match.Library.Name);
            Assert.Equal(new NuGetVersion("1.0.0"), result.Item.Data.Match.Library.Version);
            Assert.Equal(slowProvider, result.Item.Data.Match.Provider);
        }
Beispiel #4
0
        public void FilterDependencyProvidersForLibrary_WhenPackageSourceMappingIsNotEnabledReturnsAllProviders_Success()
        {
            var context = new TestRemoteWalkContext();

            // Source1
            var remoteProvider1 = CreateRemoteDependencyProvider("Source1");

            context.RemoteLibraryProviders.Add(remoteProvider1.Object);

            // Source2
            var remoteProvider2 = CreateRemoteDependencyProvider("Source2");

            context.RemoteLibraryProviders.Add(remoteProvider2.Object);

            var libraryRange = new LibraryRange("packageA", Versioning.VersionRange.None, LibraryDependencyTarget.Package);

            IList <IRemoteDependencyProvider> providers = context.FilterDependencyProvidersForLibrary(libraryRange);

            Assert.Equal(2, providers.Count);
            Assert.Equal(context.RemoteLibraryProviders, providers);
        }
Beispiel #5
0
        public void FilterDependencyProvidersForLibrary_WhenLibraryRangeIsNull_Throws()
        {
            var context = new TestRemoteWalkContext();

            Assert.Throws <ArgumentNullException>(() => context.FilterDependencyProvidersForLibrary(libraryRange: null));
        }