如何为数据理论提供List <int>? “ InlineData”

时间:2019-09-06 14:04:58

标签: c# xunit xunit.net

如何提供List作为数据理论的数据源,我在InlineData中找不到支持此功能的任何东西:

    [InlineData(null, new[] { 42, 2112 }, null)] // This doesn't work, I need something that works with List<int>
    [Trait("Category", "API")]
    [Trait("Category", "Partner")]
    [Trait("Category", "Smoke")]
    public void VerifyGetCarListAsync(int? colorID, List<int> carIDs, int? sellerID){//}

1 个答案:

答案 0 :(得分:1)

InlineData不能实现这一点,您只能使用MemberDataPropertyDataClassData来做到这一点,请参见下面的MemberData示例。

[MemberData(nameof(Data))]
public void VerifyGetCarListAsync(int? colorID, List<int> carIDs, int? sellerID){
    // test code
}


public static IEnumerable<object[]> Data => {
    yield return new object[] { null, new List<int>{ 42, 2112 }, null };
    yield return new object[] { 1, new List<int>{ 43, 2112 }, null };
    yield return new object[] { null, new List<int>{ 44, 2112 }, 6 };
}