Exemple #1
0
 public void Paste(string text)
 {
     Invoke(() => {
         Clipboard.SetText(text, TextDataFormat.Text);
     });
     _app.ExecuteCommand("Edit.Paste");
 }
Exemple #2
0
        private static void RemoveSmartTagTest(VisualStudioApp app, string filename, int line, int column, bool allScopes, string expectedText)
        {
            var project = app.OpenProject(app.CopyProjectForTest(@"TestData\RemoveImport.sln"));
            var item    = project.ProjectItems.Item(filename);
            var window  = item.Open();

            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);

            VsProjectAnalyzer analyzer = null;

            doc.InvokeTask(async() => {
                var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                doc.TextView.Caret.MoveTo(point);
                analyzer = await doc.WaitForAnalyzerAtCaretAsync();
            });

            Assert.IsNotNull(analyzer, "Failed to get analyzer");
            analyzer.WaitForCompleteAnalysis(_ => true);

            if (allScopes)
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
            }
            else
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
            }

            doc.WaitForText(expectedText);
        }
Exemple #3
0
        private static void RemoveLightBulbTest(VisualStudioApp app, string filename, int line, int column, bool allScopes, string expectedText)
        {
            var project = app.OpenProject(app.CopyProjectForTest(@"TestData\RemoveImport.sln"));
            var item    = project.ProjectItems.Item(filename);
            var window  = item.Open();

            window.Activate();

            var doc = app.GetDocument(item.Document.FullName);

            doc.InvokeTask(async() => {
                var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                doc.TextView.Caret.MoveTo(point);

                // Note that this waits for language server to be up and running
                // but that doesn't mean the quick actions are ready for that document
                // so the test will need to wait/try again until the correct results
                // are in or until a predetermined timeout.
                await doc.WaitForLanguageServerInitializedAtCaretAsync();
            });

            if (allScopes)
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
            }
            else
            {
                app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
            }

            doc.WaitForText(expectedText);
        }
Exemple #4
0
        public void CutPasteRelocatedTest(VisualStudioApp app)
        {
            var sln    = app.CopyProjectForTest(@"TestData\CutPasteRelocatedTest.sln");
            var slnDir = PathUtils.GetParent(sln);

            FileUtils.CopyDirectory(TestData.GetPath("TestData", "CutPasteRelocatedTest"), Path.Combine(slnDir, "CutPasteRelocatedTest"));
            app.OpenProject(sln);

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

            var folder = window.FindItem("Solution 'CutPasteRelocatedTest' (1 project)", "CutPasteTest", "TestFolder", "SubItem.py");

            AutomationWrapper.Select(folder);
            app.ExecuteCommand("Edit.Cut");

            var projectItem = window.FindItem("Solution 'CutPasteRelocatedTest' (1 project)", "CutPasteTest");

            AutomationWrapper.Select(projectItem);
            app.ExecuteCommand("Edit.Paste");

            Assert.IsNotNull(window.WaitForItem("Solution 'CutPasteRelocatedTest' (1 project)", "CutPasteTest", "SubItem.py"));

            app.Dte.Solution.Close(true);
            // Ensure file was moved and the path was updated correctly.
            var project = app.OpenProject(sln);

            foreach (var item in project.ProjectItems.OfType <OAFileItem>())
            {
                Assert.IsTrue(File.Exists((string)item.Properties.Item("FullPath").Value), (string)item.Properties.Item("FullPath").Value);
            }
        }
Exemple #5
0
        private static void RemoveSmartTagTest(string filename, int line, int column, bool allScopes, string expectedText)
        {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\RemoveImport.sln");
                var item    = project.ProjectItems.Item(filename);
                var window  = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                doc.Invoke(() => {
                    var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                    doc.TextView.Caret.MoveTo(point);
                });

                if (allScopes)
                {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
                }
                else
                {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
                }

                doc.WaitForText(expectedText);
            }
        }
Exemple #6
0
        public void AddCloudProject()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "AddCloudProject"
                    );
                app.SolutionExplorerTreeView.SelectProject(project);

                try {
                    app.ExecuteCommand("Project.ConverttoMicrosoftAzureCloudServiceProject");
                } catch (Exception ex1) {
                    try {
                        app.ExecuteCommand("Project.ConverttoWindowsAzureCloudServiceProject");
                    } catch (Exception ex2) {
                        Console.WriteLine("Unable to execute Project.ConverttoWindowsAzureCloudServiceProject.\r\n{0}", ex2);
                        try {
                            app.ExecuteCommand("Project.AddWindowsAzureCloudServiceProject");
                        } catch (Exception ex3) {
                            Console.WriteLine("Unable to execute Project.AddWindowsAzureCloudServiceProject.\r\n{0}", ex3);
                            throw ex1;
                        }
                    }
                }

                var res = app.SolutionExplorerTreeView.WaitForItem(
                    "Solution '" + app.Dte.Solution.Projects.Item(1).Name + "' (2 projects)",
                    app.Dte.Solution.Projects.Item(1).Name + ".Azure"
                    );
                Assert.IsNotNull(res);
            }
        }
Exemple #7
0
        public void TestPublishFtp()
        {
            using (var app = new VisualStudioApp()) {
                var    project = app.OpenProject(@"TestData\HelloWorld.sln");
                string subDir  = Guid.NewGuid().ToString();
                string url     = TestFtpUrl + "/" + subDir;
                project.Properties.Item("PublishUrl").Value = url;
                app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
                string dir = Path.Combine(FtpValidateDir, subDir);
                Debug.WriteLine(dir);

                app.OpenSolutionExplorer().SelectProject(project);

                app.ExecuteCommand("Build.PublishSelection");
                System.Threading.Thread.Sleep(2000);
                var files = WaitForFiles(dir);
                Assert.AreEqual(1, files.Length);
                Assert.AreEqual("Program.py", Path.GetFileName(files[0]));

                // do it again w/ the directories already existing
                File.Delete(files[0]);

                app.OpenSolutionExplorer().SelectProject(project);
                app.ExecuteCommand("Build.PublishSelection");
                files = WaitForFiles(dir);
                Assert.AreEqual(1, files.Length);
                Assert.AreEqual("Program.py", Path.GetFileName(files[0]));

                Directory.Delete(dir, true);
            }
        }
Exemple #8
0
        public void AddCloudProject() {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.DjangoWebProjectTemplate,
                    TestData.GetTempPath(),
                    "AddCloudProject"
                );
                app.SolutionExplorerTreeView.SelectProject(project);

                try {
                    app.ExecuteCommand("Project.ConverttoMicrosoftAzureCloudServiceProject");
                } catch (Exception ex1) {
                    try {
                        app.ExecuteCommand("Project.ConverttoWindowsAzureCloudServiceProject");
                    } catch (Exception ex2) {
                        Console.WriteLine("Unable to execute Project.ConverttoWindowsAzureCloudServiceProject.\r\n{0}", ex2);
                        try {
                            app.ExecuteCommand("Project.AddWindowsAzureCloudServiceProject");
                        } catch (Exception ex3) {
                            Console.WriteLine("Unable to execute Project.AddWindowsAzureCloudServiceProject.\r\n{0}", ex3);
                            throw ex1;
                        }
                    }
                }

                var res = app.SolutionExplorerTreeView.WaitForItem(
                    "Solution '" + app.Dte.Solution.Projects.Item(1).Name + "' (2 projects)",
                    app.Dte.Solution.Projects.Item(1).Name + ".Azure"
                );
                Assert.IsNotNull(res);
            }
        }
Exemple #9
0
        public void WebProjectEnvironment()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\CheckEnvironment.sln");

                var proj = project.GetCommonProject() as IPythonProject2;
                Assert.IsNotNull(proj);

                var outFile = Path.Combine(Path.GetDirectoryName(project.FullName), "output.txt");
                if (File.Exists(outFile))
                {
                    File.Delete(outFile);
                }

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    proj.SetProperty("CommandLineArguments", '"' + outFile + '"');
                    proj.SetProperty("Environment", "FOB=123\nOAR=456\r\nBAZ=789");
                });

                app.ExecuteCommand("Debug.StartWithoutDebugging");

                for (int retries = 10; retries > 0 && !File.Exists(outFile); --retries)
                {
                    Thread.Sleep(300);
                }

                Assert.AreEqual("FOB=123\r\nOAR=456\r\nBAZ=789", File.ReadAllText(outFile).Trim());
            }
        }
Exemple #10
0
 /// <summary>
 /// Start without debugging, no script.
 /// </summary>
 public void StartWithoutDebuggingNoScript(VisualStudioApp app, DotNotWaitOnNormalExit optionSetter)
 {
     try {
         app.ExecuteCommand("Python.StartWithoutDebugging");
     } catch (COMException e) {
         // Requires an opened python file with focus
         Assert.IsTrue(e.ToString().Contains("is not available"));
     }
 }
Exemple #11
0
        public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode)
        {
            string description = null;

            if (Version.IsCPython)
            {
                description = string.Format("{0} {1}",
                                            Version.Isx64 ? "Python 64-bit" : "Python 32-bit",
                                            Version.Version.ToVersion()
                                            );
            }
            else if (Version.IsIronPython)
            {
                description = string.Format("{0} {1}",
                                            Version.Isx64 ? "IronPython 64-bit" : "IronPython",
                                            Version.Version.ToVersion()
                                            );
            }
            Assert.IsNotNull(description, "Unknown interpreter");

            var automation  = (IVsPython)app.Dte.GetObject("VsPython");
            var options     = (IPythonOptions)automation;
            var replOptions = options.Interactive;

            Assert.IsNotNull(replOptions, "Could not find options for " + description);

            var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;

            app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
            options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord;

            bool success = false;

            for (int retries = 1; retries < 20; ++retries)
            {
                try {
                    app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\"");
                    success = true;
                    break;
                } catch (AggregateException) {
                }
                app.DismissAllDialogs();
                app.SetFocus();
                Thread.Sleep(retries * 100);
            }
            Assert.IsTrue(success, "Unable to open " + description + " through DTE");
            var interpreters = app.ComponentModel.GetService <IInterpreterRegistryService>();
            var replId       = PythonReplEvaluatorProvider.GetEvaluatorId(
                interpreters.FindConfiguration(Version.Id)
                );

            return(app.ServiceProvider.GetUIThread().Invoke(() => {
                var provider = app.ComponentModel.GetService <InteractiveWindowProvider>();
                return (ToolWindowPane)provider.OpenOrCreate(replId);
            }));
        }
        public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode) {
            string description = null;
            if (Version.IsCPython) {
                description = string.Format("{0} {1}",
                    Version.Isx64 ? CPythonInterpreterFactoryConstants.Description64 : CPythonInterpreterFactoryConstants.Description32,
                    Version.Version.ToVersion()
                );
            } else if (Version.IsIronPython) {
                description = string.Format("{0} {1}",
                    Version.Isx64 ? "IronPython 64-bit" : "IronPython",
                    Version.Version.ToVersion()
                );
            }
            Assert.IsNotNull(description, "Unknown interpreter");

            var automation = (IVsPython)app.Dte.GetObject("VsPython");
            var options = (IPythonOptions)automation;
            var replOptions = options.GetInteractiveOptions(description);
            Assert.IsNotNull(replOptions, "Could not find options for " + description);

            replOptions.InlinePrompts = InlinePrompts;
            replOptions.UseInterpreterPrompts = UseInterpreterPrompts;
            replOptions.PrimaryPrompt = PrimaryPrompt;
            replOptions.SecondaryPrompt = SecondaryPrompt;
            replOptions.EnableAttach = EnableAttach;

            var oldExecutionMode = replOptions.ExecutionMode;
            app.OnDispose(() => replOptions.ExecutionMode = oldExecutionMode);
            replOptions.ExecutionMode = executionMode;

            var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;
            app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
            options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord;

            bool success = false;
            for (int retries = 1; retries < 20; ++retries) {
                try {
                    app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\"");
                    success = true;
                    break;
                } catch (AggregateException) {
                }
                app.DismissAllDialogs();
                app.SetFocus();
                Thread.Sleep(retries * 100);
            }
            Assert.IsTrue(success, "Unable to open " + description + " through DTE");
            var interpreters = app.ComponentModel.GetService<IInterpreterOptionsService>();
            var replId = PythonReplEvaluatorProvider.GetReplId(
                interpreters.FindInterpreter(Version.Id, Version.Version.ToVersion())
            );

            var provider = app.ComponentModel.GetService<InteractiveWindowProvider>();
            return (ToolWindowPane)provider.FindReplWindow(replId);
        }
Exemple #13
0
 private static void DoFormatDocument(VisualStudioApp app)
 {
     try {
         Task.Factory.StartNew(() => {
             for (int i = 0; i < 3; i++)
             {
                 try {
                     // wait for the command to become available if it's not already
                     app.ExecuteCommand("Edit.FormatDocument");
                     return;
                 } catch {
                     System.Threading.Thread.Sleep(1000);
                 }
             }
             throw new Exception();
         }).Wait();
     } catch {
         Assert.Fail("Failed to format document");
     }
 }
Exemple #14
0
        public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode)
        {
            string description = null;

            if (Version.IsCPython)
            {
                description = string.Format("{0} {1}",
                                            Version.Isx64 ? CPythonInterpreterFactoryConstants.Description64 : CPythonInterpreterFactoryConstants.Description32,
                                            Version.Version.ToVersion()
                                            );
            }
            else if (Version.IsIronPython)
            {
                description = string.Format("{0} {1}",
                                            Version.Isx64 ? "IronPython 64-bit" : "IronPython",
                                            Version.Version.ToVersion()
                                            );
            }
            Assert.IsNotNull(description, "Unknown interpreter");

            var automation  = (IVsPython)app.Dte.GetObject("VsPython");
            var options     = (IPythonOptions)automation;
            var replOptions = options.GetInteractiveOptions(description);

            Assert.IsNotNull(replOptions, "Could not find options for " + description);

            replOptions.InlinePrompts         = InlinePrompts;
            replOptions.UseInterpreterPrompts = UseInterpreterPrompts;
            replOptions.PrimaryPrompt         = PrimaryPrompt;
            replOptions.SecondaryPrompt       = SecondaryPrompt;
            replOptions.EnableAttach          = EnableAttach;

            var oldExecutionMode = replOptions.ExecutionMode;

            app.OnDispose(() => replOptions.ExecutionMode = oldExecutionMode);
            replOptions.ExecutionMode = executionMode;

            var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;

            app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
            options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord;

            bool success = false;

            for (int retries = 1; retries < 20; ++retries)
            {
                try {
                    app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\"");
                    success = true;
                    break;
                } catch (AggregateException) {
                }
                app.DismissAllDialogs();
                app.SetFocus();
                Thread.Sleep(retries * 100);
            }
            Assert.IsTrue(success, "Unable to open " + description + " through DTE");
            var interpreters = app.ComponentModel.GetService <IInterpreterOptionsService>();
            var replId       = PythonReplEvaluatorProvider.GetReplId(
                interpreters.FindInterpreter(Version.Id, Version.Version.ToVersion())
                );

            var provider = app.ComponentModel.GetService <InteractiveWindowProvider>();

            return((ToolWindowPane)provider.FindReplWindow(replId));
        }
Exemple #15
0
        public void CutPasteTest() {
            using (var app = new VisualStudioApp()) {
                app.OpenProject(@"TestData\CutPasteRelocatedTest.sln");

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

                var folder = window.FindItem("Solution 'CutPasteRelocatedTest' (1 project)", "CutPasteTest", "TestFolder", "SubItem.py");
                AutomationWrapper.Select(folder);
                app.ExecuteCommand("Edit.Cut");

                var projectItem = window.FindItem("Solution 'CutPasteRelocatedTest' (1 project)", "CutPasteTest");
                AutomationWrapper.Select(projectItem);
                app.ExecuteCommand("Edit.Paste");

                Assert.IsNotNull(window.WaitForItem("Solution 'CutPasteRelocatedTest' (1 project)", "CutPasteTest", "SubItem.py"));

                app.Dte.Solution.Close(true);
                // Ensure file was moved and the path was updated correctly.
                var project = app.OpenProject(@"TestData\CutPasteRelocatedTest.sln");
                foreach (var item in project.ProjectItems.OfType<OAFileItem>()) {
                    Assert.IsTrue(File.Exists((string)item.Properties.Item("FullPath").Value), (string)item.Properties.Item("FullPath").Value);
                }
            }
        }
Exemple #16
0
        public void ObjectBrowserNavigationTest()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\MultiModule.sln");
                System.Threading.Thread.Sleep(1000);

                app.OpenObjectBrowser();
                var objectBrowser = app.ObjectBrowser;
                objectBrowser.EnsureLoaded();

                int nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count;
                Assert.AreEqual(1, nodeCount, "Node count: " + nodeCount.ToString());

                objectBrowser.TypeBrowserPane.Nodes[0].ExpandCollapse();
                System.Threading.Thread.Sleep(1000);

                nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count;
                Assert.AreEqual(3, nodeCount, "Node count: " + nodeCount.ToString());

                string str = objectBrowser.TypeBrowserPane.Nodes[1].Value;
                Assert.AreEqual("MyModule.py", str, "");
                str = objectBrowser.TypeBrowserPane.Nodes[2].Value;
                Assert.AreEqual("Program.py", str, "");

                objectBrowser.TypeBrowserPane.Nodes[2].ExpandCollapse();
                System.Threading.Thread.Sleep(1000);
                objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse();
                System.Threading.Thread.Sleep(1000);

                nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count;
                Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString());

                objectBrowser.TypeBrowserPane.Nodes[4].Select();
                System.Threading.Thread.Sleep(1000);
                app.ExecuteCommand("Edit.GoToDefinition");
                System.Threading.Thread.Sleep(1000);

                str = app.Dte.ActiveDocument.Name;
                Assert.AreEqual("Program.py", str, "");

                int lineNo = ((TextSelection)app.Dte.ActiveDocument.Selection).ActivePoint.Line;
                Assert.AreEqual(14, lineNo, "Line number: " + lineNo.ToString());

                app.OpenObjectBrowser();
                objectBrowser.TypeBrowserPane.Nodes[2].Select();
                System.Threading.Thread.Sleep(1000);
                app.ExecuteCommand("Edit.GoToDefinition");
                System.Threading.Thread.Sleep(1000);

                str = app.Dte.ActiveDocument.Name;
                Assert.AreEqual("MyModule.py", str, "");

                lineNo = ((TextSelection)app.Dte.ActiveDocument.Selection).ActivePoint.Line;
                Assert.AreEqual(1, lineNo, "Line number: " + lineNo.ToString());

                objectBrowser.TypeBrowserPane.Nodes[3].ExpandCollapse();
                System.Threading.Thread.Sleep(1000);
                objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse();
                System.Threading.Thread.Sleep(1000);
            }
        }
Exemple #17
0
        public void WebProjectStaticUri()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.CreateProject(
                    PythonVisualStudioApp.TemplateLanguageName,
                    PythonVisualStudioApp.EmptyWebProjectTemplate,
                    TestData.GetTempPath(),
                    "WebProjectStaticUri"
                    );

                var proj = project.GetCommonProject();
                Assert.IsNotNull(proj);

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    proj.SetProjectProperty("PythonWsgiHandler", "NoHandler");

                    proj.SetProjectProperty("StaticUriPattern", "");
                    proj.SetProjectProperty("StaticUriRewrite", "");
                });
                app.ExecuteCommand("Build.RebuildSolution");
                app.WaitForOutputWindowText("Build", "1 succeeded");

                var webConfig = File.ReadAllText(Path.Combine(Path.GetDirectoryName(project.FullName), "web.config"));
                if (!webConfig.Contains(@"<add input=""true"" pattern=""false"" />"))
                {
                    Assert.Fail(string.Format("Did not find Static Files condition in:{0}{0}{1}",
                                              Environment.NewLine,
                                              webConfig
                                              ));
                }

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    proj.SetProjectProperty("StaticUriPattern", "^static/.*$");
                });
                app.ExecuteCommand("Build.RebuildSolution");
                app.WaitForOutputWindowText("Build", "1 succeeded");

                webConfig = File.ReadAllText(Path.Combine(Path.GetDirectoryName(project.FullName), "web.config"));
                if (!webConfig.Contains(@"<add input=""{REQUEST_URI}"" pattern=""^static/.*$"" ignoreCase=""true"" negate=""true"" />"))
                {
                    Assert.Fail(string.Format("Did not find rewrite condition in:{0}{0}{1}",
                                              Environment.NewLine,
                                              webConfig
                                              ));
                }
                if (!webConfig.Contains(@"<add input=""true"" pattern=""false"" />"))
                {
                    Assert.Fail(string.Format("Did not find Static Files condition in:{0}{0}{1}",
                                              Environment.NewLine,
                                              webConfig
                                              ));
                }

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    proj.SetProjectProperty("StaticUriRewrite", "static_files/{R:1}");
                });
                app.ExecuteCommand("Build.RebuildSolution");
                app.WaitForOutputWindowText("Build", "1 succeeded");

                webConfig = File.ReadAllText(Path.Combine(Path.GetDirectoryName(project.FullName), "web.config"));
                if (webConfig.Contains(@"<add input=""{REQUEST_URI}"" pattern=""^static/.*$"" ignoreCase=""true"" negate=""true"" />"))
                {
                    Assert.Fail(string.Format("Found old rewrite condition in:{0}{0}{1}",
                                              Environment.NewLine,
                                              webConfig
                                              ));
                }
                if (!webConfig.Contains(@"<action type=""Rewrite"" url=""static_files/{R:1}"" appendQueryString=""true"" />"))
                {
                    Assert.Fail(string.Format("Did not find rewrite action in:{0}{0}{1}",
                                              Environment.NewLine,
                                              webConfig
                                              ));
                }
                if (webConfig.Contains(@"<add input=""true"" pattern=""false"" />"))
                {
                    Assert.Fail(string.Format("Should not have found Static Files condition in:{0}{0}{1}",
                                              Environment.NewLine,
                                              webConfig
                                              ));
                }

                app.ServiceProvider.GetUIThread().Invoke(() => {
                    proj.SetProjectProperty("StaticUriPattern", "invalid[pattern");
                });
                app.ExecuteCommand("Build.RebuildSolution");
                app.WaitForOutputWindowText("Build", "1 failed");
            }
        }
Exemple #18
0
        ////[TestMethod, Priority(0)]
        //[HostType("VSTestHost"), TestCategory("Installed")]
        public void ObjectBrowserNavigationTest(VisualStudioApp app)
        {
            var project = app.OpenProject(@"TestData\MultiModule.sln");

            System.Threading.Thread.Sleep(1000);

            app.OpenObjectBrowser();
            var objectBrowser = app.ObjectBrowser;

            objectBrowser.EnsureLoaded();

            int nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count;

            Assert.AreEqual(1, nodeCount, "Node count: " + nodeCount.ToString());

            objectBrowser.TypeBrowserPane.Nodes[0].ExpandCollapse();
            System.Threading.Thread.Sleep(1000);

            nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count;
            Assert.AreEqual(3, nodeCount, "Node count: " + nodeCount.ToString());

            string str = objectBrowser.TypeBrowserPane.Nodes[1].Value;

            Assert.AreEqual("MyModule.py", str, "");
            str = objectBrowser.TypeBrowserPane.Nodes[2].Value;
            Assert.AreEqual("Program.py", str, "");

            objectBrowser.TypeBrowserPane.Nodes[2].ExpandCollapse();
            System.Threading.Thread.Sleep(1000);
            objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse();
            System.Threading.Thread.Sleep(1000);

            nodeCount = objectBrowser.TypeBrowserPane.Nodes.Count;
            Assert.AreEqual(6, nodeCount, "Node count: " + nodeCount.ToString());

            objectBrowser.TypeBrowserPane.Nodes[4].Select();
            System.Threading.Thread.Sleep(1000);
            app.ExecuteCommand("Edit.GoToDefinition");
            System.Threading.Thread.Sleep(1000);

            str = app.Dte.ActiveDocument.Name;
            Assert.AreEqual("Program.py", str, "");

            int lineNo = ((TextSelection)app.Dte.ActiveDocument.Selection).ActivePoint.Line;

            Assert.AreEqual(14, lineNo, "Line number: " + lineNo.ToString());

            app.OpenObjectBrowser();
            objectBrowser.TypeBrowserPane.Nodes[2].Select();
            System.Threading.Thread.Sleep(1000);
            app.ExecuteCommand("Edit.GoToDefinition");
            System.Threading.Thread.Sleep(1000);

            str = app.Dte.ActiveDocument.Name;
            Assert.AreEqual("MyModule.py", str, "");

            lineNo = ((TextSelection)app.Dte.ActiveDocument.Selection).ActivePoint.Line;
            Assert.AreEqual(1, lineNo, "Line number: " + lineNo.ToString());

            objectBrowser.TypeBrowserPane.Nodes[3].ExpandCollapse();
            System.Threading.Thread.Sleep(1000);
            objectBrowser.TypeBrowserPane.Nodes[1].ExpandCollapse();
            System.Threading.Thread.Sleep(1000);
        }
Exemple #19
0
        public void TestPublishFtp() {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\HelloWorld.sln");
                string subDir = Guid.NewGuid().ToString();
                string url = TestFtpUrl + "/" + subDir;
                project.Properties.Item("PublishUrl").Value = url;
                app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
                string dir = Path.Combine(FtpValidateDir, subDir);
                Debug.WriteLine(dir);

                app.OpenSolutionExplorer().SelectProject(project);

                app.ExecuteCommand("Build.PublishSelection");
                System.Threading.Thread.Sleep(2000);
                var files = WaitForFiles(dir);
                Assert.AreEqual(1, files.Length);
                Assert.AreEqual("Program.py", Path.GetFileName(files[0]));

                // do it again w/ the directories already existing
                File.Delete(files[0]);

                app.OpenSolutionExplorer().SelectProject(project);
                app.ExecuteCommand("Build.PublishSelection");
                files = WaitForFiles(dir);
                Assert.AreEqual(1, files.Length);
                Assert.AreEqual("Program.py", Path.GetFileName(files[0]));

                Directory.Delete(dir, true);
            }
        }
Exemple #20
0
        private static void RemoveSmartTagTest(string filename, int line, int column, bool allScopes, string expectedText) {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\RemoveImport.sln");
                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);

                doc.Invoke(() => {
                    var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(line - 1).Start.Add(column - 1);
                    doc.TextView.Caret.MoveTo(point);
                });

                if (allScopes) {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.AllScopes");
                } else {
                    app.ExecuteCommand("EditorContextMenus.CodeWindow.RemoveImports.CurrentScope");
                }

                doc.WaitForText(expectedText);
            }
        }