0

I'm looking at using xUnit for testing. I like some of it's features.

I am trying to create a list<> and pass the list as a parameter of the test:

    [Theory]
    [InlineData( new List<IDispenseEntity>() )]
    public void Test1(List<IDispenseEntity> data)
    {

        // Some test here Assert.Equal(2, 2);
    }

I am getting:

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

I want to test various list<> with different combinations of elements in the list.

How do I pass a List<> to my test?

Eric Snyder
  • 1,816
  • 3
  • 22
  • 46

1 Answers1

0

InlineData attributes accepts only compile time values (constants).
Look for MemberData

[Theory]
[MemberData(nameof(EmptyList))]
public void Test1(List<IDispenseEntity> data)
{

    // Some test here Assert.Equal(2, 2);
}

public static IEnumerable<object[]> EmptyList()
{
    yield return new[] { new List<IDispenseEntity>() };
}
Fabio
  • 31,528
  • 4
  • 33
  • 72