Skip to content

Commit 11e6f0c

Browse files
committed
Add a test
1 parent 7a23d44 commit 11e6f0c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorComponentTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,46 @@ public static class RuntimeHelpers
274274
Assert.DoesNotContain("AddComponentParameter", source.SourceText.ToString());
275275
}
276276

277+
[Fact]
278+
public async Task ComponentParameter_UnnecessaryAt()
279+
{
280+
// Arrange
281+
var project = CreateTestProject(new()
282+
{
283+
["Views/Home/Index.cshtml"] = """
284+
@(await Html.RenderComponentAsync<MyApp.Shared.Component1>(RenderMode.Static))
285+
""",
286+
["Shared/Component1.razor"] = """
287+
@{
288+
var hi = "str";
289+
var x = 21;
290+
}
291+
<Component2 IntParam="42" StrParam="hi" />
292+
<Component2 IntParam="@(43)" StrParam="@hi" />
293+
<Component2 IntParam="@x" StrParam="@("lit")" />
294+
<Component2 IntParam="x * 3" StrParam="@(hi + "hey")" />
295+
""",
296+
["Shared/Component2.razor"] = """
297+
I: @(IntParam + 1), S: @StrParam.ToUpperInvariant()
298+
299+
@code {
300+
[Parameter] public int IntParam { get; set; }
301+
[Parameter] public required string StrParam { get; set; }
302+
}
303+
"""
304+
});
305+
var compilation = await project.GetCompilationAsync();
306+
var driver = await GetDriverAsync(project);
307+
308+
// Act
309+
var result = RunGenerator(compilation!, ref driver, out compilation);
310+
311+
// Assert
312+
Assert.Empty(result.Diagnostics);
313+
Assert.Equal(3, result.GeneratedSources.Length);
314+
await VerifyRazorPageMatchesBaselineAsync(compilation, "Views_Home_Index");
315+
}
316+
277317
[Fact, WorkItem("https://github.com/dotnet/razor/issues/8660")]
278318
public async Task TypeArgumentsCannotBeInferred()
279319
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
I: 43, S: HI
2+
I: 44, S: STR
3+
I: 22, S: LIT
4+
I: 64, S: STRHEY

0 commit comments

Comments
 (0)