Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# TechTalk.SpecFlow.BindingException:';参数计数不匹配!绑定方法_C#_Specflow_Gherkin - Fatal编程技术网

C# TechTalk.SpecFlow.BindingException:';参数计数不匹配!绑定方法

C# TechTalk.SpecFlow.BindingException:';参数计数不匹配!绑定方法,c#,specflow,gherkin,C#,Specflow,Gherkin,我正在尝试为specflow编写一个StepArgumentTransformation 我有下面的小黄瓜 Scenario: Test Arguments Given user enter once as 2 我已经在步骤定义中写了这个 [StepArgumentTransformation] public int GetOnces(string onces, string times) { return 1 * int.Parse(times);

我正在尝试为specflow编写一个StepArgumentTransformation

我有下面的小黄瓜

Scenario: Test Arguments
Given user enter once as 2
我已经在步骤定义中写了这个

    [StepArgumentTransformation]
    public int GetOnces(string onces, string times)
    {
        return 1 * int.Parse(times);
    }

    [Given(@"user enter (.*) as (.*)")]
    public void GivenUserEnterOnce(int num)
    {
        Assert.Equal(2, num);
    }
但是,GetOnces方法从未被调用,我得到了异常

TechTalk.SpecFlow.BindingException:'参数计数不匹配!绑定方法“givenUserOnce(Int32)”应具有2个参数


绑定应如下所示:

[StepArgumentTransformation("(.*) as (.*)")]
public int GetOnces(string onces, string times)
{
    return 1 * int.Parse(times);
}

[Given(@"user enter (.*)")]
public void GivenUserEnterOnce(int num)
{
    Assert.Equal(2, num);
}
如果要转换的参数不止一个,则必须在StepArgumentTransformation处指定正则表达式。您的实际步骤只有get的一个参数,因此正则表达式中只有一个参数是有效的


您可以在这里找到相关文档:

对我来说,问题在于我忘记/删除了场景中的“Then”行