当前位置: 首页>>代码示例>>C#>>正文


C# PythonVisualStudioApp.GetDocument方法代码示例

本文整理汇总了C#中TestUtilities.UI.Python.PythonVisualStudioApp.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# PythonVisualStudioApp.GetDocument方法的具体用法?C# PythonVisualStudioApp.GetDocument怎么用?C# PythonVisualStudioApp.GetDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestUtilities.UI.Python.PythonVisualStudioApp的用法示例。


在下文中一共展示了PythonVisualStudioApp.GetDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnregisteredFileExtensionEditor

        public void UnregisteredFileExtensionEditor() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\UnregisteredFileExtension.sln");

                var item = project.ProjectItems.Item("Fob.unregfileext");
                var window = item.Open();
                window.Activate();

                var doc = app.GetDocument(item.Document.FullName);
                var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;

                // we shouldn't have opened this as a .py file, so we should have no classifications.
                var classifier = doc.Classifier;
                var spans = classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));
                Assert.AreEqual(spans.Count, 0);
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:17,代码来源:EditorTests.cs

示例2: ExtensionReference

        public void ExtensionReference() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ExtensionReference.sln");

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

                var dbPath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    "Python Tools",
                    "ReferencesDB",
#if DEBUG
                    "Debug",
#endif
                    AssemblyVersionInfo.VSVersion
                );
                var existingFiles = Directory.GetFiles(dbPath, "spam*");

                // open the solution, add a reference to our spam.pyd Python extension module
                var folderNode = solutionTree.FindItem(
                    "Solution 'ExtensionReference' (1 project)",
                    "ExtensionReference",
                    SR.GetString(SR.ReferencesNodeName)
                );
                folderNode.Select();
                var dialog = new AddReferenceDialog(AutomationElement.FromHandle(app.OpenDialogWithDteExecuteCommand("Project.AddReference")));
                dialog.ActivateBrowseTab();

                dialog.BrowseFilename = TestData.GetPath(@"TestData\spam.pyd");
                dialog.ClickOK();

                app.WaitForDialogDismissed();

                // make sure the reference got added
                var spamItem = solutionTree.WaitForItem(
                    "Solution 'ExtensionReference' (1 project)",
                    "ExtensionReference",
                    SR.GetString(SR.ReferencesNodeName),
                    "spam.pyd"
                );
                Assert.IsNotNull(spamItem);

                // wait for scraping to complete
                for (int retries = 10;
                    Directory.GetFiles(dbPath, "spam*").Length == existingFiles.Length && retries > 0;
                    --retries) {
                    System.Threading.Thread.Sleep(1000);
                }

                Assert.AreNotEqual(existingFiles.Length, Directory.GetFiles(dbPath, "spam*").Length, "File was not scraped");

                // now open a file and make sure we get completions against the spam module
                var item = project.ProjectItems.Item("Program.py");
                var window = item.Open();
                window.Activate();

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

                doc.MoveCaret(doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1).Start);

                Keyboard.Type("spam.");

                using (var sh = doc.WaitForSession<ICompletionSession>()) {
                    var completion = sh.Session.CompletionSets.First().Completions.Select(x => x.InsertionText).FirstOrDefault(x => x == "system");
                    Assert.IsNotNull(completion);
                }

                // now clear the text we just typed
                for (int i = 0; i < 5; i++) {
                    Keyboard.Type(Key.Back);
                }

                // remove the extension
                app.Dte.Solution.Projects.Item(1).ProjectItems.Item("References").ProjectItems.Item(@"spam.pyd").Remove();

                // make sure it got removed
                solutionTree.WaitForItemRemoved(
                    "Solution 'ExtensionReference' (1 project)",
                    "ExtensionReference",
                    SR.GetString(SR.ReferencesNodeName),
                    "spam.pyd"
                );

                window.Activate();

                // and make sure we no longer offer completions on the spam module.
                Keyboard.Type("spam.");

                using (var sh = doc.WaitForSession<ICompletionSession>()) {
                    var completion = sh.Session.CompletionSets.First().Completions.Select(x => x.DisplayText).Single();
                    Assert.AreEqual(SR.GetString(SR.NoCompletionsCompletion), completion);
                }
            }
        }
开发者ID:wenh123,项目名称:PTVS,代码行数:94,代码来源:UITests.cs

示例3: FormattingTest

        /// <summary>
        /// Runs a single formatting test
        /// </summary>
        /// <param name="filename">The filename of the document to perform formatting in (lives in FormattingTests.sln)</param>
        /// <param name="selection">The selection to format, or null if formatting the entire document</param>
        /// <param name="expectedText">The expected source code after the formatting</param>
        /// <param name="changedSpans">The spans which should be marked as changed in the buffer after formatting</param>
        private static void FormattingTest(
            string filename,
            Span? selection,
            string expectedText,
            Span[] changedSpans,
            Func<PythonToolsService, object> updateSettings,
            Action<PythonToolsService, object> revertSettings,
            Version version = null
        ) {
            using (var app = new PythonVisualStudioApp())
            using (version == null ? null : app.SelectDefaultInterpreter(PythonPaths.Versions.FirstOrDefault(v => v.Version.ToVersion() >= version))) {
                var o = updateSettings?.Invoke(app.PythonToolsService);
                if (revertSettings != null) {
                    app.OnDispose(() => revertSettings(app.PythonToolsService, o));
                }

                var project = app.OpenProject(@"TestData\FormattingTests\FormattingTests.sln");
                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();
                var doc = app.GetDocument(item.Document.FullName);

                var aggFact = app.ComponentModel.GetService<IViewTagAggregatorFactoryService>();
                var changeTags = aggFact.CreateTagAggregator<ChangeTag>(doc.TextView);

                // format the selection or document
                if (selection == null) {
                    DoFormatDocument();
                } else {
                    doc.Invoke(() => doc.TextView.Selection.Select(new SnapshotSpan(doc.TextView.TextBuffer.CurrentSnapshot, selection.Value), false));
                    DoFormatSelection();
                }

                // verify the contents are correct
                string actual = null;
                int steady = 50;
                for (int i = 0; i < 100; i++) {
                    actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();

                    if (expectedText == actual) {
                        if (--steady <= 0) {
                            break;
                        }
                    } else {
                        steady = 50;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                Assert.AreEqual(expectedText, actual);

                // verify the change tags are correct
                var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                var tags = changeTags.GetTags(
                    new SnapshotSpan(
                        doc.TextView.TextBuffer.CurrentSnapshot,
                        new Span(0, doc.TextView.TextBuffer.CurrentSnapshot.Length)
                    )
                );
                List<Span> result = new List<Span>();
                foreach (var tag in tags) {
                    result.Add(
                        new Span(
                            tag.Span.Start.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position,
                            tag.Span.End.GetPoint(doc.TextView.TextBuffer.CurrentSnapshot, PositionAffinity.Successor).Value.Position
                        )
                    );
                }

                // dump the spans for creating tests easier
                foreach (var span in result) {
                    Console.WriteLine(span);
                }

                Assert.AreEqual(result.Count, changedSpans.Length);
                for (int i = 0; i < result.Count; i++) {
                    Assert.AreEqual(result[i], changedSpans[i]);
                }
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:86,代码来源:FormattingUITests.cs

示例4: RunOne

        private void RunOne(string filename, params SendToStep[] inputs) {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\SendToInteractive.sln");
                var program = project.ProjectItems.Item(filename);
                var window = program.Open();

                window.Activate();

                var doc = app.GetDocument(program.Document.FullName);
                doc.MoveCaret(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, 0));

                var interactive = ReplWindowProxy.Prepare(new ReplWindowPython35Tests().Settings, false);

                interactive.ExecuteText("42").Wait();
                interactive.ClearScreen();

                WaitForText(interactive.TextView, ">>> ");

                var state = new StepState(interactive, app, doc, window);
                state.Content.Append(">>> ");

                foreach (var input in inputs) {
                    input.Execute(state);
                }
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:26,代码来源:SendToReplTests.cs

示例5: GetClassifications

        private static IList<ClassificationSpan> GetClassifications(string filename) {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\Classification.sln");

                var item = project.ProjectItems.Item(filename);
                var window = item.Open();
                window.Activate();

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

                var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                var classifier = doc.Classifier;
                var spans = classifier.GetClassificationSpans(new SnapshotSpan(snapshot, 0, snapshot.Length));
                return spans;
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:16,代码来源:EditorTests.cs

示例6: OpenInvalidUnicodeFile

        public void OpenInvalidUnicodeFile() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ErrorProjectUnicode.sln");
                var item = project.ProjectItems.Item("Program.py");
                var windowTask = Task.Run(() => item.Open());

                VisualStudioApp.CheckMessageBox(TestUtilities.MessageBoxButton.Ok, "File Load", "Program.py", "Unicode (UTF-8) encoding");

                var window = windowTask.Result;
                window.Activate();
                var doc = app.GetDocument(item.Document.FullName);
                var text = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
                Console.WriteLine(string.Join(" ", text.Select(c => c < ' ' ? " .  " : string.Format(" {0}  ", c))));
                Console.WriteLine(string.Join(" ", text.Select(c => string.Format("{0:X04}", (int)c))));
                // Characters should have been replaced
                Assert.AreNotEqual(-1, text.IndexOf("\uFFFD\uFFFD\uFFFD\uFFFD", StringComparison.Ordinal));
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:18,代码来源:EditorTests.cs

示例7: CompletionsCaseSensitive

        public void CompletionsCaseSensitive() {
            // http://pytools.codeplex.com/workitem/457
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\Completions.sln");

                var item = project.ProjectItems.Item("oar.py");
                var window = item.Open();
                window.Activate();

                Keyboard.Type("from fob import ba\r");

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

                doc.WaitForText("from fob import baz");
                Keyboard.Type("\r");

                Keyboard.Type("from fob import Ba\r");
                doc.WaitForText("from fob import baz\r\nfrom fob import Baz");
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:20,代码来源:EditorTests.cs

示例8: MultiLineSignaturesTest

        public void MultiLineSignaturesTest() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\Signatures.sln");

                var item = project.ProjectItems.Item("multilinesigs.py");
                var window = item.Open();
                window.Activate();

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

                ((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
                    var point = doc.TextView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(5 - 1).Start;
                    doc.TextView.Caret.MoveTo(point);
                    ((UIElement)doc.TextView).Focus();
                }));

                app.ExecuteCommand("Edit.ParameterInfo");

                using (var sh = doc.WaitForSession<ISignatureHelpSession>()) {
                    Assert.AreEqual("b", sh.Session.SelectedSignature.CurrentParameter.Name);
                }
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:24,代码来源:EditorTests.cs

示例9: SignaturesTest

        public void SignaturesTest() {
            using (var app = new PythonVisualStudioApp()) {
                var project = app.OpenProject(@"TestData\Signatures.sln");

                var item = project.ProjectItems.Item("sigs.py");
                var window = item.Open();
                window.Activate();

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

                doc.SetFocus();

                ((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
                    doc.TextView.Caret.MoveTo(new SnapshotPoint(doc.TextView.TextBuffer.CurrentSnapshot, doc.TextView.TextBuffer.CurrentSnapshot.Length));
                    ((UIElement)doc.TextView).Focus();
                }));
                
                Keyboard.Type("f(");

                using (var sh = doc.WaitForSession<ISignatureHelpSession>()) {
                    var session = sh.Session;
                    Assert.AreEqual("a", session.SelectedSignature.CurrentParameter.Name);

                    Keyboard.Type("b=");

                    WaitForCurrentParameter(session, "b");
                    Assert.AreEqual("b", session.SelectedSignature.CurrentParameter.Name);
                    window.Activate();

                    Keyboard.Type("42,");

                    WaitForNoCurrentParameter(session);
                    Assert.AreEqual(null, session.SelectedSignature.CurrentParameter);

                    Keyboard.Backspace();
                    WaitForCurrentParameter(session);
                    Assert.AreEqual("b", session.SelectedSignature.CurrentParameter.Name);
                }
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:40,代码来源:EditorTests.cs

示例10: OutlineTest

        private void OutlineTest(string filename, params ExpectedTag[] expected) {
            using (var app = new PythonVisualStudioApp()) {

                var prevOption = app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen;
                try {
                    app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen = true;

                    var project = app.OpenProject(@"TestData\Outlining.sln");

                    var item = project.ProjectItems.Item(filename);
                    var window = item.Open();
                    window.Activate();

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

                    var snapshot = doc.TextView.TextBuffer.CurrentSnapshot;
                    var tags = doc.GetTaggerAggregator<IOutliningRegionTag>(doc.TextView.TextBuffer).GetTags(new SnapshotSpan(snapshot, 0, snapshot.Length));

                    VerifyTags(doc.TextView.TextBuffer, tags, expected);
                } finally {
                    app.GetService<PythonToolsService>().AdvancedOptions.EnterOutliningModeOnOpen = prevOption;
                }
            }
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:24,代码来源:EditorTests.cs


注:本文中的TestUtilities.UI.Python.PythonVisualStudioApp.GetDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。