-
Notifications
You must be signed in to change notification settings - Fork 0
Enabling model transformations
Romfos edited this page Feb 26, 2026
·
2 revisions
There some cases when could be useful to use C# models in gherkin steeps.
For you have model like this:
internal sealed class CustomModel
{
public required int First { get; init; }
public required string Second { get; init; }
}And gherkin step like this:
namespace BddDotNetAot.Steps;
internal sealed class Steps5
{
[When("this is given step with model transformation:")]
public void Step1(CustomModel model)
{
// use model
}
}And Feature file like this:
Scenario: step with model transformation scenario
When this is given step with model transformation:
| Name | Value |
| First | 1 |
| Second | abcd |- You need to install
BddDotNet.Gherkin.Modelsnuget package
<PackageReference Include="BddDotNet.Gherkin.Models" Version="2.1.0" />- Call
ModelTransformation<CustomModel>()extension method onIServiceCollectiontype in Program.cs
using BddDotNet;
using BddDotNet.Gherkin.Models;
using BddDotNetAot.Models;
using BddDotNetAot.Transformations;
using Microsoft.Testing.Platform.Builder;
var builder = await TestApplication.CreateBuilderAsync(args);
var services = builder.AddBddDotNet();
services.SourceGeneratedGherkinScenarios();
services.SourceGeneratedGherkinSteps();
services.ModelTransformation<CustomModel>();
using var testApp = await builder.BuildAsync();
return await testApp.RunAsync();Key points:
- Model should have at least 1 constructor. First constructor will be used.
- Public properties with
setare supported - Public fields with are supported
- Records are supported
- Nested models are not supported for now
- Each model transformation should be registered in
Program.cs
Setup
BddDotNet
Extensibility
Gherkin