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

Ayo*_*lhi 6 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){//}
Run Code Online (Sandbox Code Playgroud)

Ids*_*Zee 6

这不能用InlineData你来完成,你只能用 来完成MemberDataPropertyData或者ClassDataMemberData下面的例子。

[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 };
}
Run Code Online (Sandbox Code Playgroud)

  • 你可以这样做 `[Theory] ​​[InlineData(null, new[] { 42, 2112 }, null)] public void verifyGetCarListAsync(int? colorID, int[] carIDs, int? sellerID) { var carIDList = carIDs.ToList() ; }` (4认同)
  • “=&gt; {” 无法编译 (3认同)