public async Task TestGetMissingPackagesForSolution_NoPackagesInstalled()
        {
            // Arrange
            using (var testSolutionManager = new TestSolutionManager(true))
            {
                var projectA = testSolutionManager.AddNewMSBuildProject();
                var projectB = testSolutionManager.AddNewMSBuildProject();

                var testNuGetProjectContext = new TestNuGetProjectContext();
                var token = CancellationToken.None;

                var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
                var testSettings             = Configuration.NullSettings.Instance;
                var deleteOnRestartManager   = new TestDeleteOnRestartManager();
                var packageRestoreManager    = new PackageRestoreManager(
                    sourceRepositoryProvider,
                    testSettings,
                    testSolutionManager);

                // Act
                var packagesFromSolution = (await packageRestoreManager.GetPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, token));

                Assert.False(packagesFromSolution.Any());
            }
        }
        public async Task TestPackageRestoredEvent()
        {
            // Arrange
            using (var testSolutionManager = new TestSolutionManager(true))
            {
                var projectA = testSolutionManager.AddNewMSBuildProject();
                var projectB = testSolutionManager.AddNewMSBuildProject();

                var packageIdentity          = Packages[0];
                var testNuGetProjectContext  = new TestNuGetProjectContext();
                var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
                var testSettings             = Configuration.NullSettings.Instance;
                var resolutionContext        = new ResolutionContext();
                var token = CancellationToken.None;

                var deleteOnRestartManager = new TestDeleteOnRestartManager();
                var nuGetPackageManager    = new NuGetPackageManager(
                    sourceRepositoryProvider,
                    testSettings,
                    testSolutionManager,
                    deleteOnRestartManager);

                await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity,
                                                              resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token);

                await nuGetPackageManager.InstallPackageAsync(projectB, packageIdentity,
                                                              resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token);

                var packageRestoreManager = new PackageRestoreManager(
                    sourceRepositoryProvider,
                    testSettings,
                    testSolutionManager);
                var restoredPackages = new List <PackageIdentity>();
                packageRestoreManager.PackageRestoredEvent += delegate(object sender, PackageRestoredEventArgs args)
                {
                    if (args.Restored)
                    {
                        restoredPackages.Add(args.Package);
                    }
                };

                Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(packageIdentity));

                // Delete packages folder
                TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages"));

                Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity)));

                // Act
                await packageRestoreManager.RestoreMissingPackagesInSolutionAsync(testSolutionManager.SolutionDirectory,
                                                                                  testNuGetProjectContext,
                                                                                  new TestLogger(),
                                                                                  CancellationToken.None);

                Assert.Equal(1, restoredPackages.Count);
                Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity)));
            }
        }
        public async Task TestCheckForMissingPackages()
        {
            // Arrange
            using (var testSolutionManager = new TestSolutionManager(true))
                using (var randomPackageSourcePath = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var projectA = testSolutionManager.AddNewMSBuildProject();
                    var projectB = testSolutionManager.AddNewMSBuildProject();

                    var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("1.0.0"));
                    var packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomPackageSourcePath,
                                                                                           packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
                    var testNuGetProjectContext = new TestNuGetProjectContext();
                    var token = CancellationToken.None;

                    using (var packageStream = GetDownloadResult(packageFileInfo))
                    {
                        // Act
                        await projectA.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);

                        await projectB.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);
                    }

                    var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
                    var testSettings             = Configuration.NullSettings.Instance;
                    var deleteOnRestartManager   = new TestDeleteOnRestartManager();
                    var packageRestoreManager    = new PackageRestoreManager(
                        sourceRepositoryProvider,
                        testSettings,
                        testSolutionManager);

                    var packagesMissingEventCount = 0;
                    var packagesMissing           = false;
                    packageRestoreManager.PackagesMissingStatusChanged += delegate(object sender, PackagesMissingStatusEventArgs args)
                    {
                        packagesMissingEventCount++;
                        packagesMissing = args.PackagesMissing;
                    };

                    // Act
                    await packageRestoreManager.RaisePackagesMissingEventForSolutionAsync(testSolutionManager.SolutionDirectory, token);

                    // Assert
                    Assert.Equal(1, packagesMissingEventCount);
                    Assert.False(packagesMissing);

                    // Delete packages folder
                    TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages"));

                    // Act
                    await packageRestoreManager.RaisePackagesMissingEventForSolutionAsync(testSolutionManager.SolutionDirectory, token);

                    // Assert
                    Assert.Equal(2, packagesMissingEventCount);
                    Assert.True(packagesMissing);
                }
        }
        public async Task TestGetMissingPackagesForSolution()
        {
            // Arrange
            using (var testSolutionManager = new TestSolutionManager(true))
                using (var randomPackageSourcePath = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var projectA = testSolutionManager.AddNewMSBuildProject();
                    var projectB = testSolutionManager.AddNewMSBuildProject();

                    var packageIdentity = new PackageIdentity("packageA", new NuGetVersion("1.0.0"));
                    var packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomPackageSourcePath,
                                                                                           packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
                    var testNuGetProjectContext = new TestNuGetProjectContext();
                    var token = CancellationToken.None;

                    using (var packageStream = GetDownloadResult(packageFileInfo))
                    {
                        // Act
                        await projectA.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);

                        await projectB.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);
                    }

                    var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
                    var testSettings             = Configuration.NullSettings.Instance;
                    var deleteOnRestartManager   = new TestDeleteOnRestartManager();
                    var packageRestoreManager    = new PackageRestoreManager(
                        sourceRepositoryProvider,
                        testSettings,
                        testSolutionManager);

                    // Act
                    var packagesFromSolution = (await packageRestoreManager.GetPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, token));

                    var packagesFromSolutionList        = packagesFromSolution.ToList();
                    var missingPackagesFromSolutionList = packagesFromSolution.Where(p => p.IsMissing).ToList();

                    Assert.Equal(1, packagesFromSolutionList.Count);
                    Assert.Equal(0, missingPackagesFromSolutionList.Count);

                    // Delete packages folder
                    TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages"));

                    packagesFromSolution = (await packageRestoreManager.GetPackagesInSolutionAsync(testSolutionManager.SolutionDirectory, token));

                    packagesFromSolutionList        = packagesFromSolution.ToList();
                    missingPackagesFromSolutionList = packagesFromSolution.Where(p => p.IsMissing).ToList();

                    Assert.Equal(1, missingPackagesFromSolutionList.Count);
                }
        }
Beispiel #5
0
        private CompositionContainer Initialize()
        {
            var assemblyName = Assembly.GetEntryAssembly().FullName;

            var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var catalog = new AggregateCatalog(
                new AssemblyCatalog(Assembly.Load(assemblyName)),
                new DirectoryCatalog(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "NuGet*.dll"));

            var container = new CompositionContainer(catalog);

            var settings = Settings.LoadDefaultSettings(null, null, null);

            container.ComposeExportedValue(settings);

            var sourceRepositoryProvider = new SourceRepositoryProvider(settings, Repository.Provider.GetVisualStudio());

            container.ComposeExportedValue <ISourceRepositoryProvider>(sourceRepositoryProvider);

            var testSolutionManager = new TestSolutionManager(@"c:\temp\test");
            var projectA            = testSolutionManager.AddNewMSBuildProject("projectA");

            container.ComposeExportedValue <ISolutionManager>(testSolutionManager);

            var sourceControlManager         = new TestSourceControlManager();
            var sourceControlManagerProvider = new TestSourceControlManagerProvider(sourceControlManager);

            container.ComposeExportedValue <ISourceControlManagerProvider>(sourceControlManagerProvider);

            container.ComposeParts(this);
            return(container);
        }
Beispiel #6
0
        public async Task TestGetMissingPackagesForSolution()
        {
            // Arrange
            var testSolutionManager = new TestSolutionManager();
            var projectA            = testSolutionManager.AddNewMSBuildProject();
            var projectB            = testSolutionManager.AddNewMSBuildProject();

            var packageIdentity         = new PackageIdentity("packageA", new NuGetVersion("1.0.0"));
            var randomPackageSourcePath = TestFilesystemUtility.CreateRandomTestFolder();
            var packageFileInfo         = TestPackages.GetLegacyTestPackage(randomPackageSourcePath,
                                                                            packageIdentity.Id, packageIdentity.Version.ToNormalizedString());
            var testNuGetProjectContext = new TestNuGetProjectContext();
            var token = CancellationToken.None;

            using (var packageStream = packageFileInfo.OpenRead())
            {
                // Act
                await projectA.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);

                await projectB.InstallPackageAsync(packageIdentity, packageStream, testNuGetProjectContext, token);
            }

            var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
            var testSettings             = NullSettings.Instance;
            var packageRestoreManager    = new PackageRestoreManager(sourceRepositoryProvider, testSettings, testSolutionManager);

            // Act
            var packageReferencesFromSolution = (await packageRestoreManager.GetPackageReferencesFromSolution(token)).ToList();
            var missingPackagesFromSolution   = (await packageRestoreManager.GetMissingPackagesInSolution(token)).ToList();

            Assert.Equal(2, packageReferencesFromSolution.Count);
            Assert.Equal(0, missingPackagesFromSolution.Count);

            // Delete packages folder
            Directory.Delete(Path.Combine(testSolutionManager.SolutionDirectory, "packages"), recursive: true);

            packageReferencesFromSolution = (await packageRestoreManager.GetPackageReferencesFromSolution(token)).ToList();
            missingPackagesFromSolution   = (await packageRestoreManager.GetMissingPackagesInSolution(token)).ToList();
            Assert.Equal(2, packageReferencesFromSolution.Count);
            Assert.Equal(1, missingPackagesFromSolution.Count);
        }
        public async Task InstallingPackageShouldCreateLockFile_CustomLockFileName()
        {
            // Arrange
            using (var packageSource = TestDirectory.Create())
                using (var testSolutionManager = new TestSolutionManager())
                {
                    var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(
                        new List <PackageSource>()
                    {
                        new PackageSource(packageSource.Path)
                    });

                    var testSettings           = NullSettings.Instance;
                    var token                  = CancellationToken.None;
                    var deleteOnRestartManager = new TestDeleteOnRestartManager();
                    var nuGetPackageManager    = new NuGetPackageManager(
                        sourceRepositoryProvider,
                        testSettings,
                        testSolutionManager,
                        deleteOnRestartManager);
                    var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings);

                    var packageContext = new SimpleTestPackageContext("packageA");
                    packageContext.AddFile("lib/net45/a.dll");
                    SimpleTestPackageUtility.CreateOPCPackage(packageContext, packageSource);

                    var msBuildNuGetProject       = testSolutionManager.AddNewMSBuildProject();
                    var msBuildNuGetProjectSystem = msBuildNuGetProject.ProjectSystem as TestMSBuildNuGetProjectSystem;
                    msBuildNuGetProjectSystem.SetPropertyValue("RestorePackagesWithLockFile", "true");
                    msBuildNuGetProjectSystem.SetPropertyValue("NuGetLockFilePath", "my.lock.json");
                    var packagesConfigPath = msBuildNuGetProject.PackagesConfigNuGetProject.FullPath;
                    var packagesLockPath   = packagesConfigPath.Replace("packages.config", "my.lock.json");
                    var packageIdentity    = packageContext.Identity;

                    // Pre-Assert
                    // Check that the packages.lock.json file does not exist
                    Assert.False(File.Exists(packagesLockPath));

                    // Act
                    await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity,
                                                                  new ResolutionContext(), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token);

                    // Assert
                    // Check that the packages.lock.json file exists after the installation
                    Assert.True(File.Exists(packagesLockPath));
                    Assert.True(msBuildNuGetProjectSystem.FileExistsInProject("my.lock.json"));
                    // Check the number of target frameworks and dependencies in the lock file
                    var lockFile = PackagesLockFileFormat.Read(packagesLockPath);
                    Assert.Equal(1, lockFile.Targets.Count);
                    Assert.Equal(1, lockFile.Targets[0].Dependencies.Count);
                }
        }
        private void CreatePackageManagerControl()
        {
            _container = Initialize();

            this.Title = "NuGet Standalone UI";
            Height     = 800;
            Width      = 1000;

            var repositoryProvider = new SourceRepositoryProvider(_settings, Repository.Provider.GetVisualStudio());
            var settings           = new DefaultSettings();

            var testSolutionManager = new TestSolutionManager(@"c:\temp\test");

            var projectA = testSolutionManager.AddNewMSBuildProject("projectA");
            var projectB = testSolutionManager.AddNewMSBuildProject("projectB");
            //var projectC = testSolutionManager.AddProjectKProject("projectK");

            var projects = new NuGetProject[] { projectA, projectB };

            var packageRestoreManager = new PackageRestoreManager(repositoryProvider, settings, testSolutionManager);
            var contextFactory        = new StandaloneUIContextFactory(
                repositoryProvider,
                testSolutionManager,
                settings,
                packageRestoreManager: packageRestoreManager,
                optionsPage: null);
            var context      = contextFactory.Create(@"c:\temp\test\settings.txt", projects);
            var uiController = _uiServiceFactory.Create(
                context,
                new NuGetUIProjectContext(new StandaloneUILogger(_textBox, _scrollViewer), _sourceControlManagerProvider, _commonOperations));

            PackageManagerModel model = new PackageManagerModel(uiController, context);

            model.SolutionName     = "test solution";
            _packageManagerControl = new PackageManagerControl(model, _settings);
            layoutGrid.Children.Add(_packageManagerControl);
        }
Beispiel #9
0
        private void CreatePackageManagerControl()
        {
            _container = Initialize();

            // This method is called from MainWindow's constructor. Current thread is the main thread
            var mainThread             = Thread.CurrentThread;
            var synchronizationContext = SynchronizationContext.Current;

            NuGetUIThreadHelper.SetCustomJoinableTaskFactory(mainThread, synchronizationContext);

            Title  = "NuGet Standalone UI";
            Height = 800;
            Width  = 1000;

            var repositoryProvider = new SourceRepositoryProvider(_settings, Repository.Provider.GetVisualStudio());
            var settings           = new DefaultSettings();

            var testSolutionManager = new TestSolutionManager(@"c:\temp\test");

            var projectA = testSolutionManager.AddNewMSBuildProject("projectA");
            //var projectB = testSolutionManager.AddNewMSBuildProject("projectB");
            //var projectC = testSolutionManager.AddProjectKProject("projectK");
            var projectBuildIntegrated = testSolutionManager.AddBuildIntegratedProject("BuildIntProj", NuGetFramework.Parse("net46"));

            var projects = new[] { projectBuildIntegrated };

            var packageRestoreManager = new PackageRestoreManager(
                repositoryProvider,
                settings,
                testSolutionManager);

            var contextFactory = new StandaloneUIContextFactory(
                repositoryProvider,
                testSolutionManager,
                settings,
                packageRestoreManager: packageRestoreManager,
                optionsPage: null);
            var context      = contextFactory.Create(@"c:\temp\test\settings.txt", projects);
            var uiController = _uiServiceFactory.Create(
                context,
                new NuGetUIProjectContext(new StandaloneUILogger(_textBox, _scrollViewer), _sourceControlManagerProvider, _commonOperations));

            var model = new PackageManagerModel(uiController, context, isSolution: false, editorFactoryGuid: Guid.Empty);

            model.SolutionName     = "test solution";
            _packageManagerControl =
                new PackageManagerControl(model, _settings, new SimpleSearchBoxFactory(), vsShell: null);
            layoutGrid.Children.Add(_packageManagerControl);
        }
Beispiel #10
0
        public async Task TestRestoreMissingPackages()
        {
            // Arrange
            var testSolutionManager = new TestSolutionManager();
            var projectA            = testSolutionManager.AddNewMSBuildProject();
            var projectB            = testSolutionManager.AddNewMSBuildProject();

            var packageIdentity          = Packages[0];
            var testNuGetProjectContext  = new TestNuGetProjectContext();
            var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
            var testSettings             = NullSettings.Instance;
            var resolutionContext        = new ResolutionContext();
            var token = CancellationToken.None;

            var nuGetPackageManager = new NuGetPackageManager(sourceRepositoryProvider, testSettings, testSolutionManager);

            await nuGetPackageManager.InstallPackageAsync(projectA, packageIdentity,
                                                          resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token);

            await nuGetPackageManager.InstallPackageAsync(projectB, packageIdentity,
                                                          resolutionContext, new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token);

            var packageRestoreManager = new PackageRestoreManager(sourceRepositoryProvider, testSettings, testSolutionManager);

            Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(packageIdentity));

            // Delete packages folder
            Directory.Delete(Path.Combine(testSolutionManager.SolutionDirectory, "packages"), recursive: true);

            Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity)));

            // Act
            await packageRestoreManager.RestoreMissingPackagesInSolutionAsync(CancellationToken.None);

            Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity)));
        }
        public async Task DoNotCreateLockFileWhenFeatureDisabled()
        {
            // Arrange
            using (var packageSource = TestDirectory.Create())
                using (var testSolutionManager = new TestSolutionManager())
                {
                    var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateSourceRepositoryProvider(
                        new List <PackageSource>()
                    {
                        new PackageSource(packageSource.Path)
                    });

                    var testSettings           = NullSettings.Instance;
                    var token                  = CancellationToken.None;
                    var deleteOnRestartManager = new TestDeleteOnRestartManager();
                    var nuGetPackageManager    = new NuGetPackageManager(
                        sourceRepositoryProvider,
                        testSettings,
                        testSolutionManager,
                        deleteOnRestartManager);
                    var packagesFolderPath = PackagesFolderPathUtility.GetPackagesFolderPath(testSolutionManager, testSettings);

                    var packageContext = new SimpleTestPackageContext("packageA");
                    packageContext.AddFile("lib/net45/a.dll");
                    SimpleTestPackageUtility.CreateOPCPackage(packageContext, packageSource);

                    var msBuildNuGetProject       = testSolutionManager.AddNewMSBuildProject();
                    var msBuildNuGetProjectSystem = msBuildNuGetProject.ProjectSystem as TestMSBuildNuGetProjectSystem;
                    msBuildNuGetProjectSystem.SetPropertyValue("RestorePackagesWithLockFile", "false");
                    var packagesConfigPath = msBuildNuGetProject.PackagesConfigNuGetProject.FullPath;
                    var packagesLockPath   = packagesConfigPath.Replace("packages.config", "packages.lock.json");
                    var packageIdentity    = packageContext.Identity;

                    // Pre-Assert
                    // Check that the packages.lock.json file does not exist
                    Assert.False(File.Exists(packagesLockPath));

                    // Act
                    await nuGetPackageManager.InstallPackageAsync(msBuildNuGetProject, packageIdentity,
                                                                  new ResolutionContext(), new TestNuGetProjectContext(), sourceRepositoryProvider.GetRepositories().First(), null, token);

                    // Assert
                    // Check that the packages.lock.json still does not exist after the installation
                    Assert.False(File.Exists(packagesLockPath));
                }
        }
        public async Task Test_PackageRestoreFailure_WithRaisedEvents()
        {
            // Arrange
            using (var testSolutionManager = new TestSolutionManager(true))
                using (var randomTestPackageSourcePath = TestFileSystemUtility.CreateRandomTestFolder())
                {
                    var projectA = testSolutionManager.AddNewMSBuildProject("projectA");
                    var projectB = testSolutionManager.AddNewMSBuildProject("projectB");
                    var projectC = testSolutionManager.AddNewMSBuildProject("projectC");

                    var jQuery144                = Packages[0];
                    var jQueryValidation         = Packages[2];
                    var testNuGetProjectContext  = new TestNuGetProjectContext();
                    var sourceRepositoryProvider = TestSourceRepositoryUtility.CreateV3OnlySourceRepositoryProvider();
                    var testSettings             = Configuration.NullSettings.Instance;
                    var resolutionContext        = new ResolutionContext();
                    var token = CancellationToken.None;

                    var deleteOnRestartManager = new TestDeleteOnRestartManager();
                    var nuGetPackageManager    = new NuGetPackageManager(
                        sourceRepositoryProvider,
                        testSettings,
                        testSolutionManager,
                        deleteOnRestartManager);

                    await nuGetPackageManager.InstallPackageAsync(projectA, jQueryValidation,
                                                                  resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token);

                    await nuGetPackageManager.InstallPackageAsync(projectB, jQueryValidation,
                                                                  resolutionContext, testNuGetProjectContext, sourceRepositoryProvider.GetRepositories().First(), null, token);

                    var testPackage1 = new PackageIdentity("package1A", new NuGetVersion("1.0.0"));
                    var testPackage2 = new PackageIdentity("package1B", new NuGetVersion("1.0.0"));

                    var packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomTestPackageSourcePath,
                                                                                           testPackage1.Id, testPackage1.Version.ToNormalizedString());
                    using (var packageStream = GetDownloadResult(packageFileInfo))
                    {
                        // Act
                        await projectB.InstallPackageAsync(testPackage1, packageStream, testNuGetProjectContext, token);

                        await projectC.InstallPackageAsync(testPackage1, packageStream, testNuGetProjectContext, token);
                    }

                    packageFileInfo = TestPackagesGroupedByFolder.GetLegacyTestPackage(randomTestPackageSourcePath,
                                                                                       testPackage2.Id, testPackage2.Version.ToNormalizedString());
                    using (var packageStream = GetDownloadResult(packageFileInfo))
                    {
                        // Act
                        await projectA.InstallPackageAsync(testPackage2, packageStream, testNuGetProjectContext, token);

                        await projectC.InstallPackageAsync(testPackage2, packageStream, testNuGetProjectContext, token);
                    }

                    var packageRestoreManager = new PackageRestoreManager(
                        sourceRepositoryProvider,
                        testSettings,
                        testSolutionManager);
                    var restoredPackages = new List <PackageIdentity>();
                    packageRestoreManager.PackageRestoredEvent += delegate(object sender, PackageRestoredEventArgs args) { restoredPackages.Add(args.Package); };

                    var restoreFailedPackages = new ConcurrentDictionary <Packaging.PackageReference, IEnumerable <string> >(new PackageReferenceComparer());
                    packageRestoreManager.PackageRestoreFailedEvent += delegate(object sender, PackageRestoreFailedEventArgs args)
                    {
                        restoreFailedPackages.AddOrUpdate(args.RestoreFailedPackageReference,
                                                          args.ProjectNames,
                                                          (Packaging.PackageReference packageReference, IEnumerable <string> oldValue) => { return(oldValue); });
                    };

                    Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(jQueryValidation));

                    // Delete packages folder
                    TestFileSystemUtility.DeleteRandomTestFolder(Path.Combine(testSolutionManager.SolutionDirectory, "packages"));

                    Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(jQuery144));
                    Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(jQueryValidation));
                    Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage1));
                    Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage2));

                    // Act
                    await packageRestoreManager.RestoreMissingPackagesInSolutionAsync(testSolutionManager.SolutionDirectory,
                                                                                      testNuGetProjectContext,
                                                                                      CancellationToken.None);

                    // Assert
                    Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(jQuery144));
                    Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder(jQueryValidation));
                    Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage1));
                    Assert.False(nuGetPackageManager.PackageExistsInPackagesFolder(testPackage2));

                    Assert.Equal(4, restoredPackages.Count);
                    // The ordering is not guaranteed and can vary. Do not assert based on that
                    Assert.True(restoredPackages.Contains(jQuery144));
                    Assert.True(restoredPackages.Contains(jQueryValidation));
                    Assert.True(restoredPackages.Contains(testPackage1));
                    Assert.True(restoredPackages.Contains(testPackage2));

                    Assert.Equal(2, restoreFailedPackages.Count);

                    // The ordering is not guaranteed and can vary. Do not assert based on that
                    var restoreFailedPackageKeys = restoreFailedPackages.Keys;
                    var testPackage1Key          = restoreFailedPackageKeys.Where(r => r.PackageIdentity.Equals(testPackage1)).First();
                    var testPackage1ProjectNames = restoreFailedPackages[testPackage1Key].ToList();

                    Assert.Equal(2, testPackage1ProjectNames.Count);
                    Assert.True(testPackage1ProjectNames.Contains("projectB", StringComparer.OrdinalIgnoreCase));
                    Assert.True(testPackage1ProjectNames.Contains("projectC", StringComparer.OrdinalIgnoreCase));

                    var testPackage2Key          = restoreFailedPackageKeys.Where(r => r.PackageIdentity.Equals(testPackage2)).First();
                    var testPackage2ProjectNames = restoreFailedPackages[testPackage2Key].ToList();

                    Assert.Equal(2, testPackage2ProjectNames.Count);
                    Assert.True(testPackage2ProjectNames.Contains("projectA", StringComparer.OrdinalIgnoreCase));
                    Assert.True(testPackage2ProjectNames.Contains("projectC", StringComparer.OrdinalIgnoreCase));
                }
        }