Пример #1
0
        public void Breakpoint()
        {
            using (var app = new VisualStudioApp())
            {
                var project = app.OpenProject(@"TestData\HelloWorld.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;
                    }
                }

                // 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");
                    if (doc != null)
                    {
                        break;
                    }
                    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, 120);
                Assert.IsTrue(app.Dte.ActiveDocument.Name.Contains("server.js"));
                Assert.IsTrue((app.Dte.ActiveDocument.Object("TextDocument") as TextDocument).Selection.ActivePoint.Line == 3);
            }
        }