Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task InsertTextAsync(string text, CancellationToken cancellationTok
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var view = await GetActiveTextViewAsync(cancellationToken);
var textSnapshot = view.TextSnapshot;

var position = await GetCaretPositionAsync(cancellationToken);

Expand Down Expand Up @@ -102,6 +101,21 @@ public async Task<string> WaitForTextChangeAsync(string text, CancellationToken
return result!;
}

public async Task<bool> WaitForTextContainsAsync(string text, CancellationToken cancellationToken)
{
var result = await Helper.RetryAsync(async ct =>
{
var view = await GetActiveTextViewAsync(ct);
var content = view.TextBuffer.CurrentSnapshot.GetText();

return content.Contains(text);
},
TimeSpan.FromMilliseconds(50),
cancellationToken).ConfigureAwait(false);

return result;
}

public async Task VerifyTextContainsAsync(string text, CancellationToken cancellationToken)
{
var view = await GetActiveTextViewAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ await TestServices.SolutionExplorer.AddFileAsync(RazorProjectConstants.BlazorPro

await TestServices.Editor.PlaceCaretAsync(position, ControlledHangMitigatingCancellationToken);

await Task.Delay(500);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await Task.Delay(500);

never a fan of blanket delays. Is there any way we can poll or do something else to determine things are good to go?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely worthy of follow up. Triggering a rename is just executing a VS command via DTE, so the only things we can probably wait for, that I'm aware of, are internal to Roslyn at the moment.


// Act
await TestServices.Editor.InvokeRenameAsync(ControlledHangMitigatingCancellationToken);
TestServices.Input.Send("ZooperDooper{ENTER}");
Expand Down Expand Up @@ -337,16 +339,14 @@ public class MyComponent : ComponentBase
await TestServices.RazorProjectSystem.WaitForComponentTagNameAsync(RazorProjectConstants.BlazorProjectName, "MyComponent", ControlledHangMitigatingCancellationToken);
await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, "MyComponent.cs", ControlledHangMitigatingCancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenFileAsync

I'm a little confused, why doesn't the razor file need to be opened explicitly before the caret is moved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Razor is already open, because of the open: true in the above AddFileAsync call. This line was a bad copy-paste from a test that was trying to test rename from the C# file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I didn't see the open parameter to AddFileAsync. Now it seems like the cs file's call to AddFileAsync should specify to not open the file, but it doesn't really matter.


await TestServices.Editor.PlaceCaretAsync(position, ControlledHangMitigatingCancellationToken);

// Act
await TestServices.Editor.InvokeRenameAsync(ControlledHangMitigatingCancellationToken);
TestServices.Input.Send("ZooperDooper{ENTER}");

// Assert
await TestServices.Editor.VerifyTextContainsAsync("<ZooperDooper></ZooperDooper>", ControlledHangMitigatingCancellationToken);
await TestServices.Editor.WaitForTextContainsAsync("<ZooperDooper></ZooperDooper>", ControlledHangMitigatingCancellationToken);

await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, "MyComponent.cs", ControlledHangMitigatingCancellationToken);
await TestServices.Editor.VerifyTextContainsAsync("public class ZooperDooper : ComponentBase", ControlledHangMitigatingCancellationToken);
Expand Down
Loading