Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosifne committed Dec 12, 2023
1 parent 2ba6479 commit dd66b72
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.Editor.InlineRename;
using Microsoft.CodeAnalysis.InlineRename;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
Expand Down Expand Up @@ -719,5 +718,57 @@ public class Class2
public int LongOtherStuff$$Field;
}", HangMitigatingCancellationToken);
}

[IdeFact]
public async Task VerifyRenameLinkedDocumentsAsync()
{
var projectName = "MultiTFMProject";
await TestServices.SolutionExplorer.AddCustomProjectAsync(projectName, ".csproj", @"
<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0-windows;net48</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
</PropertyGroup>
</Project>
", HangMitigatingCancellationToken);

var startCode = @"
public class TestClass
{
}
";
await TestServices.SolutionExplorer.AddFileAsync(projectName, "TestClass.cs", startCode, cancellationToken: HangMitigatingCancellationToken);

var referencedCode = @"
public class MyClass
{
void Method()
{
TestClass x = new TestClass();
}
}";
await TestServices.SolutionExplorer.AddFileAsync(projectName, "MyClass.cs", referencedCode, cancellationToken: HangMitigatingCancellationToken);

await TestServices.SolutionExplorer.OpenFileAsync(projectName, "TestClass.cs", HangMitigatingCancellationToken);
await TestServices.SolutionExplorer.OpenFileAsync(projectName, "MyClass.cs", HangMitigatingCancellationToken);
await TestServices.Editor.PlaceCaretAsync("TestClass", charsOffset: 0, HangMitigatingCancellationToken);
await TestServices.InlineRename.InvokeAsync(HangMitigatingCancellationToken);
await TestServices.Input.SendWithoutActivateAsync([VirtualKeyCode.HOME, "M", "y", VirtualKeyCode.RETURN], HangMitigatingCancellationToken);
await TestServices.Workspace.WaitForRenameAsync(HangMitigatingCancellationToken);
await TestServices.EditorVerifier.TextEqualsAsync(
@"
public class MyClass
{
void Method()
{
MyTestClass x = new MyTestClass();
}
}", HangMitigatingCancellationToken);
// Make sure the file is renamed.
await TestServices.SolutionExplorer.GetProjectItemAsync(projectName, "./MyTestClass.cs", HangMitigatingCancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public async Task RenameFileAsync(string projectName, string oldFileName, string
projectItem.Name = newFileName;
}

private async Task<EnvDTE.ProjectItem> GetProjectItemAsync(string projectName, string relativeFilePath, CancellationToken cancellationToken)
public async Task<EnvDTE.ProjectItem> GetProjectItemAsync(string projectName, string relativeFilePath, CancellationToken cancellationToken)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

Expand Down

0 comments on commit dd66b72

Please sign in to comment.