提交 9119afc4 编写于 作者: J Jonathon Marolf

responding to PR feedback

上级 b1702195
......@@ -86,43 +86,28 @@ protected void CloseFile(string projectName, string fileName, bool saveFile = tr
protected void SaveFile(string projectName, string fileName)
=> VisualStudio.Instance.SolutionExplorer.SaveFile(projectName, fileName);
protected void AddWinFormButton(string projectName, string fileName, string buttonName)
{
OpenFileWithDesigner(projectName, fileName);
VisualStudio.Instance.Editor.AddWinFormButton(buttonName);
}
protected void AddWinFormButton(string buttonName)
=> VisualStudio.Instance.Editor.AddWinFormButton(buttonName);
protected void DeleteWinFormButton(string projectName, string fileName, string buttonName)
{
OpenFileWithDesigner(projectName, fileName);
VisualStudio.Instance.Editor.DeleteWinFormButton(buttonName);
}
protected void DeleteWinFormButton(string buttonName)
=> VisualStudio.Instance.Editor.DeleteWinFormButton(buttonName);
protected void EditWinFormButtonProperty(string projectName, string fileName, string buttonName, string propertyName, string propertyValue, string propertyTypeName = null)
{
OpenFileWithDesigner(projectName, fileName);
VisualStudio.Instance.Editor.EditWinFormButtonProperty(buttonName, propertyName, propertyValue, propertyTypeName);
}
protected void EditWinFormButtonProperty(string buttonName, string propertyName, string propertyValue, string propertyTypeName = null)
=> VisualStudio.Instance.Editor.EditWinFormButtonProperty(buttonName, propertyName, propertyValue, propertyTypeName);
protected void EditWinFormsButtonEvent(string projectName, string fileName, string buttonName, string eventName, string eventHandlerName)
{
OpenFileWithDesigner(projectName, fileName);
VisualStudio.Instance.Editor.EditWinFormButtonEvent(buttonName, eventName, eventHandlerName);
}
protected void EditWinFormsButtonEvent(string buttonName, string eventName, string eventHandlerName)
=> VisualStudio.Instance.Editor.EditWinFormButtonEvent(buttonName, eventName, eventHandlerName);
protected void VerifyWinFormButtonPropertySet(string projectName, string fileName, string buttonName, string propertyName, string expectedPropertyValue)
{
OpenFileWithDesigner(projectName, fileName);
VisualStudio.Instance.Editor.VerifyWinFormButtonPropertySet(buttonName, propertyName, expectedPropertyValue);
}
protected void VerifyWinFormButtonPropertySet(string buttonName, string propertyName, string expectedPropertyValue)
=> VisualStudio.Instance.Editor.VerifyWinFormButtonPropertySet(buttonName, propertyName, expectedPropertyValue);
protected void SelectTextInCurrentDocument(string text)
{
VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: -1, occurrence: 0, extendSelection: true, selectBlock: false);
VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: -1, occurrence: 0, extendSelection: false, selectBlock: false);
VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: 0, occurrence: 0, extendSelection: true, selectBlock: false);
}
protected void BuildSolution(bool waitForBuildToFinish = false)
protected void BuildSolution(bool waitForBuildToFinish)
=> VisualStudio.Instance.SolutionExplorer.BuildSolution(waitForBuildToFinish);
protected int GetErrorListErrorCount()
......
......@@ -24,8 +24,9 @@ public CSharpWinForms(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Add_Control()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
CloseFile(ProjectName, "Form1.cs", saveFile: true);
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
SaveFile(ProjectName, "Form1.cs");
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeButton.Name = ""SomeButton""");
VerifyTextContains(@"private System.Windows.Forms.Button SomeButton;");
......@@ -34,8 +35,9 @@ public void Add_Control()
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Change_Control_Property()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
EditWinFormButtonProperty(ProjectName, "Form1.cs", buttonName: "SomeButton", propertyName: "Text", propertyValue: "NewButtonText");
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "NewButtonText");
CloseFile(ProjectName, "Form1.cs", saveFile: true);
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeButton.Text = ""NewButtonText""");
......@@ -44,9 +46,10 @@ public void Change_Control_Property()
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Change_Control_Property_In_Code()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
EditWinFormButtonProperty(ProjectName, "Form1.cs", buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextGoesHere");
VerifyWinFormButtonPropertySet(ProjectName, "Form1.cs", buttonName: "SomeButton", propertyName: "Text", expectedPropertyValue: "ButtonTextGoesHere");
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextGoesHere");
VerifyWinFormButtonPropertySet(buttonName: "SomeButton", propertyName: "Text", expectedPropertyValue: "ButtonTextGoesHere");
CloseFile(ProjectName, "Form1.cs", saveFile: true);
// Change the control's text in designer.cs code
OpenFile(ProjectName, "Form1.Designer.cs");
......@@ -58,14 +61,15 @@ public void Change_Control_Property_In_Code()
CloseFile(ProjectName, "Form1.Designer.cs", saveFile: true);
// Verify that the control text has changed in the designer
OpenFileWithDesigner(ProjectName, "Form1.cs");
VerifyWinFormButtonPropertySet(ProjectName, "Form1.cs", buttonName: "SomeButton", propertyName: "Text", expectedPropertyValue: "GibberishText");
VerifyWinFormButtonPropertySet(buttonName: "SomeButton", propertyName: "Text", expectedPropertyValue: "GibberishText");
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Add_Click_Handler()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
EditWinFormsButtonEvent(ProjectName, "Form1.cs", buttonName: "SomeButton", eventName: "Click", eventHandlerName: "ExecuteWhenButtonClicked");
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "ExecuteWhenButtonClicked");
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeButton.Click += new System.EventHandler(this.ExecuteWhenButtonClicked);");
OpenFile(ProjectName, "Form1.cs");
......@@ -86,12 +90,13 @@ private void ExecuteWhenButtonClicked(object sender, EventArgs e)
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Rename_Control()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
// Add some control properties and events
EditWinFormButtonProperty(ProjectName, "Form1.cs", buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextValue");
EditWinFormsButtonEvent(ProjectName, "Form1.cs", buttonName: "SomeButton", eventName: "Click", eventHandlerName: "SomeButtonHandler");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextValue");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "SomeButtonHandler");
// Rename the control
EditWinFormButtonProperty(ProjectName, "Form1.cs", buttonName: "SomeButton", propertyName: "Name", propertyValue: "SomeNewButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Name", propertyValue: "SomeNewButton");
VerifyNoBuildErrors();
// Verify that the rename propagated in designer code
OpenFile(ProjectName, "Form1.Designer.cs");
......@@ -106,10 +111,11 @@ public void Rename_Control()
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Remove_Event_Handler()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
EditWinFormsButtonEvent(ProjectName, "Form1.cs", buttonName: "SomeButton", eventName: "Click", eventHandlerName: "FooHandler");
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "FooHandler");
// Remove the event handler
EditWinFormsButtonEvent(ProjectName, "Form1.cs", buttonName: "SomeButton", eventName: "Click", eventHandlerName: "");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "");
VerifyNoBuildErrors();
// Verify that the handler is removed
OpenFile(ProjectName, "Form1.Designer.cs");
......@@ -119,10 +125,9 @@ public void Remove_Event_Handler()
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Change_Accessibility()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
EditWinFormButtonProperty(ProjectName, "Form1.cs",
buttonName: "SomeButton",
propertyName: "Modifiers",
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Modifiers",
propertyTypeName: "System.CodeDom.MemberAttributes",
propertyValue: "Public");
VerifyNoBuildErrors();
......@@ -133,8 +138,9 @@ public void Change_Accessibility()
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Delete_Control()
{
AddWinFormButton(ProjectName, "Form1.cs", "SomeButton");
DeleteWinFormButton(ProjectName, "Form1.cs", "SomeButton");
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
DeleteWinFormButton("SomeButton");
VerifyNoBuildErrors();
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextDoesNotContain(@"this.SomeButton.Name = ""SomeButton"";");
......
......@@ -155,9 +155,10 @@ public void PlaceCaret(string marker, int charsOffset, int occurrence, bool exte
dte.Find.Action = EnvDTE.vsFindAction.vsFindActionFind;
var originalPosition = GetCaretPosition();
view.Caret.MoveTo(new Microsoft.VisualStudio.Text.SnapshotPoint(view.GetBufferContainingCaret().CurrentSnapshot, 0));
if (occurrence > 0)
{
view.Caret.MoveTo(new Microsoft.VisualStudio.Text.SnapshotPoint(view.GetBufferContainingCaret().CurrentSnapshot, 0));
var result = EnvDTE.vsFindResult.vsFindResultNotFound;
for (var i = 0; i < occurrence; i++)
......
......@@ -359,7 +359,7 @@ private static void SaveFile(string fileName)
if (fileToSave == null)
{
var fileNames = dte.Documents.Cast<EnvDTE.Document>().Select(d => d.Name);
throw new Exception($"File '{fileName}' not saved because it couldn't be found. Available files: {string.Join(", ", fileNames)}.");
throw new InvalidOperationException($"File '{fileName}' not saved because it couldn't be found. Available files: {string.Join(", ", fileNames)}.");
}
var textDocument = (EnvDTE.TextDocument)fileToSave.Object(nameof(EnvDTE.TextDocument));
var currentTextInDocument = textDocument.StartPoint.CreateEditPoint().GetText(textDocument.EndPoint);
......@@ -367,7 +367,7 @@ private static void SaveFile(string fileName)
fileToSave.Save();
if (File.ReadAllText(fullPath) != currentTextInDocument)
{
throw new Exception("The text that we thought we were saving isn't what we saved!");
throw new InvalidOperationException("The text that we thought we were saving isn't what we saved!");
}
}
......
......@@ -44,7 +44,7 @@ public void SetFileContents(string projectName, string fileName, string contents
public string GetFileContents(string projectName, string fileName)
=> _inProc.GetFileContents(projectName, fileName);
public void BuildSolution(bool waitForBuildToFinish = false)
public void BuildSolution(bool waitForBuildToFinish)
=> _inProc.BuildSolution(waitForBuildToFinish);
public void OpenFileWithDesigner(string projectName, string fileName)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册