Ejemplo 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.
                bool hasBeenDeleted = element.HasItemBeenDeleted;
                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.");
            });
        }
Ejemplo 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);

                        DocumentManager manager = node.GetDocumentManager();

                        // 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.ProjectManager.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");
                    }
                }
            });
        }