Esempio n. 1
0
        public void TestUnloadReloadOfProject()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                Utilities.SelectOrUnselectNodes <ProjectNode>(project, true);

                // Save everything.
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project.InteropSafeIVsHierarchy, 0);

                // Unload the project
                IVsSolution4 solutionService4 = solutionService as IVsSolution4;
                Assert.IsNotNull(solutionService4, "IVsSolution4 should be implemented!");

                solutionService4.UnloadProject(project.ProjectIDGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser);
                Assert.IsTrue(project.IsClosed, "The project has not been unloaded");

                // Reload the project
                solutionService4.ReloadProject(project.ProjectIDGuid);

                // Check to see if the project is reloaded. we cannot use the instance for the project since that is zombied at this point.
                IVsHierarchy ourHierarchy;
                string projectFullpath = project.GetMkDocument();
                solutionService.GetProjectOfUniqueName(projectFullpath, out ourHierarchy);
                Assert.IsTrue(ourHierarchy is IProjectEventsListener, "Our hierarchy has not been reloaded successfully");

                // Check to see if the nested project is there.
                EnvDTE.Project projectDTE = Utilities.GetAutomationObject(ourHierarchy);
                Assert.IsNotNull(projectDTE.ProjectItems.Item("ANestedProject"), "The nested project has not been loaded correctly.");

                // Check that bug 106520 does not happen anymore. We will check that the parent project is not dirty.
                int isDirty;
                ((IPersistFileFormat)ourHierarchy).IsDirty(out isDirty);
                Assert.IsTrue(isDirty == 0, "The parent project is dirtied after it has been reloaded");
            });
        }
Esempio n. 2
0
        public void TestUnloadReloadOfProject()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate()
            {
                //Get the global service provider and the dte
                IServiceProvider sp = VsIdeTestHostContext.ServiceProvider;
                DTE dte             = (DTE)sp.GetService(typeof(DTE));

                string destination  = Path.Combine(TestContext.TestDir, TestContext.TestName);
                ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true);

                Utilities.SelectOrUnselectNodes <ProjectNode>(project, true);

                // Save everything.
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project, 0);

                string projectFullpath = project.GetMkDocument();
                object customin        = null;
                object customout       = null;
                dte.Commands.Raise(VsMenus.guidStandardCommandSet97.ToString("B"), (int)Microsoft.VisualStudio.VSConstants.VSStd97CmdID.UnloadProject, ref customin, ref customout);
                // Check to see if the project is unloaded
                Assert.IsTrue(project.IsClosed, "The project has not been unloaded");

                dte.Commands.Raise(VsMenus.guidStandardCommandSet97.ToString("B"), (int)Microsoft.VisualStudio.VSConstants.VSStd97CmdID.ReloadProject, ref customin, ref customout);

                // Check to see if the project is reloaded. we cannot use the instance for the project since that is zombied at this point.
                IVsHierarchy ourHierarchy;
                solutionService.GetProjectOfUniqueName(projectFullpath, out ourHierarchy);
                Assert.IsTrue(ourHierarchy is IProjectEventsListener, "Our hierarchy has not been reloaded successfully");

                // Check to see if the nested project is there.
                EnvDTE.Project projectDTE = Utilities.GetAutomationObject(ourHierarchy);
                Assert.IsNotNull(projectDTE.ProjectItems.Item("ANestedProject"), "The nested project has not been loaded correctly.");

                // Check that bug 106520 does not happen anymore. We will check that the parent project is not dirty.
                int isDirty;
                ((IPersistFileFormat)ourHierarchy).IsDirty(out isDirty);
                Assert.IsTrue(isDirty == 0, "The parent project is dirtied after it has been reloaded");
            });
        }
Esempio n. 3
0
        private void TestImplicitNestedProjectReload(IServiceProvider sp, ProjectNode project, int dialogAnswer)
        {
            // Save everything.
            IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));

            solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project, 0);

            IVsProject3 nestedProject = Utilities.GetNestedHierarchy(project, "ANestedProject") as IVsProject3;

            if (nestedProject == null)
            {
                throw new InvalidOperationException("The nested project has not been loaded corectly");
            }

            string nestedProjectFileName = null;

            nestedProject.GetMkDocument(VSConstants.VSITEMID_ROOT, out nestedProjectFileName);

            if (nestedProjectFileName == null)
            {
                throw new InvalidOperationException("The nested project file name could not been retrieved corectly");
            }

            string resourceText = Utilities.GetResourceStringFromTheProjectAssembly("QueryReloadNestedProject");

            // Create the messageBoxListener Thread. This will bring up the reload of the nested project file.
            // In this scenario we will answer dialogAnswer. Also we rely on the exact messagebox text here.
            string message = String.Format(System.Globalization.CultureInfo.CurrentCulture, resourceText, nestedProjectFileName);

            DialogBoxPurger purger = new DialogBoxPurger(dialogAnswer, message);
            bool            result = false;

            try
            {
                purger.Start();
                this.AddReferenceExternallyToTheProjectFile(nestedProjectFileName);
            }
            finally
            {
                result = purger.WaitForDialogThreadToTerminate();
            }

            if (!result)
            {
                throw new InvalidOperationException("The messagebox for relaoding the nested project file has never popped up");
            }

            // Check to see if the nested project is there.
            EnvDTE.Project     projectDTE = Utilities.GetAutomationObject(project);
            EnvDTE.ProjectItem item       = projectDTE.ProjectItems.Item("ANestedProject");

            Assert.IsNotNull(item, "The nested project has not been loaded correctly.");
            EnvDTE.Project nestedAutomationProject = item.SubProject;

            // Now check to see if we can find the added reference
            VSLangProj.VSProject automationProject = nestedAutomationProject.Object as VSLangProj.VSProject;
            if (nestedAutomationProject == null)
            {
                throw new InvalidOperationException("The nested project is not a vs language project");
            }

            // Get references collection
            VSLangProj.References references = automationProject.References;

            IEnumerator enumerator = references.GetEnumerator();
            bool        found      = false;

            while (enumerator.MoveNext())
            {
                VSLangProj.Reference reference = enumerator.Current as VSLangProj.Reference;
                if (reference.Name == BuildEngineRef)
                {
                    found = true;
                }
            }

            if (dialogAnswer == NativeMethods.IDYES)
            {
                Assert.IsTrue(found, "The nested project file has not been reloaded correctly");
            }
            else
            {
                Assert.IsFalse(found, "The nested project file has been reloaded but was asked not to do that.");
            }
        }