Example #1
0
        private static void ExceptionTest(VisualStudioApp app, string filename, string expectedTitle, string expectedDescription, string exceptionType, int expectedLine)
        {
            var debug3 = (Debugger3)app.Dte.Debugger;

            using (new DebuggingGeneralOptionsSetter(app.Dte, enableJustMyCode: true)) {
                OpenDebuggerProject(app, filename);

                var exceptionSettings = debug3.ExceptionGroups.Item("Python Exceptions");

                exceptionSettings.SetBreakWhenThrown(true, exceptionSettings.Item(exceptionType));

                app.Dte.ExecuteCommand("Debug.Start");
                WaitForMode(app, dbgDebugMode.dbgBreakMode);

                exceptionSettings.SetBreakWhenThrown(false, exceptionSettings.Item(exceptionType));
                exceptionSettings.SetBreakWhenThrown(true, exceptionSettings.Item(exceptionType));
                debug3.ExceptionGroups.ResetAll();

                var excepAdorner = app.WaitForExceptionAdornment();
                AutomationWrapper.DumpElement(excepAdorner.Element);

                Assert.AreEqual(expectedDescription, excepAdorner.Description.TrimEnd());
                Assert.AreEqual(expectedTitle, excepAdorner.Title.TrimEnd());

                Assert.AreEqual((uint)expectedLine, ((StackFrame2)debug3.CurrentThread.StackFrames.Item(1)).LineNumber);

                debug3.Go(WaitForBreakOrEnd: true);

                WaitForMode(app, dbgDebugMode.dbgDesignMode);
            }
        }
Example #2
0
        public AutomationElement this[Guid tabGuid]
        {
            get
            {
                var tabItem = FindByAutomationId("PropPage_" + tabGuid.ToString("n").ToLower());
                Assert.IsNotNull(tabItem, "Failed to find page");

                AutomationWrapper.DumpElement(tabItem);
                foreach (var p in tabItem.GetSupportedPatterns())
                {
                    Console.WriteLine("Supports {0}", p.ProgrammaticName);
                }

                try
                {
                    tabItem.GetInvokePattern().Invoke();
                }
                catch (InvalidOperationException)
                {
                    AutomationWrapper.DoDefaultAction(tabItem);
                }

                return(FindByAutomationId("PageHostingPanel"));
            }
        }
Example #3
0
        public void CopyFolderInToSelf()
        {
            using (var app = new PythonVisualStudioApp()) {
                app.OpenProject(@"TestData\HelloWorld2.sln", expectedProjects: 2);

                app.OpenSolutionExplorer();
                var window = app.SolutionExplorerTreeView;

                var folder = window.FindItem("Solution 'HelloWorld2' (2 projects)", "HelloWorld2", "TestFolder");
                AutomationWrapper.Select(folder);
                Keyboard.ControlC();

                try {
                    // Remove the destination folder in case a previous test has
                    // created it.
                    Directory.Delete(TestData.GetPath(@"TestData\HelloWorld2\TestFolder - Copy"), true);
                } catch {
                }

                var subItem = window.FindItem("Solution 'HelloWorld2' (2 projects)", "HelloWorld2", "TestFolder", "SubItem.py");
                AutomationWrapper.Select(subItem);
                Keyboard.ControlV();

                var item = window.WaitForItem("Solution 'HelloWorld2' (2 projects)", "HelloWorld2", "TestFolder - Copy", "SubItem.py");
                if (item == null)
                {
                    AutomationWrapper.DumpElement(window.Element);
                    Assert.Fail("Did not find TestFolder - Copy");
                }
            }
        }
Example #4
0
        public static OverwriteFileDialog Wait(VisualStudioApp app)
        {
            var hwnd = app.WaitForDialog();

            Assert.AreNotEqual(IntPtr.Zero, hwnd, "Did not find OverwriteFileDialog");
            var element = AutomationElement.FromHandle(hwnd);

            try
            {
                Assert.IsNotNull(element.FindFirst(
                                     TreeScope.Descendants,
                                     new PropertyCondition(AutomationElement.AutomationIdProperty, "_allItems")
                                     ), "Not correct dialog - missing '_allItems'");
                Assert.IsNotNull(element.FindFirst(
                                     TreeScope.Descendants,
                                     new PropertyCondition(AutomationElement.AutomationIdProperty, "_yes")
                                     ), "Not correct dialog - missing '_yes'");

                OverwriteFileDialog res = new OverwriteFileDialog(app, element);
                element = null;
                return(res);
            }
            finally
            {
                if (element != null)
                {
                    AutomationWrapper.DumpElement(element);
                }
            }
        }
Example #5
0
        private AutomationElement FindChildOfWorkspaceHelper(string[] path, bool assertOnFailure)
        {
            var projElement = Nodes.FirstOrDefault()?.Element;

            if (assertOnFailure)
            {
                AutomationWrapper.DumpElement(Element);
                Assert.IsNotNull(projElement, "Did not find solution explorer workspace root element");
            }

            if (projElement == null)
            {
                return(null);
            }

            var itemElement = path.Any() ? FindNode(
                projElement.FindAll(TreeScope.Children, Condition.TrueCondition),
                path,
                0
                ) : projElement;

            if (assertOnFailure)
            {
                AutomationWrapper.DumpElement(Element);
                Assert.IsNotNull(itemElement, string.Format("Did not find element <{0}>", string.Join("\\", path)));
            }
            return(itemElement);
        }
Example #6
0
 private static T Pattern <T>(this AutomationElement node, AutomationPattern pattern) where T : BasePattern
 {
     try
     {
         return((T)node.GetCurrentPattern(pattern));
     }
     catch (InvalidOperationException)
     {
         Console.WriteLine("{0} pattern is not supported by {1}.", pattern.ProgrammaticName, node.Current.Name);
         AutomationWrapper.DumpElement(node);
         throw;
     }
 }
Example #7
0
        private static void ExceptionTest(string filename, string expectedTitle, string expectedDescription, string exceptionType, int expectedLine)
        {
            using (var app = new VisualStudioApp()) {
                var  debug3     = (Debugger3)app.Dte.Debugger;
                bool justMyCode = (bool)app.Dte.Properties["Debugging", "General"].Item("EnableJustMyCode").Value;
                app.Dte.Properties["Debugging", "General"].Item("EnableJustMyCode").Value = true;
                try {
                    OpenDebuggerProject(app, filename);

                    var exceptionSettings = debug3.ExceptionGroups.Item("Python Exceptions");

                    exceptionSettings.SetBreakWhenThrown(true, exceptionSettings.Item(exceptionType));

                    app.Dte.ExecuteCommand("Debug.Start");
                    WaitForMode(app, dbgDebugMode.dbgBreakMode);

                    exceptionSettings.SetBreakWhenThrown(false, exceptionSettings.Item(exceptionType));
                    exceptionSettings.SetBreakWhenThrown(true, exceptionSettings.Item(exceptionType));
                    debug3.ExceptionGroups.ResetAll();

                    var excepDialog = app.WaitForException();
                    AutomationWrapper.DumpElement(excepDialog.Element);

                    Assert.AreEqual(expectedDescription, excepDialog.Description);
                    Assert.AreEqual(expectedTitle, excepDialog.Title);

                    excepDialog.Cancel();

                    Assert.AreEqual((uint)expectedLine, ((StackFrame2)debug3.CurrentThread.StackFrames.Item(1)).LineNumber);

                    debug3.Go(WaitForBreakOrEnd: true);

                    WaitForMode(app, dbgDebugMode.dbgDesignMode);
                } finally {
                    app.Dte.Properties["Debugging", "General"].Item("EnableJustMyCode").Value = true;
                }
            }
        }
Example #8
0
        /// <summary>
        /// Dumps the current top-level window in VS
        /// </summary>
        public static void DumpVS()
        {
            var sp = ServiceProvider.GlobalProvider;

            if (sp == null)
            {
                return;
            }

            IVsUIShell uiShell = sp.GetService(typeof(IVsUIShell)) as IVsUIShell;

            uiShell.GetDialogOwnerHwnd(out IntPtr hwnd);
            AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));

            // if we have a dialog open dump the main VS window too
            var mainHwnd = new IntPtr(((EnvDTE.DTE)sp.GetService(typeof(EnvDTE.DTE))).MainWindow.HWnd);

            if (mainHwnd != hwnd)
            {
                Console.WriteLine("VS: ");
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(mainHwnd));
            }
        }
Example #9
0
        private AutomationElement FindChildOfProjectHelper(EnvDTE.Project project, string[] path, bool assertOnFailure)
        {
            var sln   = project.DTE.Solution;
            int count = sln.Projects.OfType <EnvDTE.Project>().Count(p =>
            {
                try
                {
                    return(!string.IsNullOrEmpty(p.FullName));
                }
                catch (Exception)
                {
                    return(false);
                }
            });
            var slnLabel = string.Format(
                "Solution '{0}' ({1} of {1} project{2})",
                Path.GetFileNameWithoutExtension(sln.FullName),
                count,
                count == 1 ? "" : "s"
                );

            var slnElements = Element.FindAll(TreeScope.Children, new PropertyCondition(
                                                  AutomationElement.NameProperty, slnLabel
                                                  ));
            int slnCount = slnElements.OfType <AutomationElement>().Count();

            if (assertOnFailure)
            {
                Assert.AreEqual(1, slnCount, string.Format("Did not find single node <{0}>", slnLabel));
            }
            else if (slnCount != 1)
            {
                return(null);
            }
            var slnElement = slnElements.Cast <AutomationElement>().Single();

            var projLabel    = project.Name;
            var projElements = slnElement.FindAll(TreeScope.Children, new PropertyCondition(
                                                      AutomationElement.NameProperty, projLabel
                                                      ));
            int projCount = projElements.OfType <AutomationElement>().Count();

            if (assertOnFailure)
            {
                Assert.AreEqual(1, projCount, string.Format("Did not find single node <{0}>", projLabel));
            }
            else if (projCount != 1)
            {
                return(null);
            }
            var projElement = projElements.Cast <AutomationElement>().Single();

            var itemElement = path.Any() ? FindNode(
                projElement.FindAll(TreeScope.Children, Condition.TrueCondition),
                path,
                0
                ) : projElement;

            if (assertOnFailure)
            {
                AutomationWrapper.DumpElement(Element);
                Assert.IsNotNull(itemElement, string.Format("Did not find element <{0}\\{1}\\{2}>", slnLabel, projLabel, string.Join("\\", path)));
            }
            return(itemElement);
        }