Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device.
Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
The Code Generation utility is a .NET 6.0 command-line application that has been integrated into the Ed-Fi ODS / API initdev process. Its responsibility is to generate C# classes, ORM mapping files for the core application, plus all profiles and extensions. It uses logic-less {{mustache}} templates that are embedded within the assembly to generate the files. The application depends on Castle Windsor for its container.
The code generation tool is located in the ODS repository under the folder Utilities\CodeGeneration.
Requirements
The following are required to build the application:
Visual Studio 2022 / JetBrains Rider 2021.3
.NET 6.0
Template Model
Template models generate an anonymous object to drive the mustache template. All template models implement the interface ITemplateModel, and these models are then installed into the container to be run.
To add a new template model:
Create a new class in the TemplateModels namespace.
assemblyModelType maps the to the template set to generate.
assemblyMetadataFormateVersion is the semantic version of the file.
For backward compatibility, profiles and extensions are also picked up using conventions. This may be removed in the future.
Template Sets
Template Sets are a grouping of Template Models that are to be rendered. This grouping is stored in an embedded object named TemplateSets.json which contains an array of TemplateSet objects.
namespace EdFi.Ods.CodeGen.Models.Configuration
{
public class TemplateSet
{
public string Name { get; set; }
public string Driver { get; set; }
public string OutputName { get; set; }
public string OutputPath { get; set; }
public override string ToString() => $@"
Name: {Name}
Driver: {Driver}
OutputName: {OutputName}
OutputPath: {OutputPath}
";
}
}
Name is the name of the template.
Driver is the C# Template Model.
OutputName is the file name that is created.
OutputPath is the location within the assembly to which the file is written.
The listing below shows the TemplateSets.json contents:
The tool accepts the following command line argument:
-r <repository path>. The repository path to the location of the solution (e.g., C:\EdFi\v3).
Building Code Generation
The solution can be built using Visual Studio 2022 or Rider 2021.3. Also, it can be built from the command line using the following command: dotnet build.
Running Tests
Tests can be run using Visual Studio Test Explorer, R# Test Runner of Rider 2021.3. Alternatively, the tests can be run using the command dotnet test.
Running Approval Tests
Included in the testing suite are approval tests that validate the code generated is as expected.
To run the tests, the following steps are required:
Step 1 : Build the solution with Visual Studio.
Step 2 : Set EdFi.Ods.Codegen.Console as the startup project. Note that the command argument is not necessary.
Step 3 : Run the solution within Visual Studio.
Step 4 : Open Test Explorer and look for the Verify_All test and run it to see if there are any failures