diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs index 6b359d3acc..f4a923a9bc 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs @@ -368,6 +368,43 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void Regression_609() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class User : BlazorComponent + { + public string Name { get; set; } + public Action NameChanged { get; set; } + public bool IsActive { get; set; } + public Action IsActiveChanged { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + public string UserName { get; set; } + public bool UserIsActive { get; set; } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] // https://github.com/aspnet/Blazor/issues/772 public void Regression_772() { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs index 3278500a9c..63c4d7f986 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs @@ -618,6 +618,43 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void Regression_609() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class User : BlazorComponent + { + public string Name { get; set; } + public Action NameChanged { get; set; } + public bool IsActive { get; set; } + public Action IsActiveChanged { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + public string UserName { get; set; } + public bool UserIsActive { get; set; } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] // https://github.com/aspnet/Blazor/issues/772 public void Regression_772() { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.codegen.cs new file mode 100644 index 0000000000..770bd9a042 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.codegen.cs @@ -0,0 +1,59 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + UserName + +#line default +#line hidden + ); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserName = __value, UserName); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + UserIsActive + +#line default +#line hidden + ); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserIsActive = __value, UserIsActive); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + public string UserName { get; set; } + public bool UserIsActive { get; set; } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.ir.txt new file mode 100644 index 0000000000..d50ed4106e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.ir.txt @@ -0,0 +1,47 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [60] x:\dir\subdir\Test\TestComponent.cshtml) - User - Test.User + ComponentAttributeExtensionNode - (48:1,17 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Name - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (49:1,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - UserName + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (48:1,17 [9] x:\dir\subdir\Test\TestComponent.cshtml) - NameChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserName = __value, UserName) + ComponentAttributeExtensionNode - (74:1,43 [13] x:\dir\subdir\Test\TestComponent.cshtml) - IsActive - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (75:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - UserIsActive + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (74:1,43 [13] x:\dir\subdir\Test\TestComponent.cshtml) - IsActiveChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserIsActive = __value, UserIsActive) + HtmlContent - (91:1,60 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (91:1,60 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlContent - (196:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (196:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (107:3,12 [88] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (107:3,12 [88] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n public string UserName { get; set; }\n public bool UserIsActive { get; set; }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.mappings.txt new file mode 100644 index 0000000000..77e487f350 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_609/TestComponent.mappings.txt @@ -0,0 +1,26 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (49:1,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|UserName| +Generated Location: (1135:30,18 [8] ) +|UserName| + +Source Location: (75:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|UserIsActive| +Generated Location: (1495:38,44 [12] ) +|UserIsActive| + +Source Location: (107:3,12 [88] x:\dir\subdir\Test\TestComponent.cshtml) +| + public string UserName { get; set; } + public bool UserIsActive { get; set; } +| +Generated Location: (1951:50,12 [88] ) +| + public string UserName { get; set; } + public bool UserIsActive { get; set; } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.codegen.cs new file mode 100644 index 0000000000..a3008b9415 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.codegen.cs @@ -0,0 +1,35 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.OpenComponent(0); + builder.AddAttribute(1, "Name", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(UserName)); + builder.AddAttribute(2, "NameChanged", Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserName = __value, UserName)); + builder.AddAttribute(3, "IsActive", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(UserIsActive)); + builder.AddAttribute(4, "IsActiveChanged", Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserIsActive = __value, UserIsActive)); + builder.CloseComponent(); + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + public string UserName { get; set; } + public bool UserIsActive { get; set; } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.ir.txt new file mode 100644 index 0000000000..3d4fedf1fc --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + ComponentExtensionNode - (31:1,0 [60] x:\dir\subdir\Test\TestComponent.cshtml) - User - Test.User + ComponentAttributeExtensionNode - (48:1,17 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Name - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (49:1,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - UserName + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (48:1,17 [9] x:\dir\subdir\Test\TestComponent.cshtml) - NameChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserName = __value, UserName) + ComponentAttributeExtensionNode - (74:1,43 [13] x:\dir\subdir\Test\TestComponent.cshtml) - IsActive - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (75:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - UserIsActive + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (74:1,43 [13] x:\dir\subdir\Test\TestComponent.cshtml) - IsActiveChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => UserIsActive = __value, UserIsActive) + CSharpCode - (107:3,12 [88] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (107:3,12 [88] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n public string UserName { get; set; }\n public bool UserIsActive { get; set; }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.mappings.txt new file mode 100644 index 0000000000..2fcfbd109c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Regression_609/TestComponent.mappings.txt @@ -0,0 +1,11 @@ +Source Location: (107:3,12 [88] x:\dir\subdir\Test\TestComponent.cshtml) +| + public string UserName { get; set; } + public bool UserIsActive { get; set; } +| +Generated Location: (1380:26,12 [88] ) +| + public string UserName { get; set; } + public bool UserIsActive { get; set; } +| +