Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Specflow-场景输出与数据表_C#_Asp.net_Cucumber_Specflow_Gherkin - Fatal编程技术网

C# Specflow-场景输出与数据表

C# Specflow-场景输出与数据表,c#,asp.net,cucumber,specflow,gherkin,C#,Asp.net,Cucumber,Specflow,Gherkin,我有一系列类似这样的场景: Given these receipts: | Amount | Date | Company | | 1000 | 2016/10/25 | One Company | | 1200 | 2016/10/20 | Another Company | | 1500 | 2016/10/13 | My Company | And delay is 15 When I calculate date of payme

我有一系列类似这样的场景:

Given these receipts:
| Amount | Date       | Company         |
| 1000   | 2016/10/25 | One Company     |
| 1200   | 2016/10/20 | Another Company |
| 1500   | 2016/10/13 | My Company      |
And delay is 15
When I calculate date of payment
Then Date of payment should be 20

Given these receipts:
| Amount | Date       | Company         |
| 1000   | 2016/10/25 | One Company     |
| 1200   | 2016/10/20 | Another Company |
| 1500   | 2016/10/13 | My Company      |
And delay is 30
When I calculate date of payment
Then Date of payment should be 15

Given these receipts:
| Amount | Date       | Company         |
| 1000   | 2016/10/25 | One Company     |
| 1200   | 2016/10/20 | Another Company |
| 1500   | 2016/10/13 | My Company      |
And delay is 45
When I calculate date of payment
Then Date of payment should be 10
因此,我了解了场景大纲,并尝试为上述场景制作一个大纲,但由于明显的原因,在输入收据时遇到了困难:

Given these receipts: '<receipts>'
And delay is <delay>
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples:
| delay | dateOfPayment | receipts                               |
| 15    |    20         | | Amount | Date       | Company     |  |
                        | | 1000   | 2016/10/25 | one company |  |
                        | | ..............................    |  |
方案大纲不支持表替换

但是,您可以使用:

|延迟|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期。。。 |15 | 20 | 1000 | 2016/10/25 |一家公司| 1200 | 2016/10/20 |……

场景大纲不支持表格替换

但是,您可以使用:

|延迟|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期|支付日期。。。
|15 | 20 | 1000 | 2016/10/25 |一家公司| 1200 | 2016/10/20 |

我有一个愚蠢的想法:考虑到收据不会改变,我可以用实际表格而不是占位符为给定的场景提供一个大纲

它成功了:

Scenario Outline: payment
Given these receipts:
| Amount | Date       | Company         |
| 1000   | 2016/10/25 | One Company     |
| 1200   | 2016/10/20 | Another Company |
| 1500   | 2016/10/13 | My Company      |
And delay is '<delay>'
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples: 
| delay | dateOfPayment |
| 15    | 20            |
| 30    | 10            |
| 45    | 5             |
别担心,只需添加table参数,该表将作为参数传递,就像在正常场景中一样:

[Given(@"these receipts:")]
public void GivenTheseReceipts(Table table)
{
    var receipts = table.CreateSet<Receipt>(); // you can even create a set given you have defined the Receipt class
}

public class Receipt
{
    public decimal Amount { get; set; }
    public DateTime Date { get; set; }
    public string Company { get; set; }
}
现在,这只是风格的问题


还请注意,在功能文件中的所有其他场景之前,都会调用Background。

我有一个愚蠢的想法:如果收据不变,我可能会用实际表格而不是占位符为场景提供一个给定的大纲

它成功了:

Scenario Outline: payment
Given these receipts:
| Amount | Date       | Company         |
| 1000   | 2016/10/25 | One Company     |
| 1200   | 2016/10/20 | Another Company |
| 1500   | 2016/10/13 | My Company      |
And delay is '<delay>'
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples: 
| delay | dateOfPayment |
| 15    | 20            |
| 30    | 10            |
| 45    | 5             |
别担心,只需添加table参数,该表将作为参数传递,就像在正常场景中一样:

[Given(@"these receipts:")]
public void GivenTheseReceipts(Table table)
{
    var receipts = table.CreateSet<Receipt>(); // you can even create a set given you have defined the Receipt class
}

public class Receipt
{
    public decimal Amount { get; set; }
    public DateTime Date { get; set; }
    public string Company { get; set; }
}
现在,这只是风格的问题



还请注意,在功能文件中的所有其他场景之前,将调用后台。

如果“收据”数据表数据在不同场景中保持不变,则应将其保留在原始场景中的位置。把“延迟”和“付款日期”放在场景大纲示例中。但是,如果收据数据在不同的场景中发生变化,这将不起作用。数据表中三家公司的依赖关系是什么?在本例中,公司只是一个信息,它可能是另一个日期发布日期,到期日期。@Grasshopper,所以我必须为每个场景重复该表?这似乎可以以某种方式分解,可能会创建另一个场景,其中只有一个给定的参数作为参数传递给表。也许没有使用链接中提到的feturecontext?@Grasshopper我编辑了我的问题,以展示一个可能的解决方案,但我知道它不起作用,还没有在小黄瓜中实现。在场景大纲中,您将所有场景中的每一行“收据”都用在单个示例中?如果“收据”数据表数据在场景中保持不变,您应该将其保留在原始场景中的位置。把“延迟”和“付款日期”放在场景大纲示例中。但是,如果收据数据在不同的场景中发生变化,这将不起作用。数据表中三家公司的依赖关系是什么?在本例中,公司只是一个信息,它可能是另一个日期发布日期,到期日期。@Grasshopper,所以我必须为每个场景重复该表?这似乎可以以某种方式分解,可能会创建另一个场景,其中只有一个给定的参数作为参数传递给表。也许不使用链接中提到的feturecontext?@Grasshopper我编辑了我的问题,以展示一个可能的解决方案,但我知道它不起作用,还没有在Gherkinga中实现。你使用所有场景中的每一行“收据”作为场景大纲中的单个示例?它可能是一个解决方案,尽管如此,在每一个例子中都要重复这个表,这正是我想要避免的。请检查我下面的答案。出于好奇,它能与jvm一起工作吗?有了Specflow,它就可以很好地工作了!我误解了你最初的问题@sabotero-你的解决方案是正确的。我只是觉得通过创建外部类来使用数据表很奇怪。我们不能像在cucumber中那样,在specflow中将其作为arrayList或Map使用吗?它可能是一个解决方案,但它仍然会在每个示例中重复该表,这正是我想要避免的。请检查我下面的答案。出于好奇,它能与jvm一起工作吗?有了Specflow,它就可以很好地工作了!我误解了你最初的问题@sabotero-你的解决方案是正确的。我只是觉得通过创建外部类来使用数据表很奇怪。我们不能像在cucumber中那样在specflow中作为arrayList或Map使用它吗?这是有效的小黄瓜,可以用于cucumber和specflow。该表是场景大纲的一部分,因此对于每个示例都是相同的。这是有效的小黄瓜,将用于Cucumber和SpecFlow。该表是场景大纲的一部分,因此对于每个示例都是相同的。
Background: 
Given these receipts:
| Amount | Date       | Company         |
| 1000   | 2016/10/25 | One Company     |
| 1200   | 2016/10/20 | Another Company |
| 1500   | 2016/10/13 | My Company      |

Scenario Outline: payment
And delay is '<delay>'
When I calculate date of payment
Then Date of payment should be '<dateOfPayment>'

Examples: 
| delay | dateOfPayment |
| 15    | 20            |
| 30    | 10            |
| 45    | 5             |