public void SaveTo()
 {
     var fileSystem = new Mock<MockFileSystem>(){CallBase = true};
     _packageAggregator = new PackageAggregator(fileSystem.Object, _repositoryManager, new PackageEnumerator());
     FileInfo file = _packageAggregator.Save(@".");
     Assert.IsTrue(fileSystem.Object.Paths.ContainsKey(file.ToString()));
 }
 public void ConstructorTest()
 {
     var fileSystem = new Mock<MockFileSystem>();
     _packageAggregator = new PackageAggregator(fileSystem.Object, _repositoryManager, new PackageEnumerator());
     Assert.AreSame(_repositoryManager, _packageAggregator.RepositoryManager);
     Assert.IsNotNull(_packageAggregator.Packages);
 }
 public void AggregateCount(int expectedCanResolveCount, int expectedCannotResolveCount)
 {
     var fileSystem = new Mock<MockFileSystem>();
     _packageAggregator = new PackageAggregator(fileSystem.Object, _repositoryManager, new PackageEnumerator());
     _packageAggregator.Compute((s, s1) => { }, PackageReferenceEqualityComparer.Id, new PackageReferenceSetResolver());
     Assert.AreEqual(expectedCanResolveCount, _packageAggregator.Packages.Count());
     Assert.AreEqual(expectedCannotResolveCount, _packageAggregator.PackageResolveFailures.Count());
 }
Пример #4
0
 /// <summary>
 /// Logs all package constraint satisfaction errors.
 /// </summary>
 /// <param name="repositoryGroupManager">The repository group manager.</param>
 /// <param name="packageAggregator">The package aggregator.</param>
 private void LogAllPackageConstraintSatisfactionErrors(RepositoryGroupManager repositoryGroupManager, PackageAggregator packageAggregator)
 {
     //HACK #UGLY #WTF There must be a better way....
     foreach (var p in packageAggregator.PackageResolveFailures)
     {
         foreach (var rp in repositoryGroupManager.RepositoryManagers)
         {
             foreach (var prf in rp.PackageReferenceFiles)
             {
                 if (prf.GetPackageReferences().Contains(p))
                 {
                     LogSatisfactionFailure(p, prf);
                 }
             }
         }
     }
 }
Пример #5
0
        private void GetByDirectoryPath(IFileSystem baseFileSystem, string target)
        {
            if (baseFileSystem.DirectoryExists(target))
            {
                var repositoryGroupManager = new RepositoryGroupManager(target, baseFileSystem);
                var repositoryManagers = new ConcurrentBag<RepositoryManager>(repositoryGroupManager.RepositoryManagers);

                var totalTime = new Stopwatch();
                totalTime.Start();

                int totalPackageUpdates = 0;

                bool exitWithFailure = false;
                Array.ForEach(repositoryManagers.ToArray(), (repositoryManager) =>
                    {
                        string packagesConfigDiretory = null;

                        if (repositoryManager.RepositoryConfig.Directory != null)
                            packagesConfigDiretory = repositoryManager.RepositoryConfig.Directory.FullName;
                        
                        using (var packageAggregator = new PackageAggregator(baseFileSystem, repositoryManager, new PackageEnumerator()))
                        {
                            packageAggregator.Compute((min, max) =>
                                {
                                    totalPackageUpdates += Convert.ToInt16(min);
                                    Console.WriteLine("Getting {0} distinct packages from a total of {1} from {2}",min, max,repositoryManager.RepositoryConfig.FullName);
                                },
                                Latest ? PackageReferenceEqualityComparer.IdAndAllowedVersions : PackageReferenceEqualityComparer.IdVersionAndAllowedVersions , new PackageReferenceSetResolver());

                            if (packageAggregator.PackageResolveFailures.Any())
                            {
                                LogAllPackageConstraintSatisfactionErrors(repositoryGroupManager, packageAggregator);
                                exitWithFailure = true;
                            }
                            else
                            {
                                var tempPackageConfig = packageAggregator.Save(packagesConfigDiretory);
                                InstallPackagesFromConfigFile(packagesConfigDiretory, GetPackageReferenceFile(baseFileSystem, tempPackageConfig.FullName), target);
                            }
                        }
                    });

                totalTime.Stop();

                if (exitWithFailure)
                {
                    var errorMessage = string.Format("Failed : {0} package directories, {1} packages in {2} seconds",
                                                     repositoryManagers.Count, totalPackageUpdates,
                                                     totalTime.Elapsed.TotalSeconds);
                    throw new CommandLineException(errorMessage);
                }

                Console.WriteLine(string.Format("Updated : {0} package directories, {1} packages in {2} seconds",
                                                    repositoryManagers.Count, totalPackageUpdates,
                                                    totalTime.Elapsed.TotalSeconds));
            }
        }