SpecFlow 方法绑定中正则表达式匹配之间的细微差别

Subtle differences between regex matching in SpecFlow method binding

我想为两个单独的方法定义这两个步骤绑定:

Given I remember {word} as {key}
And I remember that {key} is {word}

问题是我目前拥有的绑定是:

[Given(@"I remember (.*) as (.*)")]
[Given(@"I remember that (.*) is (.*)")]

当然,这些被评估为重复项,因为第一个绑定中的 (.*) 覆盖了第二个绑定。

如何指定正则表达式来区分这些绑定?具体来说,因此包含 that 会导致第二个绑定匹配,而省略 that 会匹配第一个绑定。

我想确保第一个子句和后面的子句在任何模式之前的第一部分是不同的。 例如

Given I remember {word} as {key}

And I also remember that {key} is {word}

这样在第一个模式之前就没有公共部分了。

反复试验产生了这个可行的解决方案...

这个功能步骤

Given I remember {word} as {key}

匹配此方法属性

[Given(@"I remember (?!that)(.*) as (.*)")]

以及这个特征步骤

And I remember that {key} is {word}

匹配此方法属性

[Then(@"^I remember that (.*) is equal to (.*)$")]