C# Specflow-我们可以在Specflow示例表中传递参数吗

C# Specflow-我们可以在Specflow示例表中传递参数吗,c#,api,automation,bdd,specflow,C#,Api,Automation,Bdd,Specflow,我的设想是 Scenario Outline: Verify if the user can create an response if user posts a request with invalid payload Given User had specified name <name> description <description> in create application request And User had specified ten

我的设想是

Scenario Outline: Verify if the user can create an response if user posts a request with invalid payload
    Given User had specified name <name> description <description> in create application request
    And User had specified tenantId id <tenantId> in header of createApplication request
    When User sends a create request to application service with invalidPayload
    Then User should get an error code <errorCode> in the createApplication response with error message as <errorMessage>
Examples:
| description| name | errorCode | errorMessage|tenantid|                                                            
| testdescription| DummyApplication| 857 | Application named ${name} already exists for a given tenant | mock|                   
场景大纲:验证用户是否可以在用户发布具有无效负载的请求时创建响应
给定用户在创建应用程序请求中指定了名称说明
并且用户在createApplication请求的标头中指定了tenantId
当用户使用invalidPayload向应用程序服务发送创建请求时
然后,用户应该在createApplication响应中获得一个错误代码,错误消息如下
示例:
|描述|名称|错误代码|错误消息|租户|
|给定租户| mock |的testdescription | DummyApplication | 857 |名为${name}的应用程序已存在
在上面的部分中,我想用name参数验证错误消息,示例表中已经定义了该参数的值。 作为参数传递的预期错误消息为,
“给定租户已存在名为'DummyApplication'的应用程序。”

通常的方法是在拥有变量时存储它,并在以后需要时重新使用它。例如,您可以使用ScenarioContext并拥有一个属性

 private string Name
 {
   get
   {
      return ScenarioContext.Current["Name"].ToString();
   }
   set
   {
      ScenarioContext.Current["Name"] = value;
   }
        }

[Given(@"User had specified name (.*) description (.*) in create application request")]
        public void GivenUserHadSpecifiedNameDummyApplicationDescriptionTestdescriptionInCreateApplicationRequest(string name, string description)
        {
            // store the name
            this.Name = name;
        }


        [Then(@"User should get an error code (.*) in the createApplication response with error message as (.*)")]
        public void ThenUserShouldGetAnErrorCodeInTheCreateApplicationResponseWithErrorMessageAsApplicationNamedNameAlreadyExistsForAGivenTenant(int errorCode, string errorMessage)
        {
            // retrieve the name and use
            var expected = errorMessage.Replace("${name}", $"'{this.Name}'");
            //Application named 'DummyApplication' already exists for a given tenant

        }

在当前的specflow示例表中,给定租户已存在名为${name}的应用程序| mock |如果上面的name参数将来更改为ApplicationName,我不需要从中更改errorMessage参数吗${name}到${ApplicationName}以及在步骤定义代码
var expected=errorMessage.Replace(${name},$“{this.name}”);
在上述代码中,我需要将${name}替换为${ApplicationName}抱歉,我刚刚重新阅读了此内容。如果您的意思是将specflow定义更改为| description | ApplicationName |…-在这种情况下,您无需更改任何内容,specflow步骤需要两个参数-一个用于名称,一个用于描述。它们的名称无关紧要。$(名称)在specflow errror messages中,示例只是一个占位符,它会被替换。