-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In case of optional parameter get error of "Parameter count mismatch" #509
Comments
Is this during execution or design time in VS2022? And NUnit right? Related code for this:
|
It's during the test execution and yes, NUnit |
It looks like optional parameters aren't supported in Reqnroll. I will test with SpecFlow to be sure |
I'm not sure why you don't got an error with SpecFlow, but I get this with SpecFlow 3.9.74
|
This is a documentation issue. I've created a feature request for this, see: https://github.com/orgs/reqnroll/discussions/510 I will update the docs |
Now Reqnroll doesn't support optional parameters, public class RegexOptionalGroups : IRuntimePlugin
{
public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginParameters runtimePluginParameters,
UnitTestProviderConfiguration unitTestProviderConfiguration)
{
runtimePluginEvents.CustomizeGlobalDependencies += RuntimePluginEvents_CustomizeGlobalDependencies;
}
private void RuntimePluginEvents_CustomizeGlobalDependencies(object sender, CustomizeGlobalDependenciesEventArgs e)
{
e.ObjectContainer.RegisterTypeAs<MyMatchArgumentCalculator, IMatchArgumentCalculator>();
}
public class MyMatchArgumentCalculator : IMatchArgumentCalculator
{
public object[] CalculateArguments(Match match, StepInstance stepInstance,
IStepDefinitionBinding stepDefinitionBinding)
{
var regexArgs = match.Groups.Cast<Group>().Skip(1);
if (stepDefinitionBinding.ExpressionType == "CucumberExpression")
{
regexArgs = regexArgs.Where(g => g.Success);
}
List<object> arguments = regexArgs.Select(g => g.Value).Cast<object>().ToList();
if (stepInstance.MultilineTextArgument != null)
{
arguments.Add(stepInstance.MultilineTextArgument);
}
if (stepInstance.TableArgument != null)
{
arguments.Add(stepInstance.TableArgument);
}
return arguments.ToArray();
}
}
} @gasparnagy maybe I add docs page for this case? like we have for forcing regex step def |
@olegKoshmeliuk |
Yes in SecFlow 3.x.
|
@zsbolgar also other example of plugin #181 (comment) |
@olegKoshmeliuk sorry, does it mean, that there will be no solution/fix in reqnroll? |
@zsbolgar solution is add IMatchArgumentCalculator plugin to your solution, it will fix your steps. |
thanks @olegKoshmeliuk. Is there a place where I can find how to add this kind of plugin to the solution? |
@olegKoshmeliuk the optional parameter case should look like this? public void ThenCalledApiHasFollowingResponse(string _, int seconds = 20)
{
Console.WriteLine(seconds);
} |
@zsbolgar it's simple CS file in project |
See also https://docs.reqnroll.net/latest/extend/plugins.html |
Thank you @olegKoshmeliuk and @304NotModified, I'm going to check it. |
Used Visual Studio
Visual Studio 2022 + NUnit
Are the latest Visual Studio updates installed?
Yes
Content of reqnroll.json (if present)
Issue Description
Step with optional parameter gives error if I call without the optional parameter.
Steps to Reproduce
I use optional parameter in several steps, eg: "^the Show User Properties checkbox is( not)? selected$"
The step method has paramter (string selected)
In case if I call without the optional parameter I get this error.
Link to a project repository that reproduces the issue
No response
The text was updated successfully, but these errors were encountered: