Exemplo n.º 1
0
        public void TestDeletingAProjectItem()
        {
            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);

                List <uint> filenodeids = Utilities.SelectOrUnselectNodes <FileNode>(project, true);
                Debug.Assert(filenodeids.Count > 0, "There is no file node availabale");
                FileNode node          = project.NodeFromItemId(filenodeids[0]) as FileNode;
                ProjectElement element = node.ItemNode;
                string path            = node.GetMkDocument();
                node.Remove(true);

                //Now see if it is removed from the UI.
                HierarchyNode deletedNode = project.NodeFromItemId(filenodeids[0]);
                Assert.IsTrue(deletedNode == null, "File has not been removed correctly");

                // See if it has been removed from the procject file.
                MethodInfo mi       = typeof(ProjectElement).GetMethod("HasItemBeenDeleted", BindingFlags.Instance | BindingFlags.NonPublic);
                bool hasBeenDeleted = (bool)mi.Invoke(element, new object[] { });
                Assert.IsTrue(hasBeenDeleted, "File has not been removed correctly from the project file.");

                // See if it has been deleted physically
                Assert.IsFalse(File.Exists(path), "File has not been removed correctly from the disk.");
            });
        }
Exemplo n.º 2
0
        public void TestDoDefaultActionOnFileNode()
        {
            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);

                MethodInfo doDefaultAction = typeof(ProjectNode).GetMethod("DoDefaultAction", BindingFlags.NonPublic | BindingFlags.Instance);

                // select the model file, close it and then do deafult action on it. test whether it has opened it.
                List <uint> filenodeids = Utilities.SelectOrUnselectNodes <FileNode>(project, true);

                foreach (uint id in filenodeids)
                {
                    FileNode node = project.NodeFromItemId(id) as FileNode;
                    Assert.IsNotNull(node);
                    string document = node.GetMkDocument();

                    if (String.Compare(Path.GetExtension(document), ".cs", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        VsShellUtilities.SaveFileIfDirty(project.Site, document);

                        MethodInfo getDocumentManager = typeof(FileNode).GetMethod("GetDocumentManager", BindingFlags.NonPublic | BindingFlags.Instance);
                        DocumentManager manager       = getDocumentManager.Invoke(node, new object[] { }) as DocumentManager;

                        // Close the node.
                        Assert.IsTrue(manager.Close(__FRAMECLOSE.FRAMECLOSE_SaveIfDirty) == VSConstants.S_OK);

                        // Be sure the node is selected.
                        Utilities.ManipulateNode(project, node.ID, EXPANDFLAGS.EXPF_SelectItem);

                        // Invoke opening of the node.
                        doDefaultAction.Invoke(node, new object[] { });

                        // Check whether the document has been opened.
                        Guid logicalView = Guid.Empty;
                        IVsUIHierarchy hierOpen;
                        uint itemId;
                        IVsWindowFrame windowFrame;
                        Assert.IsTrue(VsShellUtilities.IsDocumentOpen(node.ProjectMgr.Site, document, logicalView, out hierOpen, out itemId, out windowFrame), "DoDeafult action did not open the file");
                        Assert.IsTrue(itemId == node.ID, "We did not open the correct document");
                        Assert.IsNotNull(windowFrame, "Do deafult action did not retun a window frame");
                        Assert.IsTrue(windowFrame.IsVisible() == VSConstants.S_OK, "Do deafult action did not show a window frame");
                    }
                }
            });
        }
Exemplo n.º 3
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");
            });
        }
Exemplo n.º 4
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");
            });
        }