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

1

16

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){//}
Tavie answered 6/9, 2019 at 14:4 Comment(0)
I
27

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 };
}
Infuscate answered 6/9, 2019 at 14:51 Comment(4)
"=> {" does not compilePiranesi
public static IEnumerable<object[]> Data => new List<object[]> { new object[] { 1, 2, 3 }, new object[] { -4, -6, -10 }, new object[] { -2, 2, 0 }, new object[] { int.MinValue, -1, int.MaxValue }, };Overlooker
You could do [Theory] [InlineData(null, new[] { 42, 2112 }, null)] public void VerifyGetCarListAsync(int? colorID, int[] carIDs, int? sellerID) { var carIDList = carIDs.ToList(); }Charliecharline
PropertyData has been renamed to MemberData. xunit.net/docs/upgrade-extensionsPhraseogram

© 2022 - 2024 — McMap. All rights reserved.