Closed andyjbenham closed 1 year ago
It would seem that the documentation page for StepArgumentTranformation can be misleading and does not contain a complete sample. In the code you provide, both the Step definition and the StepArgumentTransformation attributes use the same Regex which confuses the system (the Step binding matches and so it attempts to process the transformation without invoking the custom StepArgumentTransformer).
A simple fix for the example is to make each Regex unique.
[Given("in (.*)")]
public void GivenTheDate(DateTime dt)
{
}
[StepArgumentTransformation(@"(\d+) days")]
public DateTime InXDaysTransform(int days)
{
return DateTime.Today.AddDays(days);
}
This approach works because the beginning of the binding phrase "in ..." indicates which Binding step to use. The regex of "(\d+) days" indicates which StepArgumentTransformer to use. For example, you might also have other transformers that calculate dates by adding weeks or months or years.
TL;DR: the regex which is used in the StepArgumentTransformer cannot be entire pattern used to match/identify the Step.
HTH
Thanks! That makes sense. Cheers for your prompt response
Thanks! That makes sense. Cheers for your prompt response
Glad to help. Please close this issue if you have no further questions about this topic.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
SpecFlow Version
3.9.74
Which test runner are you using?
NUnit
Test Runner Version Number
3.9.74
.NET Implementation
.NET 6.0
Project Format of the SpecFlow project
Classic project format using
<PackageReference>
tags.feature.cs files are generated using
SpecFlow.Tools.MsBuild.Generation NuGet package
Test Execution Method
Visual Studio Test Explorer
SpecFlow Section in app.config or content of specflow.json
No response
Issue Description
Simple transformations for a given type are working but when specifying regex step text - even using a simple example from your documentation the StepArgumentTransformation does not execute and a System.FormatException is generated
Steps to Reproduce
Feature:
Step:
Transformation:
Link to Repro Project
No response