public MonoDevelopPackageRestoreManager (IMonoDevelopSolutionManager solutionManager)
		{
			restoreManager = new PackageRestoreManager (
				solutionManager.CreateSourceRepositoryProvider (),
				solutionManager.Settings,
				solutionManager);
		}
		public RestoreNuGetPackagesInProjectAction (
			DotNetProject project,
			NuGetProject nugetProject,
			IMonoDevelopSolutionManager solutionManager)
		{
			this.project = project;
			this.nugetProject = nugetProject;
			this.solutionManager = solutionManager;

			packageManagementEvents = PackageManagementServices.PackageManagementEvents;

			restoreManager = new PackageRestoreManager (
				solutionManager.CreateSourceRepositoryProvider (),
				solutionManager.Settings,
				solutionManager
			);
		}
        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);
        }
        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);
        }
        public async Task TestPackageRestoredEvent()
        {
            // 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);
            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
            Directory.Delete(Path.Combine(testSolutionManager.SolutionDirectory, "packages"), recursive: true);

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

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

            Assert.Equal(1, restoredPackages.Count);
            Assert.True(nuGetPackageManager.PackageExistsInPackagesFolder((packageIdentity)));
        }
        public async Task TestCheckForMissingPackages()
        {
            // 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);

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

            // Act
            await packageRestoreManager.RaisePackagesMissingEventForSolution(token);

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

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

            // Act
            await packageRestoreManager.RaisePackagesMissingEventForSolution(token);

            // Assert
            Assert.Equal(2, packagesMissingEventCount);
            Assert.True(packagesMissing);
        }