提交 3e4cf945 编写于 作者: S Sam Harwell

Bypass the Preview Changes dialog for Fix All testing

上级 64764506
......@@ -16,7 +16,7 @@ internal abstract class FixSomeCodeAction : CodeAction
private static readonly HashSet<string> s_predefinedCodeFixProviderNames = GetPredefinedCodeFixProviderNames();
internal readonly FixAllState FixAllState;
private readonly bool _showPreviewChangesDialog;
private bool _showPreviewChangesDialog;
internal FixSomeCodeAction(
FixAllState fixAllState, bool showPreviewChangesDialog)
......@@ -84,5 +84,28 @@ private static HashSet<string> GetPredefinedCodeFixProviderNames()
return names;
}
internal TestAccessor GetTestAccessor()
{
return new TestAccessor(this);
}
internal readonly struct TestAccessor
{
private readonly FixSomeCodeAction _fixSomeCodeAction;
internal TestAccessor(FixSomeCodeAction fixSomeCodeAction)
{
_fixSomeCodeAction = fixSomeCodeAction;
}
/// <summary>
/// Gets a reference to <see cref="_showPreviewChangesDialog"/>, which can be read or written by test code.
/// </summary>
public ref bool ShowPreviewChangesDialog
{
get => ref _fixSomeCodeAction._showPreviewChangesDialog;
}
}
}
}
......@@ -215,12 +215,7 @@ class C
VisualStudio.Editor.Verify.CodeAction(
"Use expression body for properties",
applyFix: true,
fixAllScope: FixAllScope.Project,
blockUntilComplete: false);
var expectedTitle = "Preview Changes - Fix all occurrences";
VisualStudio.PreviewChangesDialog.VerifyOpen(expectedTitle, Helper.HangMitigatingTimeout);
VisualStudio.PreviewChangesDialog.ClickApplyAndWaitForFeature(expectedTitle, FeatureAttribute.DiagnosticService);
fixAllScope: FixAllScope.Project);
Assert.Equal(expectedText, VisualStudio.Editor.GetText());
......@@ -243,11 +238,7 @@ class C
VisualStudio.Editor.Verify.CodeAction(
"Use block body for properties",
applyFix: true,
fixAllScope: FixAllScope.Project,
blockUntilComplete: false);
VisualStudio.PreviewChangesDialog.VerifyOpen(expectedTitle, Helper.HangMitigatingTimeout);
VisualStudio.PreviewChangesDialog.ClickApplyAndWaitForFeature(expectedTitle, FeatureAttribute.DiagnosticService);
fixAllScope: FixAllScope.Project);
expectedText = @"
class C
......
......@@ -15,6 +15,7 @@
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Roslyn.Utilities;
using OLECMDEXECOPT = Microsoft.VisualStudio.OLE.Interop.OLECMDEXECOPT;
using ThreadHelper = Microsoft.VisualStudio.Shell.ThreadHelper;
......@@ -319,7 +320,7 @@ private async Task<IEnumerable<ISuggestedAction>> GetLightBulbActionsAsync(ILigh
public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bool blockUntilComplete)
{
var lightBulbAction = GetLightBulbApplicationAction(actionName, fixAllScope);
var lightBulbAction = GetLightBulbApplicationAction(actionName, fixAllScope, blockUntilComplete);
var task = ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
......@@ -340,7 +341,7 @@ public void ApplyLightBulbAction(string actionName, FixAllScope? fixAllScope, bo
private void BeginInvokeExecuteOnActiveView(Action<IWpfTextView> action)
=> BeginInvokeOnUIThread(GetExecuteOnActionViewCallback(action));
private Func<IWpfTextView, Task> GetLightBulbApplicationAction(string actionName, FixAllScope? fixAllScope)
private Func<IWpfTextView, Task> GetLightBulbApplicationAction(string actionName, FixAllScope? fixAllScope, bool willBlockUntilComplete)
{
return async view =>
{
......@@ -378,6 +379,17 @@ private void BeginInvokeExecuteOnActiveView(Action<IWpfTextView> action)
throw new InvalidOperationException($"Unable to find FixAll in {fixAllScope.ToString()} code fix for suggested action '{action.DisplayText}'.");
}
if (willBlockUntilComplete
&& action is FixAllSuggestedAction fixAllSuggestedAction
&& fixAllSuggestedAction.CodeAction is FixSomeCodeAction fixSomeCodeAction)
{
// Ensure the preview changes dialog will not be shown. Since the operation 'willBlockUntilComplete',
// the caller would not be able to interact with the preview changes dialog, and the tests would
// either timeout or deadlock.
fixSomeCodeAction.GetTestAccessor().ShowPreviewChangesDialog = false;
}
if (string.IsNullOrEmpty(actionName))
{
return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册