public void CachedPackageSourceProviderReadsEnabledSourceValues()
        {
            // Arrange
            var sourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            var sourceA = new PackageSource("SourceA", "SourceA", isEnabled: false);
            var sourceB = new PackageSource("SourceB", "Source B");
            sourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { sourceA, sourceB });

            // Act
            var cachedPackageSource = new CachedPackageSourceProvider(sourceProvider.Object);
            var result = cachedPackageSource.GetEnabledPackageSources().ToList();

            // Assert
            Assert.Equal(new[] { sourceB }, result);
        }
Esempio n. 2
0
        public void CachedPackageSourceProviderReadsEnabledSourceValues()
        {
            // Arrange
            var sourceProvider = new Mock <IPackageSourceProvider>(MockBehavior.Strict);
            var sourceA        = new PackageSource("SourceA", "SourceA", isEnabled: false);
            var sourceB        = new PackageSource("SourceB", "Source B");

            sourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { sourceA, sourceB });

            // Act
            var cachedPackageSource = new CachedPackageSourceProvider(sourceProvider.Object);
            var result = cachedPackageSource.GetEnabledPackageSources().ToList();

            // Assert
            Assert.Equal(new[] { sourceB }, result);
        }
        public void CachedPackageSourceProviderReadsCredentials()
        {
            // Arrange
            var sourceProvider = new Mock<IPackageSourceProvider>(MockBehavior.Strict);
            var sourceA = new PackageSource("SourceA") { UserName = "******", Password = "******" };
            var sourceB = new PackageSource("SourceB", "Source B", isEnabled: false);

            sourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { sourceA, sourceB });

            // Act
            var cachedPackageSource = new CachedPackageSourceProvider(sourceProvider.Object);
            var result = cachedPackageSource.GetEnabledPackageSources().First();

            // Assert
            Assert.Equal("Username", result.UserName);
            Assert.Equal("password", result.Password);
        }
Esempio n. 4
0
        public void CachedPackageSourceProviderReadsCredentials()
        {
            // Arrange
            var sourceProvider = new Mock <IPackageSourceProvider>(MockBehavior.Strict);
            var sourceA        = new PackageSource("SourceA")
            {
                UserName = "******", Password = "******"
            };
            var sourceB = new PackageSource("SourceB", "Source B", isEnabled: false);

            sourceProvider.Setup(s => s.LoadPackageSources()).Returns(new[] { sourceA, sourceB });

            // Act
            var cachedPackageSource = new CachedPackageSourceProvider(sourceProvider.Object);
            var result = cachedPackageSource.GetEnabledPackageSources().First();

            // Assert
            Assert.Equal("Username", result.UserName);
            Assert.Equal("password", result.Password);
        }
Esempio n. 5
0
        /// <returns>True if one or more packages are installed.</returns>
        private bool ExecuteInParallel(IFileSystem fileSystem, ICollection<PackageReference> packageReferences)
        {
            bool packageRestoreConsent = new PackageRestoreConsent(Settings).IsGranted;
            int defaultConnectionLimit = ServicePointManager.DefaultConnectionLimit;
            if (packageReferences.Count > defaultConnectionLimit)
            {
                ServicePointManager.DefaultConnectionLimit = Math.Min(10, packageReferences.Count);
            }

            // The PackageSourceProvider reads from the underlying ISettings multiple times. One of the fields it reads is the password which is consequently decrypted
            // once for each package being installed. Per work item 2345, a couple of users are running into an issue where this results in an exception in native 
            // code. Instead, we'll use a cached set of sources. This should solve the issue and also give us some perf boost.
            SourceProvider = new CachedPackageSourceProvider(SourceProvider);

            var satellitePackages = new List<IPackage>();

            if (DisableParallelProcessing)
            {
                foreach (var package in packageReferences)
                {
                    RestorePackage(fileSystem, package.Id, package.Version, packageRestoreConsent, satellitePackages);
                }

                return true;
            }

            var tasks = packageReferences.Select(package =>
                            Task.Factory.StartNew(() => RestorePackage(fileSystem, package.Id, package.Version, packageRestoreConsent, satellitePackages))).ToArray();

            Task.WaitAll(tasks);
            // Return true if we installed any satellite packages or if any of our install tasks succeeded.
            return InstallSatellitePackages(fileSystem, satellitePackages) ||
                   tasks.All(p => !p.IsFaulted && p.Result);
        }