question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a Way to Validate Templates

See original GitHub issue

It’s very easy to build and deploy a broken template. In particular, you might add complicated symbols that cause the project to fail to build when the user selects certain options. One way to help solve this is to validate the template. The validator would

  1. Validate the template.json file.
  2. Create the template with the default symbols, build it, maybe run it using the ASP.NET Core TestHost API to ensure it works.
  3. Foreach symbol, provide a non-default value, then build it, maybe run it using the ASP.NET Core TestHost API.

I’m currently planning to do the above using xUnit tests. However, you might know a better way using the templating internals and Roslyn perhaps?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RehanSaeedcommented, May 31, 2017

I’ve written some code to run tests against a template that lets you do this:

[Fact]
public async Task Home_BuildsAndRuns_Returns200Ok()
{
    // Find the location of the template project in the current solution.
    var projectDirectoryPath = TemplateAssert.GetProjectDirectoryPath(
        this.GetType().GetTypeInfo().Assembly,
        "ApiTemplate.csproj");
    TemplateAssert.DotnetNewInstall(projectDirectoryPath).Wait();

    using (var project = await TemplateAssert.DotnetNew("bapi", "HomeTest"))
    {
        await TemplateAssert.DotnetRestore(project.DirectoryPath);
        await TemplateAssert.DotnetBuild(project.DirectoryPath);
        await TemplateAssert.DotnetPublish(project.DirectoryPath, "netcoreapp1.1");
        await TemplateAssert.NpmInstall(project.DirectoryPath);
        await TemplateAssert.Gulp(project.DirectoryPath, "build");
        await TemplateAssert.DotnetRun(
            project.DirectoryPath,
            async testServer =>
            {
                var response = await testServer.CreateClient().GetAsync("/");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            });
    }
}

Right now it all works but with one issue remaining. DotnetRun dynamically loads the published assemblies and attempts to bootstrap the Startup class using the ASP.NET Core TestHost. Unfortunately, loading Swashbuckle.AspNetCore causes a TypeLoadException. It seems to have trouble with third party libraries. I’d really appreciate any help as I’m at a loss.

0reactions
RehanSaeedcommented, Jul 21, 2017

@mlorbetske My framework is still work in progress. I managed to get it working (including starting up an ASP.NET Core site using the TestHost API and executing some requests) but I had to restore, build and pubslish it as a standalone app, so it includes all the DLL’s in one folder.

I currently have issue https://github.com/dotnet/corefx/issues/21982 open in the corefx repository to see if I can do the above using a normal non-standalone publish. Once I’ve sorted this issue, I’ll release my code as a NuGet package for all to play use and profit from.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validating a template - AWS CloudFormation
The aws cloudformation validate-template command is designed to check only the syntax of your template. It does not ensure that the property values...
Read more >
Is there a way to validate CloudFormation templates before ...
After installing Perun, to validate the template you can use the command validate: ~ $ perun validate <PATH TO THE TEMPLATE>.
Read more >
validate-template — AWS CLI 2.13.11 Command Reference
Description¶. Validates a specified template. CloudFormation first checks if the template is valid JSON. If it isn't, CloudFormation checks if the template ......
Read more >
Validating a Template - Using Oracle Cloud Stack
Access the Oracle Cloud Stack console, and then click Templates. Click Unpublished. Click the template that you want to validate. The Template Builder...
Read more >
Resolve template validation or template format errors in ...
How do I resolve template validation or template format errors in CloudFormation? ... make sure that you're using the most recent version of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found