Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Jul 19, 2024
1 parent 5d75e5e commit a2fcfd4
Show file tree
Hide file tree
Showing 21 changed files with 547 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,93 @@ public class MyComponent<T> : ComponentBase
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48778")]
public void ImplicitStringConversion_ParameterCasing_AddAttribute()
{
_configuration = base.Configuration with { LanguageVersion = RazorLanguageVersion.Version_7_0 };

AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;
namespace Test;
public class MyClass
{
public static implicit operator string(MyClass c) => "";
}
public class MyComponent : ComponentBase
{
[Parameter] public string Placeholder { get; set; } = "";
}
"""));

var generated = CompileToCSharp("""
<MyComponent PlaceHolder="@(new MyClass())" />
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48778")]
public void ImplicitStringConversion_ParameterCasing_AddComponentParameter()
{
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;
namespace Test;
public class MyClass
{
public static implicit operator string(MyClass c) => "";
}
public class MyComponent : ComponentBase
{
[Parameter] public string Placeholder { get; set; } = "";
}
"""));

var generated = CompileToCSharp("""
<MyComponent PlaceHolder="@(new MyClass())" />
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/aspnetcore/issues/48778")]
public void ImplicitStringConversion_ParameterCasing_Multiple()
{
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;
namespace Test;
public class MyClass
{
public static implicit operator string(MyClass c) => "";
}
public class MyComponent : ComponentBase
{
[Parameter] public string Placeholder { get; set; } = "";
[Parameter] public string PlaceHolder { get; set; } = "";
}
"""));

var generated = CompileToCSharp("""
<MyComponent PlaceHolder="@(new MyClass())" />
""");

AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1869483")]
public void AddComponentParameter()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o =
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
;
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - - PlaceHolder - - AttributeStructure.DoubleQuotes
CSharpExpression - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1033:29,28 [13] )
|new MyClass()|

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o =
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
;
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - - PlaceHolder - - AttributeStructure.DoubleQuotes
CSharpExpression - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1033:29,28 [13] )
|new MyClass()|

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
#pragma warning disable BL0005
((global::Test.MyComponent)default).
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
PlaceHolder

#line default
#line hidden
#nullable disable
= default;
#pragma warning restore BL0005
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.MyComponent);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [20] ) - global::System
UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [25] ) - global::System.Linq
UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml) - PlaceHolder - PlaceHolder - AttributeStructure.DoubleQuotes
CSharpExpression - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (1138:29,28 [13] )
|new MyClass()|

Source Location: (13:0,13 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|PlaceHolder|
Generated Location: (1559:42,13 [11] )
|PlaceHolder|

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.OpenComponent<global::Test.MyComponent>(0);
__builder.AddAttribute(1, "PlaceHolder", (object)(
#nullable restore
#line (1,29)-(1,42) "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass()

#line default
#line hidden
#nullable disable
));
__builder.CloseComponent();
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Document -
NamespaceDeclaration - - Test
UsingDirective - (3:1,1 [22] ) - global::System
UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic
UsingDirective - (69:3,1 [27] ) - global::System.Linq
UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks
UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
MethodDeclaration - - protected override - void - BuildRenderTree
Component - (0:0,0 [46] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent
ComponentAttribute - - PlaceHolder - - AttributeStructure.DoubleQuotes
CSharpExpression - (26:0,26 [16] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source Location: (28:0,28 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass()|
Generated Location: (867:23,0 [13] )
|new MyClass()|

Loading

0 comments on commit a2fcfd4

Please # to comment.