internal void OpenProject(VisualStudioApp app, string slnName, out PythonProjectNode projectNode, out EnvDTE.Project dteProject) { PythonVersion.AssertInstalled(); dteProject = app.OpenProject("TestData\\Targets\\" + slnName); projectNode = dteProject.GetPythonProject(); var fact = projectNode.InterpreterFactories.Where(x => x.Configuration.Id == PythonVersion.Id).FirstOrDefault(); Assert.IsNotNull(fact, "Project does not contain expected interpreter"); projectNode.ActiveInterpreter = fact; dteProject.Save(); }
public void AddReferenceAndBuild() { using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\ProjectReference.sln"); TargetInfo ti = TargetInfo.GetTargetInfo(); // Wait for solution to load... for (int i = 0; i < 40 && app.Dte.Solution.Projects.Count == 0; i++) { System.Threading.Thread.Sleep(250); } Assert.IsFalse(0 == app.Dte.Solution.Projects.Count); // Set platform foreach (SolutionConfiguration2 solConfiguration2 in app.Dte.Solution.SolutionBuild.SolutionConfigurations) { if (String.Equals(solConfiguration2.PlatformName, ti.Plat, StringComparison.Ordinal)) { solConfiguration2.Activate(); break; } } // Build project app.Dte.Solution.SolutionBuild.Build(true); // Check for C# reference in the appxrecipe file string appxRecipePath = string.Format("{0}\\TestData\\ProjectReference\\bin\\{1}\\Debug\\ProjectReference.build.appxrecipe", Directory.GetCurrentDirectory(), ti.Plat); Assert.AreEqual(true, File.Exists(appxRecipePath), string.Format("ProjectReference.build.appxrecipe is missing from bin output folder")); string appxRecipeStr = File.ReadAllText(appxRecipePath); Assert.IsTrue(appxRecipeStr.Contains("CSComponent")); } }
private static void CloudProjectTest(string roleType, bool openServiceDefinition) { Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType); using (var app = new VisualStudioApp()) using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"))) { app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3); var ccproj = app.Dte.Solution.Projects.Cast<EnvDTE.Project>().FirstOrDefault(p => p.Name == "CloudProject"); Assert.IsNotNull(ccproj); if (openServiceDefinition) { var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open(); wnd.Activate(); app.OnDispose(() => wnd.Close()); } IVsHierarchy hier; var sln = app.GetService<IVsSolution>(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier)); app.ServiceProvider.GetUIThread().Invoke(() => NodejsProject.UpdateServiceDefinition( hier, roleType, roleType + "Role1", new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)app.Dte) ) ); var doc = new XmlDocument(); for (int retries = 5; retries > 0; --retries) { try { doc.Load(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef")); break; } catch (IOException ex) { Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex); } catch (XmlException) { var copyTo = TestData.GetPath(@"TestData\CloudProject\CloudProject\" + Path.GetRandomFileName()); File.Copy(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"), copyTo); Console.WriteLine("Copied file to " + copyTo); throw; } Thread.Sleep(100); } var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); doc.Save(Console.Out); var nav = doc.CreateNavigator(); if (roleType == "Web") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='setup_web.cmd > log.txt']", ns )); } else if (roleType == "Worker") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='setup_worker.cmd > log.txt']", ns )); Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='node.cmd .\\server.js']", ns )); } } }
public void DjangoProjectWithSubdirectory() { using (var app = new VisualStudioApp()) { var project = app.OpenProject("TestData\\DjangoProjectWithSubDirectory.sln"); var pyProj = (IPythonProject2)project.GetPythonProject(); var dsm = pyProj.Site.GetUIThread().Invoke(() => pyProj.GetProperty("DjangoSettingsModule")); Assert.AreEqual("config.settings", dsm); var workDir = pyProj.Site.GetUIThread().Invoke(() => pyProj.GetWorkingDirectory()).TrimEnd('\\'); Assert.AreEqual(TestData.GetPath("TestData\\DjangoProjectWithSubDirectory\\project"), workDir, true); var cmd = pyProj.FindCommand("DjangoCollectStaticCommand"); pyProj.Site.GetUIThread().Invoke(() => { Assert.IsTrue(cmd.CanExecute(pyProj), "Cannot execute DjangoCollectStaticCommand"); cmd.Execute(pyProj); }); // The static dir is 'test_static', check that the admin files // are copied into there. Assert.IsTrue(Directory.Exists(Path.Combine(workDir, "test_static", "admin")), "admin static directory was not created"); Assert.IsTrue(File.Exists(Path.Combine(workDir, "test_static", "admin", "css", "base.css")), "admin static files were not copied"); } }
public void ClientServerIntelliSenseModes() { string solutionLabel = "Solution 'ClientServerCode' (1 project)", projectLabel = "ClientServerCode", nodeDirectoryLabel = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node), nodeSubDirectoryLabel = NodejsFolderNode.AppendLabel("NodeSubDirectory", FolderContentType.Node), browserDirectoryLabel = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser), emptyBrowserSubDirectoryLabel = "BrowserSubDirectory", browserSubDirectoryLabel = NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Browser), mixedDirectoryLabel = NodejsFolderNode.AppendLabel("MixedDirectory", FolderContentType.Mixed), mixedDirectoryBrowserDirectoryLabel = NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Browser), mixedDirectoryNodeDirectoryLabel = NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node), browserCodeLabel = "browserCode.js", mixedDirectoryRenamedLabel = NodejsFolderNode.AppendLabel("MixedDirectoryRenamed", FolderContentType.Mixed); using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\ClientServerCode\ClientServerCode.sln"); using (new NodejsOptionHolder(NodejsPackage.Instance.GeneralOptionsPage, "ShowBrowserAndNodeLabels", true)) { // Wait until project is loaded var solutionExplorer = app.OpenSolutionExplorer(); solutionExplorer.WaitForItem( solutionLabel, projectLabel, "app.js"); var nodejsProject = app.GetProject("ClientServerCode").GetNodejsProject(); var projectNode = solutionExplorer.WaitForItem( solutionLabel, projectLabel); var browserDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, browserDirectoryLabel ); Assert.IsNotNull( browserDirectory, "Browser directories should be labeled as such. Could not find " + browserDirectoryLabel); var browserSubDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, browserDirectoryLabel, emptyBrowserSubDirectoryLabel ); Assert.IsNotNull( browserSubDirectory, "Project initialization: could not find " + emptyBrowserSubDirectoryLabel); var nodeDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, nodeDirectoryLabel ); Assert.IsNotNull( nodeDirectory, "Node directories should be labeled as such. Could not find " + nodeDirectoryLabel); var nodeSubDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, nodeDirectoryLabel, nodeSubDirectoryLabel ); Assert.IsNotNull( nodeSubDirectory, "Project initialization: could not find " + nodeSubDirectoryLabel); projectNode.Select(); using (var newItem = NewItemDialog.FromDte(app)) { newItem.FileName = "newItem.js"; newItem.OK(); } Assert.AreEqual( "Compile", nodejsProject.GetItemType("newItem.js"), "Top level files should be set to item type 'Compile'"); Keyboard.Type("process."); Keyboard.Type(Keyboard.CtrlSpace.ToString()); using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"newItem.js")).WaitForSession<ICompletionSession>()) { var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText); Assert.IsTrue( completions.Contains("env"), "New documents of the node type should open with default VS editor" ); } browserSubDirectory.Select(); using (var newBrowserItem = NewItemDialog.FromDte(app)) { newBrowserItem.FileName = "newBrowserItem.js"; newBrowserItem.OK(); } Keyboard.Type("document."); System.Threading.Thread.Sleep(2000); Keyboard.Type(Keyboard.CtrlSpace.ToString()); using (var session = app.GetDocument(Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\browserSubDirectory\newBrowserItem.js")).WaitForSession<ICompletionSession>()) { var completions = session.Session.CompletionSets.First().Completions.Select(x => x.InsertionText); Assert.IsTrue( completions.Contains("body"), "New documents of the browser type should open with default VS editor" ); } browserSubDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, browserDirectoryLabel, browserSubDirectoryLabel ); Assert.IsNotNull( browserSubDirectory, "Folder label was not updated to " + browserSubDirectoryLabel); var newBrowserItemFile = solutionExplorer.WaitForItem( solutionLabel, projectLabel, browserDirectoryLabel, browserSubDirectoryLabel, "newBrowserItem.js" ); Assert.AreEqual( "Content", nodejsProject.GetItemType(@"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js"), "Adding a javascript file to a 'browser' directory should set the item type as Content."); var mixedDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, mixedDirectoryLabel ); Assert.IsNotNull( mixedDirectory, "Folder with mixed browser/node content should be specified as such. Could not find: " + mixedDirectoryLabel); nodeDirectory.Select(); using (var newTypeScriptItem = NewItemDialog.FromDte(app)) { newTypeScriptItem.FileName = "newTypeScriptItem.ts"; newTypeScriptItem.OK(); } Assert.AreEqual( "TypeScriptCompile", nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"), "Non-javascript files should retain their content type."); var newBrowserItemNode = nodejsProject.FindNodeByFullPath( Path.Combine(nodejsProject.ProjectHome, @"BrowserDirectory\BrowserSubDirectory\newBrowserItem.js") ); newBrowserItemNode.ExcludeFromProject(); var excludedBrowserItem = solutionExplorer.WaitForItem( solutionLabel, projectLabel, browserDirectoryLabel, emptyBrowserSubDirectoryLabel ); Assert.IsNotNull( emptyBrowserSubDirectoryLabel, "Label should be removed when there are no included javascript files the directory. Could not find " + emptyBrowserSubDirectoryLabel); (newBrowserItemNode as NodejsFileNode).IncludeInProject(false); var includedBrowserItem = solutionExplorer.WaitForItem( solutionLabel, projectLabel, browserDirectoryLabel, browserSubDirectoryLabel ); Assert.IsNotNull( includedBrowserItem, "Label should be added when a javascript file is included in the directory. Could not find " + browserSubDirectoryLabel); var mixedDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath( Path.Combine(nodejsProject.ProjectHome, @"MixedDirectory\")); System.Threading.Thread.Sleep(2000); mixedDirectory.Select(); Keyboard.PressAndRelease(Key.F2); Keyboard.Type("MixedDirectoryRenamed"); Keyboard.PressAndRelease(Key.Enter); mixedDirectoryNode.ExpandItem(EXPANDFLAGS.EXPF_ExpandFolderRecursively); var renamedMixedDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, mixedDirectoryRenamedLabel, mixedDirectoryBrowserDirectoryLabel, browserCodeLabel ); Assert.IsNotNull( renamedMixedDirectory, "Renaming mixed directory failed: could not find " + browserCodeLabel); newBrowserItemNode.ItemNode.ItemTypeName = "Compile"; var nodeBrowserSubDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed), NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node) ); Assert.IsNotNull( nodeBrowserSubDirectory, "Changing the item type should change the directory label. Could not find " + NodejsFolderNode.AppendLabel("BrowserSubDirectory", FolderContentType.Node) ); var nodeDirectoryNode = app.GetProject("ClientServerCode").GetNodejsProject().FindNodeByFullPath( Path.Combine(app.GetProject("ClientServerCode").GetNodejsProject().ProjectHome, @"NodeDirectory\")); (nodeDirectoryNode as NodejsFolderNode).SetItemTypeRecursively(VSLangProj.prjBuildAction.prjBuildActionContent); Assert.AreEqual( "Content", nodejsProject.GetItemType(@"NodeDirectory\NodeSubDirectory\nodeCode.js"), "nodeCode.js file should be marked as content after recursively setting directory contents as Content." ); Assert.AreEqual( "TypeScriptCompile", nodejsProject.GetItemType(@"NodeDirectory\newTypeScriptItem.ts"), "Only javascript file item types should change when marking item types recursively." ); var fromPoint = solutionExplorer.WaitForItem( solutionLabel, projectLabel, mixedDirectoryRenamedLabel, mixedDirectoryNodeDirectoryLabel ).GetClickablePoint(); var toPoint = solutionExplorer.WaitForItem( solutionLabel, projectLabel, mixedDirectoryRenamedLabel, mixedDirectoryBrowserDirectoryLabel ).GetClickablePoint(); Mouse.MoveTo(fromPoint); Mouse.Down(MouseButton.Left); Mouse.MoveTo(toPoint); Mouse.Up(MouseButton.Left); var draggedDirectory = solutionExplorer.WaitForItem( solutionLabel, projectLabel, mixedDirectoryRenamedLabel, NodejsFolderNode.AppendLabel("BrowserDirectory", FolderContentType.Mixed), NodejsFolderNode.AppendLabel("NodeDirectory", FolderContentType.Node) ); Assert.IsNotNull( draggedDirectory, "Labels not properly updated after dragging and dropping directory." ); } } }
public void ErrorListAndTaskListAreClearedWhenProjectWithMultipleFilesIsUnloaded() { using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\ErrorProjectMultipleFiles.sln"); app.WaitForTaskListItems(typeof(SVsErrorList), 14); app.WaitForTaskListItems(typeof(SVsTaskList), 4); var solutionService = app.GetService<IVsSolution>(typeof(SVsSolution)); Assert.IsNotNull(solutionService); IVsHierarchy selectedHierarchy; ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy)); Assert.IsNotNull(selectedHierarchy); Console.WriteLine("Unloading project"); ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0)); app.WaitForTaskListItems(typeof(SVsErrorList), 0); app.WaitForTaskListItems(typeof(SVsTaskList), 0); } }
public void ErrorListAndTaskListAreClearedWhenProjectIsDeleted() { using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\ErrorProjectDelete.sln"); app.WaitForTaskListItems(typeof(SVsErrorList), 7); app.WaitForTaskListItems(typeof(SVsTaskList), 2); Console.WriteLine("Deleting project"); app.Dte.Solution.Remove(project); app.WaitForTaskListItems(typeof(SVsErrorList), 0); app.WaitForTaskListItems(typeof(SVsTaskList), 0); } }
public void CommentTaskList() { using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\ErrorProject.sln"); var projectNode = project.GetPythonProject(); var expectedDocument = Path.Combine(projectNode.ProjectHome, "Program.py"); var expectedCategory = VSTASKCATEGORY.CAT_COMMENTS; var expectedItems = new[] { new TaskItemInfo(expectedDocument, 4, 5, VSTASKPRIORITY.TP_NORMAL, expectedCategory, null, "TODO 123"), new TaskItemInfo(expectedDocument, 5, 0, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "456 UnresolvedMergeConflict"), }; TaskListTest(app, typeof(SVsTaskList), expectedItems, navigateTo: new[] { 0, 1 }); } }
public void ErrorList() { using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\ErrorProject.sln"); var projectNode = project.GetPythonProject(); var expectedDocument = Path.Combine(projectNode.ProjectHome, "Program.py"); var expectedCategory = VSTASKCATEGORY.CAT_BUILDCOMPILE; var expectedItems = new[] { new TaskItemInfo(expectedDocument, 2, 8, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected indent"), new TaskItemInfo(expectedDocument, 2, 13, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected token '('"), new TaskItemInfo(expectedDocument, 2, 30, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected token ')'"), new TaskItemInfo(expectedDocument, 2, 31, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected token '<newline>'"), new TaskItemInfo(expectedDocument, 3, 0, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected token '<NL>'"), new TaskItemInfo(expectedDocument, 3, 0, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected token '<dedent>'"), new TaskItemInfo(expectedDocument, 4, 0, VSTASKPRIORITY.TP_HIGH, expectedCategory, null, "unexpected token 'pass'"), }; TaskListTest(app, typeof(SVsErrorList), expectedItems, navigateTo: new[] { 0, 1, 2, 3, 4, 5, 6 }); } }
//TODO: TestAttachThreadsMakingProgress // See workitem http://pytools.codeplex.com/workitem/456 #region Helper methods private static SD.Process OpenSolutionAndLaunchFile(VisualStudioApp app, string debugSolution, string startFile, string interpreterArgs, string programArgs) { var project = app.OpenProject(debugSolution, startFile); return LaunchFileFromProject(app, project, startFile, interpreterArgs, programArgs); }
public void Breakpoint() { using (var app = new VisualStudioApp()) { var project = app.OpenProject(@"TestData\HelloWorld.sln"); TargetInfo ti = GetTargetInfo(); // Wait for solution to load... for (int i = 0; i < 40 && app.Dte.Solution.Projects.Count == 0; i++) { System.Threading.Thread.Sleep(250); } Assert.IsFalse(0 == app.Dte.Solution.Projects.Count); // Set platform foreach (SolutionConfiguration2 solConfiguration2 in app.Dte.Solution.SolutionBuild.SolutionConfigurations) { if(String.Equals(solConfiguration2.PlatformName, ti.Plat, StringComparison.Ordinal)) { solConfiguration2.Activate(); break; } } // Open project properties var item = app.SolutionExplorerTreeView.WaitForItem( "Solution '" + app.Dte.Solution.Projects.Item(1).Name + "' (1 project)", app.Dte.Solution.Projects.Item(1).Name ); AutomationWrapper.Select(item); app.Dte.ExecuteCommand("ClassViewContextMenus.ClassViewMultiselectProjectReferencesItems.Properties"); AutomationElement doc = null; for (int i = 0; i < 10; i++) { doc = app.GetDocumentTab("HelloWorld.njsproj"); if (doc != null) { break; } System.Threading.Thread.Sleep(1000); } Assert.IsNotNull(doc, "Failed to find project properties tab"); // Enter IP address of target machine var debuggerMachineName = new TextBox( new AutomationWrapper(doc).FindByAutomationId("_debuggerMachineName") ); debuggerMachineName.SetFocus(); Keyboard.ControlA(); Keyboard.Backspace(); Keyboard.Type(ti.IP); app.Dte.ExecuteCommand("File.SaveAll"); // Build project app.Dte.Solution.SolutionBuild.Build(true); // Add breakpoint app.Dte.Debugger.Breakpoints.Add(String.Empty, "server.js", 3, 1, String.Empty, dbgBreakpointConditionType.dbgBreakpointConditionTypeWhenTrue, String.Empty, String.Empty, 1, String.Empty, 1, dbgHitCountType.dbgHitCountTypeNone); // F5 app.Dte.ExecuteCommand("Debug.Start"); // Check that breakpoint is hit app.WaitForMode(dbgDebugMode.dbgBreakMode); Assert.IsTrue(app.Dte.ActiveDocument.Name.Contains("server.js")); Assert.IsTrue((app.Dte.ActiveDocument.Object("TextDocument") as TextDocument).Selection.ActivePoint.Line == 3); } }