本文整理汇总了C#中VisualStudioApp.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# VisualStudioApp.GetDocument方法的具体用法?C# VisualStudioApp.GetDocument怎么用?C# VisualStudioApp.GetDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisualStudioApp
的用法示例。
在下文中一共展示了VisualStudioApp.GetDocument方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNewScript
public void CreateNewScript() {
using (var app = new VisualStudioApp()) {
var project = app.CreateProject(
RConstants.TemplateLanguageName, RConstants.ProjectTemplate_EmptyProject,
System.IO.Path.GetTempPath(), "RTestProject");
app.OpenSolutionExplorer().SelectProject(project);
using (var newItem = NewItemDialog.FromDte(app)) {
AutomationWrapper.Select(newItem.ProjectTypes.FindItem("R Script"));
newItem.FileName = "my-script.r";
newItem.OK();
}
var document = app.GetDocument("my-script.r");
document.SetFocus();
document.Type("2 -> a");
document.Text.Should().Be("2 -> a# R Script");
}
}
示例2: OpenItem
private static EditorWindow OpenItem(VisualStudioApp app, string startItem, Project project, out Window window)
{
EnvDTE.ProjectItem item = null;
if (startItem.IndexOf('\\') != -1) {
var items = project.ProjectItems;
foreach (var itemName in startItem.Split('\\')) {
Console.WriteLine(itemName);
item = items.Item(itemName);
items = item.ProjectItems;
}
} else {
item = project.ProjectItems.Item(startItem);
}
Assert.IsNotNull(item);
window = item.Open();
window.Activate();
return app.GetDocument(item.Document.FullName);
}
示例3: OutlineTest
private void OutlineTest(string filename, params ExpectedTag[] expected) {
using (var app = new VisualStudioApp()) {
var prevOption = NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen;
try {
NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen = true;
var project = app.OpenProject(@"TestData\Outlining\Outlining.sln");
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
System.Threading.Thread.Sleep(2000);
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 {
NodejsPackage.Instance.AdvancedEditorOptionsPage.EnterOutliningOnOpen = prevOption;
}
}
}
示例4: 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) {
using (var app = new VisualStudioApp()) {
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;
for (int i = 0; i < 100; i++) {
actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
if (expectedText == actual) {
break;
}
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]);
}
}
}
示例5: OpenDjangoProjectItem
private static EditorWindow OpenDjangoProjectItem(VisualStudioApp app, string startItem, out Window window, string projectName = @"TestData\DjangoEditProject.sln", bool wait = false) {
var project = app.OpenProject(projectName, startItem);
var pyProj = project.GetPythonProject();
EnvDTE.ProjectItem item = null;
if (startItem.IndexOf('\\') != -1) {
var items = project.ProjectItems;
foreach (var itemName in startItem.Split('\\')) {
Console.WriteLine(itemName);
item = items.Item(itemName);
items = item.ProjectItems;
}
} else {
item = project.ProjectItems.Item(startItem);
}
Assert.IsNotNull(item);
window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
if (wait) {
pyProj.GetAnalyzer().WaitForCompleteAnalysis(_ => true);
}
return doc;
}
示例6: AddSmartTagTest
private static void AddSmartTagTest(string filename, int line, int column, string[] expectedActions, int invokeAction = -1, string expectedText = null) {
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\AddImport.sln");
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
AddSmartTagTest(doc, line, column, expectedActions, invokeAction, expectedText);
}
}
示例7: Parameters
public void Parameters() {
var getreclimit = new[] { "from sys import getrecursionlimit" };
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\AddImport.sln");
var item = project.ProjectItems.Item("Parameters.py");
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
AddSmartTagTest(doc, 1, 19, _NoSmartTags);
AddSmartTagTest(doc, 1, 30, getreclimit);
AddSmartTagTest(doc, 4, 18, _NoSmartTags);
AddSmartTagTest(doc, 7, 18, _NoSmartTags);
AddSmartTagTest(doc, 10, 20, _NoSmartTags);
AddSmartTagTest(doc, 13, 22, _NoSmartTags);
AddSmartTagTest(doc, 16, 22, _NoSmartTags);
AddSmartTagTest(doc, 19, 22, _NoSmartTags);
AddSmartTagTest(doc, 19, 35, getreclimit);
AddSmartTagTest(doc, 22, 25, _NoSmartTags);
AddSmartTagTest(doc, 22, 56, getreclimit);
AddSmartTagTest(doc, 25, 38, _NoSmartTags);
AddSmartTagTest(doc, 25, 38, _NoSmartTags);
AddSmartTagTest(doc, 25, 48, getreclimit);
AddSmartTagTest(doc, 29, 12, _NoSmartTags);
AddSmartTagTest(doc, 29, 42, getreclimit);
AddSmartTagTest(doc, 34, 26, _NoSmartTags);
AddSmartTagTest(doc, 34, 31, getreclimit);
AddSmartTagTest(doc, 42, 16, _NoSmartTags);
AddSmartTagTest(doc, 51, 16, _NoSmartTags);
}
}
示例8: TypingTest
/// <summary>
/// Single auto indent test
/// </summary>
/// <param name="project">containting project</param>
/// <param name="filename">filename in the project</param>
/// <param name="line">zero-based line</param>
/// <param name="column">zero based column</param>
/// <param name="expectedText"></param>
private static void TypingTest(VisualStudioApp app, Project project, string filename, int line, int column, string expectedText, Action typing) {
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
doc.SetFocus();
var textLine = doc.TextView.TextViewLines[line];
((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
try {
doc.TextView.Caret.MoveTo(textLine.Start + column);
((UIElement)doc.TextView).Focus();
} catch (Exception) {
Debug.Fail("Bad position for moving caret");
}
}));
typing();
string actual = null;
for (int i = 0; i < 100; i++) {
actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
if (expectedText == actual) {
break;
}
System.Threading.Thread.Sleep(100);
}
Assert.AreEqual(expectedText, actual);
}
示例9: AutoIndentTest
private static void AutoIndentTest(VisualStudioApp app, Project project, string typedText, string expectedText) {
var item = project.ProjectItems.Item("Program.py");
var window = item.Open();
window.Activate();
Keyboard.Type(typedText);
var doc = app.GetDocument(item.Document.FullName);
string actual = null;
for (int i = 0; i < 100; i++) {
actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
if (expectedText == actual) {
break;
}
System.Threading.Thread.Sleep(100);
}
Assert.AreEqual(expectedText, actual);
window.Document.Close(vsSaveChanges.vsSaveChangesNo);
}
示例10: AutoIndentExistingTest
/// <summary>
/// Single auto indent test
/// </summary>
/// <param name="project">containting project</param>
/// <param name="filename">filename in the project</param>
/// <param name="line">zero-based line</param>
/// <param name="column">zero based column</param>
/// <param name="expectedText"></param>
private static void AutoIndentExistingTest(VisualStudioApp app, Project project, string filename, int line, int column, string expectedText) {
var item = project.ProjectItems.Item(filename);
var window = item.Open();
window.Activate();
var doc = app.GetDocument(item.Document.FullName);
doc.SetFocus();
var textLine = doc.TextView.TextViewLines[line];
((UIElement)doc.TextView).Dispatcher.Invoke((Action)(() => {
doc.TextView.Caret.MoveTo(textLine.Start + column);
((UIElement)doc.TextView).Focus();
}));
Keyboard.Type("\r");
string actual = null;
for (int i = 0; i < 100; i++) {
actual = doc.TextView.TextBuffer.CurrentSnapshot.GetText();
if (expectedText == actual) {
break;
}
System.Threading.Thread.Sleep(100);
}
Assert.AreEqual(actual, expectedText);
}
示例11: RemoveSmartTagTest
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);
}
}