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