Inheritance: IVsExtension, INotifyPropertyChanged
Example #1
0
        public override bool CanExecute(PackageItem item)
        {
            IPackage package = item.PackageIdentity;
            if (package == null)
            {
                return false;
            }
            // only enable command on a Package in the Update provider if it not updated yet.

            // the specified package can be updated if the local repository contains a package 
            // with matching id and smaller version number.

            // Optimization due to bug #2008: if the LocalRepository is backed by a packages.config file, 
            // check the packages information directly from the file, instead of going through
            // the IPackageRepository interface, which could potentially connect to TFS.
            var packageLookup = LocalRepository as ILatestPackageLookup;
            if (packageLookup != null)
            {
                SemanticVersion localPackageVersion; 
                return packageLookup.TryFindLatestPackageById(item.Id, out localPackageVersion) &&
                       localPackageVersion < package.Version;
            }
            
            return LocalRepository.GetPackages().Any(
                p => p.Id.Equals(package.Id, StringComparison.OrdinalIgnoreCase) && p.Version < package.Version);
        }
Example #2
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Local repository contains Package A and Package B
            // We test the CanExecute() method on Package A and Package C

            // Arrange
            var repository = new MockPackageRepository();

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            repository.AddPackage(packageA);

            var packageB = PackageUtility.CreatePackage("B", "2.0");
            repository.AddPackage(packageB);

            var packageC = PackageUtility.CreatePackage("C", "2.0");

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => repository.Exists(p));

            var provider = CreateInstalledProvider(null, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteA);
            Assert.IsFalse(canExecuteC);
        }
Example #3
0
        public override bool CanExecute(PackageItem item)
        {
            IPackage package = item.PackageIdentity;
            if (package == null) {
                return false;
            }
            // only enable command on a Package in the Update provider if it not updated yet.

            // the specified package can be updated if the local repository contains a package
            // with matching id and smaller version number.
            return ProjectManager.LocalRepository.GetPackages().Any(
                p => p.Id.Equals(package.Id, StringComparison.OrdinalIgnoreCase) && p.Version < package.Version);
        }
Example #4
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Local repository contains Package A 1.0 and Package B
            // Source repository contains Package A 2.0 and Package C

            var packageA1 = PackageUtility.CreatePackage("A", "1.0");
            var packageA2 = PackageUtility.CreatePackage("A", "2.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            // Arrange
            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageA1);
            localRepository.AddPackage(packageB);

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA2);
            sourceRepository.AddPackage(packageC);

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.LocalRepository).Returns(localRepository);

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);

            var provider = CreateUpdatesProvider(packageManager.Object, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA2, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteA);
            Assert.IsFalse(canExecuteC);
        }
Example #5
0
        public void CanExecuteReturnsCorrectResult()
        {
            // Arrange

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageA);

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);

            var provider = CreateOnlineProvider(packageManager.Object, projectManager.Object);

            var extensionA = new PackageItem(provider, packageA, null);
            var extensionB = new PackageItem(provider, packageB, null);
            var extensionC = new PackageItem(provider, packageC, null);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteB = provider.CanExecute(extensionB);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.IsTrue(canExecuteC);
            Assert.IsTrue(canExecuteB);
            Assert.IsFalse(canExecuteA);
        }
 public override bool CanExecute(PackageItem item)
 {
     return(_baseProvider.CanExecute(item));
 }
Example #7
0
 protected virtual void ExecuteCommand(IProjectManager projectManager, PackageItem item, IVsPackageManager activePackageManager, IList <PackageOperation> operations)
 {
     activePackageManager.InstallPackage(projectManager, item.PackageIdentity, operations, ignoreDependencies: false, allowPrereleaseVersions: IncludePrerelease, logger: this);
 }
Example #8
0
 /// <summary>
 /// This method is called on background thread.
 /// </summary>
 /// <returns><c>true</c> if the method succeeded. <c>false</c> otherwise.</returns>
 protected virtual bool ExecuteCore(PackageItem item)
 {
     return true;
 }
        public void ExecuteMethodInvokesUninstallScriptWhenThePackageContainsOne()
        {
            // Arrange
            var repository = new MockPackageRepository();

            var packageA = PackageUtility.CreatePackage("A", "1.0", tools: new string[] { "uninstall.ps1" });
            repository.AddPackage(packageA);

            var projectManager = CreateProjectManager(repository);

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.UninstallPackage(
                projectManager, It.IsAny<string>(), It.IsAny<SemanticVersion>(), false, false, It.IsAny<ILogger>())).Callback(
                () => projectManager.RemovePackageReference("A"));
            packageManager.Setup(p => p.GetProjectManager(It.IsAny<Project>())).Returns(projectManager);


            var project = new Mock<Project>();
            var scriptExecutor = new Mock<IScriptExecutor>();

            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.GetProject(It.IsAny<string>())).Returns(project.Object);

            var provider = CreateInstalledProvider(packageManager.Object, null, project.Object, scriptExecutor.Object, solutionManager.Object);

            var extensionA = new PackageItem(provider, packageA);

            var mockLicenseWindowOpener = new Mock<IUserNotifierServices>();

            var manualEvent = new ManualResetEventSlim(false);

            provider.ExecuteCompletedCallback = () =>
            {
                try
                {
                    // Assert
                    scriptExecutor.Verify(p => p.Execute(It.IsAny<string>(), "uninstall.ps1", packageA, project.Object, It.IsAny<FrameworkName>(), It.IsAny<ILogger>()), Times.Once());
                }
                finally
                {
                    manualEvent.Set();
                }
            };

            // Act
            provider.Execute(extensionA);

            manualEvent.Wait();
        }
 public override bool CanExecute(PackageItem item)
 {
     return true;
 }
Example #11
0
        protected override bool ExecuteCore(PackageItem item)
        {
            IPackage package = item.PackageIdentity;

            // treat solution-level packages specially
            if (!PackageManager.IsProjectLevel(package))
            {
                return UninstallSolutionPackage(package);
            }

            // display the Manage dialog to allow user to pick projects to install/uninstall
            IEnumerable<Project> selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                Resources.Dialog_InstalledSolutionInstruction,
                item.PackageIdentity,
                // Selector function to return the initial checkbox state for a Project.
                // We check a project by default if it has the current package installed.
                project => PackageManager.GetProjectManager(project).LocalRepository.Exists(package),
                ignored => true);

            if (selectedProjects == null)
            {
                // user presses Cancel button on the Solution dialog
                return false;
            }

            // bug #1181: Use HashSet<unique name> instead of HashSet<Project>.
            // in some rare cases, the project instance returned by GetProjects() may be different 
            // than the ones in selectedProjectSet.
            var selectedProjectsSet = new HashSet<string>(
                selectedProjects.Select(p => p.GetUniqueName()),
                StringComparer.OrdinalIgnoreCase);

            // now determine if user has actually made any change to the checkboxes
            IList<Project> allProjects = _solutionManager.GetProjects().ToList();

            bool hasInstallWork = allProjects.Any(p =>
                selectedProjectsSet.Contains(p.GetUniqueName()) && !IsPackageInstalledInProject(p, package));

            bool hasUninstallWork = allProjects.Any(p =>
                !selectedProjectsSet.Contains(p.GetUniqueName()) && IsPackageInstalledInProject(p, package));

            if (!hasInstallWork && !hasUninstallWork)
            {
                // nothing to do, so return
                return false;
            }

            var uninstallRepositories = new List<IPackageRepository>();
            var uninstallFrameworks = new List<FrameworkName>();
            var uninstallProjects = new List<Project>();

            bool? removeDepedencies = false;
            if (hasUninstallWork)
            {
                // Starting in 2.0, each project can have a different set of dependencies (because of different target frameworks).
                // To keep the UI simple, we aggregate all the dependencies from all uninstall projects
                // and ask if user wants to uninstall them all.

                foreach (Project project in allProjects)
                {
                    // check if user wants to uninstall the package in this project
                    if (!selectedProjectsSet.Contains(project.GetUniqueName()))
                    {
                        uninstallProjects.Add(project);
                        uninstallRepositories.Add(PackageManager.GetProjectManager(project).LocalRepository);
                        uninstallFrameworks.Add(project.GetTargetFrameworkName());
                    }
                }

                removeDepedencies = AskRemoveDependency(package, uninstallRepositories, uninstallFrameworks);
                if (removeDepedencies == null)
                {
                    // user cancels the operation.
                    return false;
                }
            }

            ShowProgressWindow();

            // now install the packages that are checked
            // Bug 1357: It's crucial that we perform all installs before uninstalls
            // to avoid the package file being deleted before an install.
            if (hasInstallWork)
            {
                bool successful = InstallPackageIntoProjects(package, allProjects, selectedProjectsSet);
                if (!successful)
                {
                    return false;
                }
            }

            // now uninstall the packages that are unchecked           
            for (int i = 0; i < uninstallProjects.Count; ++i)
            {
                try
                {
                    CheckDependentPackages(package, uninstallRepositories[i], uninstallFrameworks[i]);
                    UninstallPackageFromProject(uninstallProjects[i], item, (bool)removeDepedencies);
                }
                catch (Exception ex)
                {
                    AddFailedProject(uninstallProjects[i], ex);
                }
            }

            HideProgressWindow();
            return true;
        }
        public void CanExecuteAlwaysReturnTrue()
        {

            // Local repository contains Package A and Package B
            // We test the CanExecute() method on Package A and Package C

            // Arrange
            var repository = new MockPackageRepository();

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            repository.AddPackage(packageA);

            var packageB = PackageUtility.CreatePackage("B", "2.0");
            repository.AddPackage(packageB);

            var packageC = PackageUtility.CreatePackage("C", "2.0");

            var provider = CreateInstalledProvider(null, repository);

            var extensionA = new PackageItem(provider, packageA);
            var extensionC = new PackageItem(provider, packageC);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.True(canExecuteA);
            Assert.True(canExecuteC);
        }
Example #13
0
 public override bool CanExecute(PackageItem item)
 {
     return(true);
 }
Example #14
0
 public override bool CanExecute(PackageItem item)
 {
     // Enable command on a Package in the Installed provider if the package is installed.
     return(ProjectManager.IsInstalled(item.PackageIdentity));
 }
Example #15
0
        protected override bool ExecuteCore(PackageItem item)
        {
            IPackage package = item.PackageIdentity;

            // treat solution-level packages specially
            if (!PackageManager.IsProjectLevel(package))
            {
                return(UninstallSolutionPackage(package));
            }

            // display the Manage dialog to allow user to pick projects to install/uninstall
            IEnumerable <Project> selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                Resources.Dialog_InstalledSolutionInstruction,
                item.PackageIdentity,
                // Selector function to return the initial checkbox state for a Project.
                // We check a project by default if it has the current package installed.
                project => PackageManager.GetProjectManager(project).IsInstalled(package),
                ignored => true);

            if (selectedProjects == null)
            {
                // user presses Cancel button on the Solution dialog
                return(false);
            }

            // bug #1181: Use HashSet<unique name> instead of HashSet<Project>.
            // in some rare cases, the project instance returned by GetProjects() may be different
            // than the ones in selectedProjectSet.
            var selectedProjectsSet = new HashSet <string>(
                selectedProjects.Select(p => p.UniqueName),
                StringComparer.OrdinalIgnoreCase);

            // now determine if user has actually made any change to the checkboxes
            IList <Project> allProjects = _solutionManager.GetProjects().ToList();

            bool hasInstallWork = allProjects.Any(p =>
                                                  selectedProjectsSet.Contains(p.UniqueName) && !IsPackageInstalledInProject(p, package));

            bool hasUninstallWork = allProjects.Any(p =>
                                                    !selectedProjectsSet.Contains(p.UniqueName) && IsPackageInstalledInProject(p, package));

            if (!hasInstallWork && !hasUninstallWork)
            {
                // nothing to do, so return
                return(false);
            }

            var uninstallRepositories = new List <IPackageRepository>();
            var uninstallFrameworks   = new List <FrameworkName>();
            var uninstallProjects     = new List <Project>();

            bool?removeDepedencies = false;

            if (hasUninstallWork)
            {
                // Starting in 2.0, each project can have a different set of dependencies (because of different target frameworks).
                // To keep the UI simple, we aggregate all the dependencies from all uninstall projects
                // and ask if user wants to uninstall them all.

                foreach (Project project in allProjects)
                {
                    // check if user wants to uninstall the package in this project
                    if (!selectedProjectsSet.Contains(project.UniqueName))
                    {
                        uninstallProjects.Add(project);
                        uninstallRepositories.Add(PackageManager.GetProjectManager(project).LocalRepository);
                        uninstallFrameworks.Add(project.GetTargetFrameworkName());
                    }
                }

                removeDepedencies = AskRemoveDependency(package, uninstallRepositories, uninstallFrameworks);
                if (removeDepedencies == null)
                {
                    // user cancels the operation.
                    return(false);
                }
            }

            ShowProgressWindow();

            // now install the packages that are checked
            // Bug 1357: It's crucial that we perform all installs before uninstalls
            // to avoid the package file being deleted before an install.
            if (hasInstallWork)
            {
                bool successful = InstallPackageIntoProjects(package, allProjects, selectedProjectsSet);
                if (!successful)
                {
                    return(false);
                }
            }

            // now uninstall the packages that are unchecked
            for (int i = 0; i < uninstallProjects.Count; ++i)
            {
                try
                {
                    CheckDependentPackages(package, uninstallRepositories[i], uninstallFrameworks[i]);
                    UninstallPackageFromProject(uninstallProjects[i], item, (bool)removeDepedencies);
                }
                catch (Exception ex)
                {
                    AddFailedProject(uninstallProjects[i], ex);
                }
            }

            HideProgressWindow();
            return(true);
        }
Example #16
0
        protected override bool ExecuteCore(PackageItem item)
        {
            _activePackageManager = GetActivePackageManager();
            using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Install))
            {
                IList <Project> selectedProjectsList;

                ShowProgressWindow();
                bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity);
                if (isProjectLevel)
                {
                    HideProgressWindow();
                    var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                        Resources.Dialog_OnlineSolutionInstruction,
                        item.PackageIdentity,
                        DetermineProjectCheckState,
                        ignored => true);
                    if (selectedProjects == null)
                    {
                        // user presses Cancel button on the Solution dialog
                        return(false);
                    }

                    selectedProjectsList = selectedProjects.ToList();
                    if (selectedProjectsList.Count == 0)
                    {
                        return(false);
                    }

                    // save the checked state of projects so that we can restore them the next time
                    SaveProjectCheckStates(selectedProjectsList);

                    ShowProgressWindow();
                }
                else
                {
                    // solution package. just install into the solution
                    selectedProjectsList = new Project[0];
                }

                IList <PackageOperation> operations;
                bool acceptLicense = isProjectLevel ? ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, selectedProjectsList, out operations)
                                                    : ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, targetFramework: null, operations: out operations);
                if (!acceptLicense)
                {
                    return(false);
                }

                try
                {
                    RegisterPackageOperationEvents(_activePackageManager, null);

                    _activePackageManager.InstallPackage(
                        selectedProjectsList,
                        item.PackageIdentity,
                        operations,
                        ignoreDependencies: false,
                        allowPrereleaseVersions: IncludePrerelease,
                        logger: this,
                        eventListener: this);
                }
                finally
                {
                    UnregisterPackageOperationEvents(_activePackageManager, null);
                }

                return(true);
            }
        }
Example #17
0
 protected override void ExecuteCommand(IProjectManager projectManager, PackageItem item, IVsPackageManager activePackageManager, IList <PackageOperation> operations)
 {
     activePackageManager.UpdatePackage(projectManager, item.PackageIdentity, operations, updateDependencies: true, allowPrereleaseVersions: IncludePrerelease, logger: this);
 }
Example #18
0
 /// <summary>
 /// This method is called on background thread.
 /// </summary>
 /// <returns><c>true</c> if the method succeeded. <c>false</c> otherwise.</returns>
 protected virtual bool ExecuteCore(PackageItem item)
 {
     return(true);
 }
Example #19
0
 public abstract bool CanExecute(PackageItem item);
Example #20
0
        protected override void OnExecuteCompleted(PackageItem item)
        {
            _lastExecutionItem = item;
            SelectedNode.PackageLoadCompleted += SelectedNode_PackageLoadCompleted;

            // For the solution Installed provider, packages can be installed and uninstalled.
            // It's cumbersome to update the packages incrementally, so we just refresh everything.
            SelectedNode.Refresh(resetQueryBeforeRefresh: true);

            // repopulate the list of project references for all package items
            foreach (PackageItem packageItem in SelectedNode.Extensions)
            {
                packageItem.ReferenceProjects.Clear();
                packageItem.ReferenceProjects.AddRange(GetReferenceProjects(packageItem.PackageIdentity));
            }
        }
        protected override bool ExecuteCore(PackageItem item)
        {
            _activePackageManager = GetActivePackageManager();
            using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Update))
            {
                ShowProgressWindow();
                IList <Project> selectedProjectsList;
                bool            isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity);
                if (isProjectLevel)
                {
                    HideProgressWindow();
                    var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                        Resources.Dialog_UpdatesSolutionInstruction,
                        item.PackageIdentity,
                        // Selector function to return the initial checkbox state for a Project.
                        // We check a project if it has the current package installed by Id, but not version
                        project =>
                    {
                        var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository;
                        return(localRepository.Exists(item.Id) && IsVersionConstraintSatisfied(item, localRepository));
                    },
                        project =>
                    {
                        var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository;

                        // for the Updates solution dialog, we only enable a project if it has an old version of
                        // the package installed.
                        return(localRepository.Exists(item.Id) &&
                               !localRepository.Exists(item.Id, item.PackageIdentity.Version) &&
                               IsVersionConstraintSatisfied(item, localRepository));
                    }
                        );

                    if (selectedProjects == null)
                    {
                        // user presses Cancel button on the Solution dialog
                        return(false);
                    }

                    selectedProjectsList = selectedProjects.ToList();
                    if (selectedProjectsList.Count == 0)
                    {
                        return(false);
                    }

                    ShowProgressWindow();
                }
                else
                {
                    // solution package. just update into the solution
                    selectedProjectsList = new Project[0];
                }

                IList <PackageOperation> operations;
                bool acceptLicense = isProjectLevel ? ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, selectedProjectsList, out operations)
                                                    : ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, targetFramework: null, operations: out operations);

                if (!acceptLicense)
                {
                    return(false);
                }

                if (!isProjectLevel && operations.Any())
                {
                    // When dealing with solution level packages, only the set of actions specified under operations are executed.
                    // In such a case, no operation to uninstall the current package is specified. We'll identify the package that is being updated and
                    // explicitly add a uninstall operation.
                    var packageToUpdate = _activePackageManager.LocalRepository.FindPackage(item.Id);
                    if (packageToUpdate != null)
                    {
                        operations.Insert(0, new PackageOperation(packageToUpdate, PackageAction.Uninstall));
                    }
                }

                try
                {
                    RegisterPackageOperationEvents(_activePackageManager, null);

                    _activePackageManager.UpdatePackage(
                        selectedProjectsList,
                        item.PackageIdentity,
                        operations,
                        updateDependencies: true,
                        allowPrereleaseVersions: IncludePrerelease,
                        logger: this,
                        eventListener: this);
                }
                finally
                {
                    UnregisterPackageOperationEvents(_activePackageManager, null);
                }

                return(true);
            }
        }
Example #22
0
        private void SelectedNode_PackageLoadCompleted(object sender, EventArgs e)
        {
            ((PackagesTreeNodeBase)sender).PackageLoadCompleted -= SelectedNode_PackageLoadCompleted;

            if (SelectedNode == null || _lastExecutionItem == null)
            {
                return;
            }

            // find a new PackageItem that represents the same package as _lastExecutionItem does;
            PackageItem foundItem = SelectedNode.Extensions.OfType<PackageItem>().FirstOrDefault(
                p => PackageEqualityComparer.IdAndVersion.Equals(p.PackageIdentity, _lastExecutionItem.PackageIdentity));
            if (foundItem != null)
            {
                foundItem.IsSelected = true;
            }

            _lastExecutionItem = null;
        }
 protected void UninstallPackageFromProject(Project project, PackageItem item, bool removeDependencies)
 {
     IProjectManager projectManager = null;
     try
     {
         projectManager = PackageManager.GetProjectManager(project);
         // make sure the package is installed in this project before proceeding
         if (projectManager.IsInstalled(item.PackageIdentity))
         {
             RegisterPackageOperationEvents(PackageManager, projectManager);
             PackageManager.UninstallPackage(projectManager, item.Id, version: item.PackageIdentity.Version, forceRemove: false, removeDependencies: removeDependencies, logger: this);
         }
     }
     finally
     {
         if (projectManager != null)
         {
             UnregisterPackageOperationEvents(PackageManager, projectManager);
         }
     }
 }
 public override void Execute(PackageItem item)
 {
 }
 protected override void ExecuteCommand(IProjectManager projectManager, PackageItem item, IVsPackageManager activePackageManager, IList<PackageOperation> operations)
 {
     activePackageManager.UpdatePackages(
         projectManager, 
         new [] { item.PackageIdentity }, 
         operations, 
         updateDependencies: true, 
         allowPrereleaseVersions: IncludePrerelease, 
         logger: this);
 }
        public void ExecuteMethodCallsUninstallPackageMethodOnPackageManager()
        {
            // Local repository contains Package A

            // Arrange
            var repository = new MockPackageRepository();

            var packageA = PackageUtility.CreatePackage("A", "1.0");
            repository.AddPackage(packageA);

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.LocalRepository).Returns(repository);
            projectManager.Setup(p => p.IsInstalled(It.Is<IPackage>(item => item == packageA))).Returns(true);

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.GetProjectManager(It.IsAny<Project>())).Returns(projectManager.Object);

            var provider = CreateInstalledProvider(packageManager.Object, repository);

            var extensionA = new PackageItem(provider, packageA);

            var mockWindowServices = new Mock<IUserNotifierServices>();

            var mre = new ManualResetEventSlim(false);
            provider.ExecuteCompletedCallback = () =>
            {
                // Assert
                packageManager.Verify(p => p.UninstallPackage(projectManager.Object, "A", null, false, false, provider), Times.Once());
                mockWindowServices.Verify(p => p.ShowLicenseWindow(It.IsAny<IEnumerable<IPackage>>()), Times.Never());

                mre.Set();
            };

            // Act
            provider.Execute(extensionA);

            mre.Wait();
        }
        public void ExecuteUninstallsSolutionLevelPackageWhenUpdating()
        {
            // Arrange
            var packageA_10 = PackageUtility.CreatePackage("A", "1.0", content: null, assemblyReferences: null, tools: new[] { "init.ps1" }, dependencies: null);
            var packageA_12 = PackageUtility.CreatePackage("A", "1.2", content: null, assemblyReferences: null, tools: new[] { "init.ps1" }, dependencies: null);

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA_12);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageA_10);

            var projectManager1 = new Mock<IProjectManager>();
            projectManager1.Setup(p => p.LocalRepository).Returns(localRepository);

            var project1 = MockProjectUtility.CreateMockProject("Project1");

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.LocalRepository).Returns(localRepository);
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project1))).Returns(projectManager1.Object);
            packageManager.Setup(p => p.IsProjectLevel(packageA_12)).Returns(false);

            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project1"))).Returns(project1);
            solutionManager.Setup(p => p.GetProjects()).Returns(new Project[] { project1 });

            var mockWindowService = new Mock<IUserNotifierServices>();
            mockWindowService.Setup(p => p.ShowProjectSelectorWindow(
                It.IsAny<string>(),
                It.IsAny<IPackage>(),
                It.IsAny<Predicate<Project>>(),
                It.IsAny<Predicate<Project>>())).Returns(new Project[0]);

            var provider = CreateSolutionUpdatesProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, userNotifierServices: mockWindowService.Object);
            var extensionTree = provider.ExtensionsTree;

            var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
            firstTreeNode.Repository.AddPackage(packageA_10);

            provider.SelectedNode = firstTreeNode;
            IVsPackageManager activePackageManager = provider.GetActivePackageManager();
            Mock<IVsPackageManager> mockPackageManager = Mock.Get<IVsPackageManager>(activePackageManager);

            var manualEvent = new ManualResetEventSlim(false);

            Exception exception = null;

            provider.ExecuteCompletedCallback = delegate
            {
                try
                {
                    // Assert
                    mockPackageManager.Verify(p => p.UpdatePackage(
                        new Project[0],
                        packageA_12,
                        new[] { new PackageOperation(packageA_10, PackageAction.Uninstall), new PackageOperation(packageA_12, PackageAction.Install) },
                        true,
                        false,
                        provider,
                        provider), Times.Once());
                }
                catch (Exception e)
                {
                    exception = e;
                }
                finally
                {
                    manualEvent.Set();
                }
            };

            var extensionA_12 = new PackageItem(provider, packageA_12);

            // Act
            provider.Execute(extensionA_12);

            // do not allow the method to return
            manualEvent.Wait();

            Assert.Null(exception);
        }
Example #28
0
        protected override bool ExecuteCore(PackageItem item)
        {
            _activePackageManager = GetActivePackageManager();
            using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Install, item.Id, item.Version))
            {
                IList<Project> selectedProjectsList;

                ShowProgressWindow();
                bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity);
                if (isProjectLevel)
                {
                    HideProgressWindow();
                    var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                        Resources.Dialog_OnlineSolutionInstruction,
                        item.PackageIdentity,
                        DetermineProjectCheckState,
                        ignored => true);
                    if (selectedProjects == null)
                    {
                        // user presses Cancel button on the Solution dialog
                        return false;
                    }

                    selectedProjectsList = selectedProjects.ToList();
                    if (selectedProjectsList.Count == 0)
                    {
                        return false;
                    }

                    // save the checked state of projects so that we can restore them the next time
                    SaveProjectCheckStates(selectedProjectsList);

                    ShowProgressWindow();
                }
                else
                {
                    // solution package. just install into the solution
                    selectedProjectsList = new Project[0];
                }

                IList<PackageOperation> operations;
                bool acceptLicense = isProjectLevel ? ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, selectedProjectsList, out operations)
                                                    : ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, targetFramework: null, operations: out operations);
                if (!acceptLicense)
                {
                    return false;
                }

                try
                {
                    RegisterPackageOperationEvents(_activePackageManager, null);

                    _activePackageManager.InstallPackage(
                        selectedProjectsList,
                        item.PackageIdentity,
                        operations,
                        ignoreDependencies: false,
                        allowPrereleaseVersions: IncludePrerelease,
                        logger: this,
                        eventListener: this);
                }
                finally
                {
                    UnregisterPackageOperationEvents(_activePackageManager, null);
                }

                return true;
            }
        }
Example #29
0
 public abstract bool CanExecute(PackageItem item);
        protected override bool ExecuteCore(PackageItem item)
        {
            if (_project.SupportsINuGetProjectSystem())
            {
                ShowProgressWindow();
                UninstallPackageFromProject(_project, item, (bool)false);
                HideProgressWindow();
                return true;
            }
            else
            {
                CheckDependentPackages(item.PackageIdentity, LocalRepository, _targetFramework);

                bool? removeDependencies = AskRemoveDependency(
                    item.PackageIdentity,
                    new[] { LocalRepository },
                    new[] { _targetFramework });

                if (removeDependencies == null)
                {
                    // user presses Cancel
                    return false;
                }

                ShowProgressWindow();
                UninstallPackageFromProject(_project, item, (bool)removeDependencies);
                HideProgressWindow();
                return true;
            }
        }
        protected override bool ExecuteCore(PackageItem item)
        {
            _activePackageManager = GetActivePackageManager();
            using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Update, item.Id, item.Version))
            {
                ShowProgressWindow();
                IList <Project> selectedProjectsList;
                bool            isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity);
                if (isProjectLevel)
                {
                    HideProgressWindow();
                    var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                        Resources.Dialog_UpdatesSolutionInstruction,
                        item.PackageIdentity,
                        // Selector function to return the initial checkbox state for a Project.
                        // We check a project if it has the current package installed by Id, but not version
                        project =>
                    {
                        var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository;
                        return(localRepository.Exists(item.Id) && IsVersionConstraintSatisfied(item, localRepository));
                    },
                        project =>
                    {
                        var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository;

                        // for the Updates solution dialog, we only enable a project if it has an old version of
                        // the package installed.
                        return(localRepository.Exists(item.Id) &&
                               !localRepository.Exists(item.Id, item.PackageIdentity.Version) &&
                               IsVersionConstraintSatisfied(item, localRepository));
                    }
                        );

                    if (selectedProjects == null)
                    {
                        // user presses Cancel button on the Solution dialog
                        return(false);
                    }

                    selectedProjectsList = selectedProjects.ToList();
                    if (selectedProjectsList.Count == 0)
                    {
                        return(false);
                    }

                    ShowProgressWindow();
                }
                else
                {
                    // solution package. just install into the active project.
                    selectedProjectsList = new Project[] { _solutionManager.DefaultProject };
                }

                // resolve operations
                var actionsByProject = ResolveActionsByProjectForInstall(
                    item.PackageIdentity,
                    _activePackageManager,
                    selectedProjectsList);

                // ask for license agreement
                var allActions = new List <Resolver.PackageAction>();
                foreach (var actions in actionsByProject.Values)
                {
                    allActions.AddRange(actions);
                }

                bool acceptLicense = ShowLicenseAgreement(allActions);
                if (!acceptLicense)
                {
                    return(false);
                }

                var actionExecutor = new Resolver.ActionExecutor();
                actionExecutor.Logger = this;
                actionExecutor.PackageOperationEventListener  = this;
                actionExecutor.CatchProjectOperationException = true;

                // execute operations by project
                foreach (var actionsForOneProject in actionsByProject)
                {
                    var projectManager = actionsForOneProject.Key;
                    var project        = ((VsProjectSystem)(projectManager.Project)).Project;
                    try
                    {
                        RegisterPackageOperationEvents(_activePackageManager, projectManager);
                        actionExecutor.Execute(actionsForOneProject.Value);
                    }
                    catch (Exception ex)
                    {
                        AddFailedProject(project, ex);
                    }
                    finally
                    {
                        UnregisterPackageOperationEvents(_activePackageManager, projectManager);
                    }
                }

                return(true);
            }
        }
 protected override void OnExecuteCompleted(PackageItem item)
 {
     if (SelectedNode != null)
     {
         // after every uninstall operation, just refresh the current node because
         // when packages are uninstalled, the number of pages may decrease.
         SelectedNode.Refresh(resetQueryBeforeRefresh: true);
     }
     else
     {
         base.OnExecuteCompleted(item);
     }
 }
Example #33
0
        protected override bool ExecuteCore(PackageItem item)
        {
            _activePackageManager = GetActivePackageManager();
            using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Update))
            {
                ShowProgressWindow();
                IList<Project> selectedProjectsList;
                bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity);
                if (isProjectLevel)
                {
                    HideProgressWindow();
                    var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
                        Resources.Dialog_UpdatesSolutionInstruction,
                        item.PackageIdentity,
                        // Selector function to return the initial checkbox state for a Project.
                        // We check a project if it has the current package installed by Id, but not version
                        project => _activePackageManager.GetProjectManager(project).LocalRepository.Exists(item.Id),
                        project =>
                        {
                            var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository;

                            // for the Updates solution dialog, we only enable a project if it has an old version of 
                            // the package installed.
                            return localRepository.Exists(item.Id) &&
                                   !localRepository.Exists(item.Id, item.PackageIdentity.Version);
                        }
                    );

                    if (selectedProjects == null)
                    {
                        // user presses Cancel button on the Solution dialog
                        return false;
                    }

                    selectedProjectsList = selectedProjects.ToList();
                    if (selectedProjectsList.Count == 0)
                    {
                        return false;
                    }

                    ShowProgressWindow();
                }
                else
                {
                    // solution package. just update into the solution
                    selectedProjectsList = new Project[0];
                }

                IList<PackageOperation> operations;
                bool acceptLicense = isProjectLevel ? ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, selectedProjectsList, out operations)
                                                    : ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, targetFramework: null, operations: out operations);

                if (!acceptLicense)
                {
                    return false;
                }

                if (!isProjectLevel && operations.Any())
                {
                    // When dealing with solution level packages, only the set of actions specified under operations are executed. 
                    // In such a case, no operation to uninstall the current package is specified. We'll identify the package that is being updated and
                    // explicitly add a uninstall operation.
                    var packageToUpdate = _activePackageManager.LocalRepository.FindPackage(item.Id);
                    if (packageToUpdate != null)
                    {
                        operations.Insert(0, new PackageOperation(packageToUpdate, PackageAction.Uninstall));
                    }
                }

                try
                {
                    RegisterPackageOperationEvents(_activePackageManager, null);

                    _activePackageManager.UpdatePackage(
                        selectedProjectsList,
                        item.PackageIdentity,
                        operations,
                        updateDependencies: true,
                        allowPrereleaseVersions: IncludePrerelease,
                        logger: this,
                        eventListener: this);
                }
                finally
                {
                    UnregisterPackageOperationEvents(_activePackageManager, null);
                }

                return true;
            }
        }
        protected override void OnExecuteCompleted(PackageItem item)
        {
            base.OnExecuteCompleted(item);

            // When this was the Update All command execution, 
            // an individual Update command may have updated all remaining packages.
            // If there are no more updates left, we hide the Update All button. 
            // 
            // However, we only want to do so if there's only one page of result, because
            // we don't want to download all packages in all pages just to check for this condition.
            if (SelectedNode != null && SelectedNode.TotalNumberOfPackages > 1 && SelectedNode.TotalPages == 1)
            {
                if (SelectedNode.Extensions.OfType<PackageItem>().All(p => !p.IsEnabled))
                {
                    _updateAllUIService.Hide();
                }
            }
        }
        public virtual void Execute(PackageItem item)
        {
            if (OperationCoordinator.IsBusy)
            {
                return;
            }

            // disable all operations while this install is in progress
            OperationCoordinator.IsBusy = true;

            _readmeFile = null;
            _originalPackageId = item.Id;
            _progressProvider.ProgressAvailable += OnProgressAvailable;

            _uiCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            _culture = System.Threading.Thread.CurrentThread.CurrentCulture;

            _failedProjects = new Dictionary<Project, Exception>();

            ClearProgressMessages();

            SaveExpandedNodes();

            var worker = new BackgroundWorker();
            worker.DoWork += OnRunWorkerDoWork;
            worker.RunWorkerCompleted += OnRunWorkerCompleted;
            worker.RunWorkerAsync(item);

            // write an introductory sentence before every operation starts to make the console easier to read
            string progressMessage = GetProgressMessage(item.PackageIdentity);
            WriteLineToOutputWindow("------- " + progressMessage + " -------");
        }
        public void ExecuteMethodCallUpdatePackageOnAllProjects(bool includePrerelease)
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");
            var packageB2 = PackageUtility.CreatePackage("B", "4.0");

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);
            sourceRepository.AddPackage(packageB2);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageB);

            var projectManager1 = new Mock<IProjectManager>();
            projectManager1.Setup(p => p.LocalRepository).Returns(localRepository);

            var projectManager2 = new Mock<IProjectManager>();
            projectManager2.Setup(p => p.LocalRepository).Returns(localRepository);

            var project1 = MockProjectUtility.CreateMockProject("Project1");
            var project2 = MockProjectUtility.CreateMockProject("Project2");

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project1))).Returns(projectManager1.Object);
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project2))).Returns(projectManager2.Object);
            packageManager.Setup(p => p.IsProjectLevel(It.IsAny<IPackage>())).Returns(true);

            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project1"))).Returns(project1);
            solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project2"))).Returns(project2);
            solutionManager.Setup(p => p.GetProjects()).Returns(new Project[] { project1, project2 });

            var mockWindowService = new Mock<IUserNotifierServices>();
            mockWindowService.Setup(p => p.ShowProjectSelectorWindow(
                It.IsAny<string>(),
                It.IsAny<IPackage>(),
                It.IsAny<Predicate<Project>>(),
                It.IsAny<Predicate<Project>>())).Returns(new Project[] { project1, project2 });

            var provider = CreateSolutionUpdatesProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, userNotifierServices: mockWindowService.Object);
            provider.IncludePrerelease = includePrerelease;
            var extensionTree = provider.ExtensionsTree;

            var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
            firstTreeNode.Repository.AddPackage(packageA);
            firstTreeNode.Repository.AddPackage(packageB);
            firstTreeNode.Repository.AddPackage(packageC);

            provider.SelectedNode = firstTreeNode;
            IVsPackageManager activePackageManager = provider.GetActivePackageManager();
            Mock<IVsPackageManager> mockPackageManager = Mock.Get<IVsPackageManager>(activePackageManager);

            var manualEvent = new ManualResetEventSlim(false);

            provider.ExecuteCompletedCallback = delegate
            {
                // Assert
                Assert.Equal(RepositoryOperationNames.Update, sourceRepository.LastOperation);

                mockPackageManager.Verify(p => p.UpdatePackage(
                    new Project[] { project1, project2 },
                    packageB2,
                    It.IsAny<IEnumerable<PackageOperation>>(),
                    true,
                    includePrerelease,
                    provider,
                    provider), Times.Once());

                manualEvent.Set();
            };

            var extensionB2 = new PackageItem(provider, packageB2);

            // Act
            provider.Execute(extensionB2);

            // do not allow the method to return
            manualEvent.Wait();
        }
Example #37
0
        public void CanExecuteReturnsCorrectResultWhenLoweredVersionPackageIsInstalled()
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();
            // these are installed packages
            localRepository.AddPackage(PackageUtility.CreatePackage("A", "2.0"));
            localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0-beta"));
            localRepository.AddPackage(PackageUtility.CreatePackage("C", "3.0-beta"));

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);

            var provider = CreateOnlineProvider(packageManager.Object, localRepository);

            var extensionA = new PackageItem(provider, packageA);
            var extensionB = new PackageItem(provider, packageB);
            var extensionC = new PackageItem(provider, packageC);

            // Act
            bool canExecuteA = provider.CanExecute(extensionA);
            bool canExecuteB = provider.CanExecute(extensionB);
            bool canExecuteC = provider.CanExecute(extensionC);

            // Assert
            Assert.False(canExecuteA);
            Assert.True(canExecuteB);
            Assert.True(canExecuteC);
        }
Example #38
0
        public virtual void Execute(PackageItem item)
        {
            if (OperationCoordinator.IsBusy) {
                return;
            }

            // disable all operations while this install is in progress
            OperationCoordinator.IsBusy = true;

            _progressProvider.ProgressAvailable += OnProgressAvailable;

            _uiCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            _culture = System.Threading.Thread.CurrentThread.CurrentCulture;

            var worker = new BackgroundWorker();
            worker.DoWork += OnRunWorkerDoWork;
            worker.RunWorkerCompleted += OnRunWorkerCompleted;
            worker.RunWorkerAsync(item);

            // write an introductory sentence before every operation starts to make the console easier to read
            string progressMessage = GetProgressMessage(item.PackageIdentity);
            WriteLineToOutputWindow("------- " + progressMessage + " -------");

            ShowProgressWindow();
        }
Example #39
0
        public void ExecuteMethodCallsInstallPackageMethodOnPackageManager(bool includePrerelease)
        {
            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageC);
            sourceRepository.AddPackage(packageB);

            var localRepository = new MockPackageRepository();
            localRepository.AddPackage(packageA);

            var projectManager = new Mock<IProjectManager>();
            projectManager.Setup(p => p.LocalRepository).Returns(localRepository);

            var project = new Mock<Project>();

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project.Object))).Returns(projectManager.Object);

            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(s => s.GetProject(It.IsAny<string>())).Returns(project.Object);

            var provider = CreateOnlineProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, project: project.Object);
            provider.IncludePrerelease = includePrerelease;
            var extensionTree = provider.ExtensionsTree;

            var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
            firstTreeNode.Repository.AddPackage(packageA);
            firstTreeNode.Repository.AddPackage(packageB);
            firstTreeNode.Repository.AddPackage(packageC);

            provider.SelectedNode = firstTreeNode;
            IVsPackageManager activePackageManager = provider.GetActivePackageManager();
            Mock<IVsPackageManager> mockPackageManager = Mock.Get<IVsPackageManager>(activePackageManager);
            mockPackageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project.Object))).Returns(projectManager.Object);

            ManualResetEvent manualEvent = new ManualResetEvent(false);

            provider.ExecuteCompletedCallback = delegate
            {
                // Assert
                Assert.Equal(RepositoryOperationNames.Install, sourceRepository.LastOperation);

                mockPackageManager.Verify(p => p.InstallPackage(projectManager.Object, packageB, It.IsAny<IEnumerable<PackageOperation>>(), false, includePrerelease, provider), Times.Once());

                manualEvent.Set();
            };

            var extensionB = new PackageItem(provider, packageB);

            // Act
            provider.Execute(extensionB);

            // do not allow the method to return
            manualEvent.WaitOne();
        }
Example #40
0
 protected virtual void OnExecuteCompleted(PackageItem item)
 {
     // After every operation, just update the status of all packages in the current node.
     // Strictly speaking, this is not required; only affected packages need to be updated.
     // But doing so would require us to keep a Dictionary<IPackage, PackageItem> which is not worth it.
     if (SelectedNode != null) {
         foreach (PackageItem node in SelectedNode.Extensions) {
             node.UpdateEnabledStatus();
         }
     }
 }
Example #41
0
        public void ExecuteMethodInstallPackagesWithInitScript()
        {
            // source repo has A, B, C
            // solution repo has A
            // project repo has C

            // install B

            // Arrange
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0", content: new string[] { "hello world" }, tools: new string[] { "init.ps1" });
            var packageC = PackageUtility.CreatePackage("C", "3.0");

            var solutionRepository = new MockPackageRepository();
            solutionRepository.AddPackage(packageA);

            var sourceRepository = new MockPackageRepository();
            sourceRepository.AddPackage(packageA);
            sourceRepository.AddPackage(packageB);
            sourceRepository.AddPackage(packageC);

            var localRepository = new MockPackageRepository();
            localRepository.Add(packageC);

            var projectManager = CreateProjectManager(localRepository, solutionRepository);

            var project = new Mock<Project>();
            project.Setup(p => p.Properties.Item("TargetFrameworkMoniker").Value).Returns(".NETFramework, Version=4.0");
            var scriptExecutor = new Mock<IScriptExecutor>();

            var packageManager = new Mock<IVsPackageManager>();
            packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
            packageManager.Setup(p => p.LocalRepository).Returns(solutionRepository);
            packageManager.Setup(p => p.InstallPackage(projectManager, packageB, It.IsAny<IEnumerable<PackageOperation>>(), false, false, It.IsAny<ILogger>())).
                Raises(p => p.PackageInstalled += null, packageManager, new PackageOperationEventArgs(packageB, null, ""));
            packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project.Object))).Returns(projectManager);

            var solutionManager = new Mock<ISolutionManager>();
            solutionManager.Setup(s => s.GetProject(It.IsAny<string>())).Returns(project.Object);

            var provider = CreateOnlineProvider(packageManager.Object, null, null, null, project.Object, scriptExecutor.Object, solutionManager.Object);
            var extensionTree = provider.ExtensionsTree;

            var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
            firstTreeNode.Repository.AddPackage(packageA);
            firstTreeNode.Repository.AddPackage(packageB);
            firstTreeNode.Repository.AddPackage(packageC);

            provider.SelectedNode = firstTreeNode;

            ManualResetEvent manualEvent = new ManualResetEvent(false);

            provider.ExecuteCompletedCallback = delegate
            {
                try
                {
                    // Assert

                    // init.ps1 should be executed
                    scriptExecutor.Verify(p => p.Execute(It.IsAny<string>(), PowerShellScripts.Init, packageB, null, null, It.IsAny<ILogger>()), Times.Once());

                    // InstallPackage() should get called
                    packageManager.Verify(p => p.InstallPackage(
                       projectManager, It.IsAny<IPackage>(), It.IsAny<IEnumerable<PackageOperation>>(), false, false, It.IsAny<ILogger>()), Times.Once());
                }
                finally
                {
                    manualEvent.Set();
                }
            };

            var extensionB = new PackageItem(provider, packageB);

            // Act
            provider.Execute(extensionB);

            // do not allow the method to return
            manualEvent.WaitOne();
        }