Component item template (#9077)
This commit is contained in:
parent
45b5a04393
commit
3e1b1ac4e0
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/dotnetcli.host"
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/template",
|
||||
"author": "Microsoft",
|
||||
"classifications": [
|
||||
"Web",
|
||||
"ASP.NET"
|
||||
],
|
||||
"name": "Razor Component",
|
||||
"generatorVersions": "[1.0.0.0-*)",
|
||||
"description": "A reusable UI component implemented with Razor",
|
||||
"tags": {
|
||||
"language": "C#",
|
||||
"type": "item"
|
||||
},
|
||||
"groupIdentity": "Microsoft.AspNetCore.Components.RazorComponent",
|
||||
"precedence": "100",
|
||||
"identity": "Microsoft.AspNetCore.Components.RazorComponent",
|
||||
"shortname": "razorcomponent",
|
||||
"sourceName": "Component1",
|
||||
"primaryOutputs": [
|
||||
{
|
||||
"path": "Component1.razor"
|
||||
}
|
||||
],
|
||||
"defaultName": "Component1",
|
||||
"symbols": {
|
||||
"HostIdentifier": {
|
||||
"type": "bind",
|
||||
"binding": "HostIdentifier"
|
||||
}
|
||||
},
|
||||
"postActions": [
|
||||
{
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<h3>Component1</h3>
|
||||
|
||||
@functions {
|
||||
|
||||
}
|
||||
|
|
@ -347,6 +347,27 @@ namespace Templates.Test.Helpers
|
|||
}
|
||||
}
|
||||
|
||||
public void AssertFileExists(string path, bool shouldExist)
|
||||
{
|
||||
var fullPath = Path.Combine(TemplateOutputDir, path);
|
||||
var doesExist = File.Exists(fullPath);
|
||||
|
||||
if (shouldExist)
|
||||
{
|
||||
Assert.True(doesExist, "Expected file to exist, but it doesn't: " + path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(doesExist, "Expected file not to exist, but it does: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
public string ReadFile(string path)
|
||||
{
|
||||
AssertFileExists(path, shouldExist: true);
|
||||
return File.ReadAllText(Path.Combine(TemplateOutputDir, path));
|
||||
}
|
||||
|
||||
internal async Task<ProcessEx> RunDotNetNewRawAsync(string arguments)
|
||||
{
|
||||
await DotNetNewLock.WaitAsync();
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ namespace Templates.Test.Helpers
|
|||
{
|
||||
public class ProjectFactoryFixture : IDisposable
|
||||
{
|
||||
private static SemaphoreSlim DotNetNewLock = new SemaphoreSlim(1);
|
||||
private static SemaphoreSlim NodeLock = new SemaphoreSlim(1);
|
||||
private readonly static SemaphoreSlim DotNetNewLock = new SemaphoreSlim(1);
|
||||
private readonly static SemaphoreSlim NodeLock = new SemaphoreSlim(1);
|
||||
|
||||
private ConcurrentDictionary<string, Project> _projects = new ConcurrentDictionary<string, Project>();
|
||||
private readonly ConcurrentDictionary<string, Project> _projects = new ConcurrentDictionary<string, Project>();
|
||||
|
||||
public IMessageSink DiagnosticsMessageSink { get; }
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
// 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 System.Threading.Tasks;
|
||||
using Templates.Test.Helpers;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Templates.Items.Test
|
||||
{
|
||||
public class RazorComponentsTest
|
||||
{
|
||||
public RazorComponentsTest(ProjectFactoryFixture projectFactory, ITestOutputHelper output)
|
||||
{
|
||||
ProjectFactory = projectFactory;
|
||||
Output = output;
|
||||
}
|
||||
|
||||
public Project Project { get; set; }
|
||||
|
||||
public ProjectFactoryFixture ProjectFactory { get; }
|
||||
public ITestOutputHelper Output { get; }
|
||||
|
||||
[Fact]
|
||||
public async Task RazorComponentsItemTemplate()
|
||||
{
|
||||
Project = await ProjectFactory.GetOrCreateProject("razorcomponentitem", Output);
|
||||
|
||||
var createResult = await Project.RunDotNetNewAsync("razorcomponent --name Different");
|
||||
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create", Project, createResult));
|
||||
|
||||
Project.AssertFileExists("Different.razor", shouldExist: true);
|
||||
Assert.Contains("<h3>Different</h3>", Project.ReadFile("Different.razor"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,13 +34,8 @@ namespace Templates.Test
|
|||
var createResult = await Project.RunDotNetNewAsync("mvc", language: languageOverride);
|
||||
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", Project, createResult));
|
||||
|
||||
AssertDirectoryExists(Project.TemplateOutputDir, "Areas", false);
|
||||
AssertDirectoryExists(Project.TemplateOutputDir, "Extensions", false);
|
||||
AssertFileExists(Project.TemplateOutputDir, "urlRewrite.config", false);
|
||||
AssertFileExists(Project.TemplateOutputDir, "Controllers/AccountController.cs", false);
|
||||
|
||||
var projectExtension = languageOverride == "F#" ? "fsproj" : "csproj";
|
||||
var projectFileContents = ReadFile(Project.TemplateOutputDir, $"{Project.ProjectName}.{projectExtension}");
|
||||
var projectFileContents = Project.ReadFile($"{Project.ProjectName}.{projectExtension}");
|
||||
Assert.DoesNotContain(".db", projectFileContents);
|
||||
Assert.DoesNotContain("Microsoft.EntityFrameworkCore.Tools", projectFileContents);
|
||||
Assert.DoesNotContain("Microsoft.VisualStudio.Web.CodeGeneration.Design", projectFileContents);
|
||||
|
|
@ -112,11 +107,7 @@ namespace Templates.Test
|
|||
var createResult = await Project.RunDotNetNewAsync("mvc", auth: "Individual", useLocalDB: useLocalDB);
|
||||
Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", Project, createResult));
|
||||
|
||||
AssertDirectoryExists(Project.TemplateOutputDir, "Extensions", false);
|
||||
AssertFileExists(Project.TemplateOutputDir, "urlRewrite.config", false);
|
||||
AssertFileExists(Project.TemplateOutputDir, "Controllers/AccountController.cs", false);
|
||||
|
||||
var projectFileContents = ReadFile(Project.TemplateOutputDir, $"{Project.ProjectName}.csproj");
|
||||
var projectFileContents = Project.ReadFile($"{Project.ProjectName}.csproj");
|
||||
if (!useLocalDB)
|
||||
{
|
||||
Assert.Contains(".db", projectFileContents);
|
||||
|
|
@ -226,41 +217,5 @@ namespace Templates.Test
|
|||
await aspNetProcess.AssertPagesOk(pages);
|
||||
}
|
||||
}
|
||||
|
||||
private void AssertDirectoryExists(string basePath, string path, bool shouldExist)
|
||||
{
|
||||
var fullPath = Path.Combine(basePath, path);
|
||||
var doesExist = Directory.Exists(fullPath);
|
||||
|
||||
if (shouldExist)
|
||||
{
|
||||
Assert.True(doesExist, "Expected directory to exist, but it doesn't: " + path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(doesExist, "Expected directory not to exist, but it does: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
private void AssertFileExists(string basePath, string path, bool shouldExist)
|
||||
{
|
||||
var fullPath = Path.Combine(basePath, path);
|
||||
var doesExist = File.Exists(fullPath);
|
||||
|
||||
if (shouldExist)
|
||||
{
|
||||
Assert.True(doesExist, "Expected file to exist, but it doesn't: " + path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.False(doesExist, "Expected file not to exist, but it does: " + path);
|
||||
}
|
||||
}
|
||||
|
||||
private string ReadFile(string basePath, string path)
|
||||
{
|
||||
AssertFileExists(basePath, path, shouldExist: true);
|
||||
return File.ReadAllText(Path.Combine(basePath, path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue