【发布时间】:2020-11-13 22:24:59
【问题描述】:
我有一个场景大纲,其中包含向 oData Web API 发出 GET 请求以从中获取一些数据的场景。设想 验证从 API 返回的数据是否根据过滤器和正确的顺序。 Order by 子句是根据场景中提供的表构建的
Scenario Outline: Validate that data from API call for a given user is according to filters provided
Given for the user id of 101
Given default filters for GET request
Given the result multicolumn order direction is <firstColumn> <firstOrderby> then <secondColumn> <secondOrderby>
And following is unordered list of securities
| securityID | attribute1 | attribute2 | attribute3 | attribute4 |
| 16654 | active | 0 | pending | 33 |
| 16655 | active | 0 | pending | 33 |
| 16656 | active | 0 | pending | 33 |
| 16657 | active | 0 | pending | 33 |
| 16658 | inactive | 4 | pending | 33 |
| 16659 | active | 0 | pending | 33 |
| 16660 | active | 0 | pending | 33 |
| 16661 | active | 0 | pending | 33 |
| 16662 | active | 0 | pending | 33 |
| 16663 | inactive | 0 | pending | 33 |
| 16664 | inactive | 2 | pending | 33 |
When I invoke the API GET
Then the SecAPI should return HTTP <statusCode>
And the response securities should be in expected order in each <sampleName> with matching fields and record count of 11
Examples:
| firstColumn | firstOrderby | secondColumn | secondOrderby | statusCode | sampleName |
| securityID | Asc | attribute2 | Desc | 200 | Asc-Desc |
| securityID | Asc | attribute2 | Asc | 200 | Asc-Asc |
| securityID | Desc | attribute2 | Asc | 200 | Desc-Asc |
| securityID | Asc | attribute2 | Desc | 200 | Asc-Desc |
| securityID | Asc | attribute2 | | 200 | Asc-Desc |
| securityID | | attribute2 | | 200 | Asc-Desc |
对于上述场景大纲,除了以下给出的声明外,一切正常:
Given the result multicolumn order direction is <firstColumn> <firstOrderby> then <secondColumn> <secondOrderby>
对于上述声明,我在steps.cs文件中有以下步骤
[Given(@"the result multicolumn (order direction is (.*) (.*) then (.*) (.*))")]
public void GivenTheResultOrderDirectionIs(StringWrapper orderBy)
{
//step code here
}
并按照 steptransformation 将给定语句中的 4 个参数转换为正确的 oData orderBy 子句:
[Binding]
public class CustomTransforms
{
[StepArgumentTransformation(@"order direction is <(\w+)> <(\w+)> then <(\w+)> <(\w+)>")]
public StringWrapper OrderByTransform(string column1, string column1Direction, string column2, string column2Direction)
{
string orderByClause;
//build clause here
return new StringWrapper(orderByClause);
}
}
问题是 OrderByClauseTransform 永远不会被调用。我遇到了以下异常:
抛出异常:TechTalk.SpecFlow.dll 中的“TechTalk.SpecFlow.BindingException” TechTalk.SpecFlow.dll 中出现“TechTalk.SpecFlow.BindingException”类型的异常,但未在用户代码中处理 参数计数不匹配!绑定方法'.......GivenTheResultMulticolumnOrderDirectionIs(StringWrapper)'应该有5个参数
【问题讨论】:
-
\w不匹配<也不匹配>。你需要two column order is <(\w+)> <(\w+)> then <(\w+)> <(\w+)> -
还是不行。错误与 Given... 方法需要 5 个参数相同。它不是在研究变换方法。如果我从给定...方法中删除额外的 () 则错误说它需要 4 个参数
-
你能格式化你的场景大纲并更正它吗?存在一些格式错误,因此我们不确定这是否是导致问题的原因。
-
我已经重新格式化并更新了场景大纲。我不允许发布真实代码,所以这是对问题的模拟。
-
会不会是SpecFlow转换不支持多个参数?