Search code examples
c#xunitxunit.net

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


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){//}

Solution

  • 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 };
    }