我的情况是
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|
在上一节中,我想验证错误消息,但具有名称参数,其值已在示例表中定义。我作为参数传递的预期错误消息是,“给定租户的名称为'DummyApplication'的应用程序已经存在。”
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
}