diff --git a/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs b/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs index 4ec8c01221..22695000a9 100644 --- a/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs +++ b/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs @@ -244,7 +244,7 @@ namespace Microsoft.Blazor.Build.Core.RazorCompilation.Engine public override void WriteUsingDirective(CodeRenderingContext context, UsingDirectiveIntermediateNode node) { - throw new System.NotImplementedException(nameof(WriteUsingDirective)); + context.CodeWriter.WriteUsing(node.Content, endLine: true); } private static string GetContent(HtmlContentIntermediateNode node) diff --git a/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs b/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs index 7f74718fae..59d4d82e64 100644 --- a/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs +++ b/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs @@ -286,6 +286,23 @@ namespace Microsoft.Blazor.Build.Test }); } + [Fact] + public void SupportsUsingStatements() + { + // Arrange + var treeBuilder = new RenderTreeBuilder(new TestRenderer()); + + // Arrange/Act + var component = CompileToComponent(@" + @using System.Collections.Generic + @(typeof(List).FullName)"); + component.BuildRenderTree(treeBuilder); + + // Assert + Assert.Collection(treeBuilder.GetNodes().Where(NotWhitespace), + node => AssertNode.Text(node, typeof(List).FullName)); + } + private static bool NotWhitespace(RenderTreeNode node) => node.NodeType != RenderTreeNodeType.Text || !string.IsNullOrWhiteSpace(node.TextContent); diff --git a/test/testapps/BasicTestApp/KeyPressEventComponent.cs b/test/testapps/BasicTestApp/KeyPressEventComponent.cs deleted file mode 100644 index 8ca96adc4b..0000000000 --- a/test/testapps/BasicTestApp/KeyPressEventComponent.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Blazor.Components; -using Microsoft.Blazor.RenderTree; -using System.Collections.Generic; - -namespace BasicTestApp -{ - public class KeyPressEventComponent : IComponent - { - private List keysPressed = new List(); - - public void BuildRenderTree(RenderTreeBuilder builder) - { - builder.AddText("Type here:"); - builder.OpenElement("input"); - builder.AddAttribute("onkeypress", OnKeyPressed); - builder.CloseElement(); - - builder.OpenElement("ul"); - foreach (var key in keysPressed) - { - builder.OpenElement("li"); - builder.AddText(key); - builder.CloseElement(); - } - builder.CloseElement(); - } - - private void OnKeyPressed(UIEventArgs eventInfo) - { - keysPressed.Add(((UIKeyboardEventArgs)eventInfo).Key); - } - } -} diff --git a/test/testapps/BasicTestApp/KeyPressEventComponent.cshtml b/test/testapps/BasicTestApp/KeyPressEventComponent.cshtml new file mode 100644 index 0000000000..1014bbcad6 --- /dev/null +++ b/test/testapps/BasicTestApp/KeyPressEventComponent.cshtml @@ -0,0 +1,18 @@ +@using System.Collections.Generic +@using Microsoft.Blazor.RenderTree +Type here: +
    + @foreach (var key in keysPressed) + { +
  • @key
  • + } +
+ +@functions { + List keysPressed = new List(); + + void OnKeyPressed(UIEventArgs eventArgs) + { + keysPressed.Add(((UIKeyboardEventArgs)eventArgs).Key); + } +}