Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide List<int> for a data theory ? "InlineData" [duplicate]

How to provide List as a data source for a data theory, I can't find anything in InlineData that supports this :

    [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){//}
like image 870
Ayoub Salhi Avatar asked Sep 06 '19 14:09

Ayoub Salhi


1 Answers

This cannot be accomplished with InlineData you can only do this with MemberData, PropertyData or ClassData see the MemberData example below.

[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 };
}
like image 80
Ids van der Zee Avatar answered Oct 17 '22 12:10

Ids van der Zee