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 @@ -142,7 +142,7 @@ private static string PopulateMethodSignature(VersionedDocumentContext documentC
{
var templateWithMethodSignature = s_generateMethodTemplate.Replace(s_methodName, actionParams.MethodName);

var returnType = actionParams.IsAsync ? "async System.Threading.Tasks.Task" : "void";
var returnType = actionParams.IsAsync ? "System.Threading.Tasks.Task" : "void";
templateWithMethodSignature = templateWithMethodSignature.Replace(s_returnType, returnType);

var eventTagHelper = documentContext.Project.TagHelpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class CodeActionEndToEndTest : SingleServerDelegatingEndpointTestBase
private const string GenerateEventHandlerTitle = "Generate Event Handler 'DoesNotExist'";
private const string GenerateAsyncEventHandlerTitle = "Generate Async Event Handler 'DoesNotExist'";
private const string GenerateEventHandlerReturnType = "void";
private const string GenerateAsyncEventHandlerReturnType = "async System.Threading.Tasks.Task";
private const string GenerateAsyncEventHandlerReturnType = "System.Threading.Tasks.Task";
private const string CodeBehindTestReplaceNamespace = "$$Replace_Namespace$$";

private static GenerateMethodCodeActionResolver[] CreateRazorCodeActionResolversFn(
string filePath,
Expand Down Expand Up @@ -675,7 +676,6 @@ await ValidateCodeActionAsync(input,
[InlineData("\r\npublic void Exists(){}\r\n")]
public async Task Handle_GenerateMethod_CodeBehindFile_Exists(string spacingOrMethod)
{
var @namespace = $"Test.{Path.GetTempPath().Replace(":", "_").Replace("\\", ".")[..^1]}";
var input = """
<button @onclick="[||]DoesNotExist"></button>
""";
Expand All @@ -685,7 +685,7 @@ public async Task Handle_GenerateMethod_CodeBehindFile_Exists(string spacingOrMe
""";

var initialCodeBehindContent = $$"""
namespace {{@namespace}}
namespace {{CodeBehindTestReplaceNamespace}}
{
public partial class test
{{{spacingOrMethod}}
Expand All @@ -694,7 +694,7 @@ public partial class test
""";

var expectedCodeBehindContent = $$"""
namespace {{@namespace}}
namespace {{CodeBehindTestReplaceNamespace}}
{
public partial class test
{{{spacingOrMethod}}
Expand All @@ -720,7 +720,6 @@ await ValidateCodeBehindFileAsync(
[InlineData("\r\npublic void Exists(){}\r\n")]
public async Task Handle_GenerateAsyncMethod_CodeBehindFile_Exists(string spacingOrMethod)
{
var @namespace = $"Test.{Path.GetTempPath().Replace(":", "_").Replace("\\", ".")[..^1]}";
var input = """
<button @onclick="[||]DoesNotExist"></button>
""";
Expand All @@ -730,7 +729,7 @@ public async Task Handle_GenerateAsyncMethod_CodeBehindFile_Exists(string spacin
""";

var initialCodeBehindContent = $$"""
namespace {{@namespace}}
namespace {{CodeBehindTestReplaceNamespace}}
{
public partial class test
{{{spacingOrMethod}}
Expand All @@ -739,7 +738,7 @@ public partial class test
""";

var expectedCodeBehindContent = $$"""
namespace {{@namespace}}
namespace {{CodeBehindTestReplaceNamespace}}
{
public partial class test
{{{spacingOrMethod}}
Expand Down Expand Up @@ -789,7 +788,6 @@ await ValidateCodeBehindFileAsync(
[Fact]
public async Task Handle_GenerateMethod_CodeBehindFile_FileScopedNamespace()
{
var @namespace = $"Test.{Path.GetTempPath().Replace(":", "_").Replace("\\", ".")[..^1]}";
var input = """
<button @onclick="[||]DoesNotExist"></button>
""";
Expand All @@ -799,14 +797,14 @@ public async Task Handle_GenerateMethod_CodeBehindFile_FileScopedNamespace()
""";

var initialCodeBehindContent = $$"""
namespace {{@namespace}};
namespace {{CodeBehindTestReplaceNamespace}};
public partial class test
{
}
""";

var expectedCodeBehindContent = $$"""
namespace {{@namespace}};
namespace {{CodeBehindTestReplaceNamespace}};
public partial class test
{
private void DoesNotExist(Microsoft.AspNetCore.Components.Web.MouseEventArgs e)
Expand Down Expand Up @@ -848,10 +846,11 @@ private async Task ValidateCodeBehindFileAsync(
await CreateLanguageServerAsync(codeDocument, razorFilePath);
var documentContext = CreateDocumentContext(uri, codeDocument);
var requestContext = new RazorRequestContext(documentContext, Logger, null!);

File.Create(codeBehindFilePath).Close();
try
{
codeDocument.TryComputeNamespace(fallbackToRootNamespace: true, out var @namespace);
initialCodeBehindContent = initialCodeBehindContent.Replace(CodeBehindTestReplaceNamespace, @namespace);
File.WriteAllText(codeBehindFilePath, initialCodeBehindContent);

var result = await GetCodeActionsAsync(uri, textSpan, razorSourceText, requestContext, razorCodeActionProviders: new[] { new GenerateMethodCodeActionProvider() }, diagnostics);
Expand All @@ -876,7 +875,7 @@ private async Task ValidateCodeBehindFileAsync(
AssertEx.EqualOrDiff(expectedRazorContent, actualRazorContent);

var actualCodeBehindContent = codeBehindSourceText.WithChanges(codeBehindEdits).ToString();
AssertEx.EqualOrDiff(expectedCodeBehindContent, actualCodeBehindContent);
AssertEx.EqualOrDiff(expectedCodeBehindContent.Replace(CodeBehindTestReplaceNamespace, @namespace), actualCodeBehindContent);
}
finally
{
Expand Down