Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "https://json.schemastore.org/dotnetcli.host"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"author": "Microsoft",
"name": "Razor Component with Code-Behind",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"symbols/namespace/description": "namespace for the generated code",
"postActions/openInEditor/description": "Opens Component1.razor in the editor"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "https://json.schemastore.org/template",
"author": "Microsoft",
"classifications": [
"Web",
"ASP.NET"
],
"name": "Razor Component with Code-Behind",
"generatorVersions": "[1.0.0.0-*)",
"description": "A reusable UI component implemented with Razor and a code-behind file",
"tags": {
"language": "C#",
"type": "item"
},
"groupIdentity": "Microsoft.AspNetCore.Components.RazorComponentCodeBehind",
"precedence": "10000",
"identity": "Microsoft.AspNetCore.Components.RazorComponentCodeBehind.10.0",
"shortname": "razorcomponent-cb",
"sourceName": "Component1",
"primaryOutputs": [
{
"path": "Component1.razor"
},
{
"path": "Component1.razor.cs"
}
],
"defaultName": "Component1",
"symbols": {
"namespace": {
"description": "namespace for the generated code",
"replaces": "MyApp.Namespace",
"type": "parameter"
},
"HostIdentifier": {
"type": "bind",
"binding": "HostIdentifier"
}
},
"postActions": [
{
"id": "openInEditor",
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens Component1.razor in the editor",
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "0"
},
"continueOnError": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>Component1</h3>

@code {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Components;

namespace MyApp.Namespace
{
public partial class Component1 : ComponentBase
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ public async Task BlazorServerItemTemplate()
Project.AssertFileExists("Different.razor", shouldExist: true);
Assert.Contains("<h3>Different</h3>", Project.ReadFile("Different.razor"));
}

[Fact]
public async Task BlazorServerItemTemplateCodeBehind()
{
Project = await ProjectFactory.CreateProject(Output);

await Project.RunDotNetNewAsync("razorcomponent-cb --name CodeBehindComponent", isItemTemplate: true);

Project.AssertFileExists("CodeBehindComponent.razor", shouldExist: true);
Project.AssertFileExists("CodeBehindComponent.razor.cs", shouldExist: true);

var razorContent = Project.ReadFile("CodeBehindComponent.razor");
var codeContent = Project.ReadFile("CodeBehindComponent.razor.cs");

Assert.Contains("<h3>CodeBehindComponent</h3>", razorContent);
Assert.Contains("public partial class CodeBehindComponent : ComponentBase", codeContent);
Assert.Contains("using Microsoft.AspNetCore.Components;", codeContent);
}
}
Loading