diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs index cb825b3307..f6ed94ed04 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RazorCompilerTest.cs @@ -374,6 +374,40 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test frame => AssertFrame.Component(frame, 0)); } + [Fact] + public void CanPassParametersToComponents() + { + // Arrange/Act + var testComponentTypeName = typeof(TestComponent).FullName.Replace('+', '.'); + var testObjectTypeName = typeof(SomeType).FullName.Replace('+', '.'); + var component = CompileToComponent($""); + var frames = GetRenderTree(component); + + // Assert + // TODO: Fix this. + // * Currently the attribute names are lowercased if they were + // parsed by AngleSharp as HTML, and left in their original case if they + // were parsed by the Razor compiler as a C# expression. They should all + // retain their original case when the target element represents a component. + // * Similarly, unquoted values are interpreted as strings if they were parsed + // by AngleSharp (e.g., intproperty=123 passes a string). The values should + // always be treated as C# expressions if the target represents a component. + // This problem will probably go away on its own when we have new component + // tooling. + Assert.Collection(frames, + frame => AssertFrame.Component(frame, 0), + frame => AssertFrame.Attribute(frame, "intproperty", "123", 1), + frame => AssertFrame.Attribute(frame, "stringproperty", "My string", 2), + frame => + { + AssertFrame.Attribute(frame, "ObjectProperty"); + Assert.IsType(frame.AttributeValue); + }); + } + [Fact] public void ComponentsDoNotHaveLayoutAttributeByDefault() { @@ -602,5 +636,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test public interface ITestInterface { } public class TestBaseClass : BlazorComponent { } + + public class SomeType { } } } diff --git a/test/shared/AssertFrame.cs b/test/shared/AssertFrame.cs index ac320e0796..d1d00d72b5 100644 --- a/test/shared/AssertFrame.cs +++ b/test/shared/AssertFrame.cs @@ -52,6 +52,12 @@ namespace Microsoft.AspNetCore.Blazor.Test.Helpers Assert.Equal(attributeEventHandlerValue, frame.AttributeValue); } + public static void Attribute(RenderTreeFrame frame, string attributeName, object attributeValue, int? sequence = null) + { + AssertFrame.Attribute(frame, attributeName, sequence); + Assert.Equal(attributeValue, frame.AttributeValue); + } + public static void Component(RenderTreeFrame frame, int? sequence = null) where T : IComponent { Assert.Equal(RenderTreeFrameType.Component, frame.FrameType);