将 SpecFlow 特征步骤与字符串内的双引号匹配

Match a SpecFlow feature step with double quotes inside of a string

我有一步

Then I must see the 3 text text text "Text" as one of the search results

还有一个步骤定义

[Then(@"I must see the (.*) as one of the search results")]

无论我在步骤定义中向正则表达式 "' 添加哪些符号,我都会得到

"3 text text text \"Text\""

在这种情况下,我不想转义引号,而是在一步中抓取预定义数据的精确匹配。

In this case, I don't want to escape quotes, but to grab the exact match of predefined data in a step.

我相信您正在寻找完全匹配的引号。在那种情况下,其中一个实现可以使用 doc string

小黄瓜会是

Then I must see below text as one of the search results

  """
  3 text text text "Text" 
  """

步骤定义为

 [Then(@"I must see below text as one of the search results")]
    
            public void docStringOnlyTest(string docString)
            {
                
                log.Info(docString);
            }

这将在控制台

上记录3 text text text "Text"

doc 字符串被捕获为步骤定义中的最后一个参数,并由三引号定义 """