My test works properly for first and second scenario, but third example ([MemberData(nameof(SampleData), Error.Key.InvalidParameters)]) is not launched at all; I am getting an error: System.NotSupportedException : Specified method is not supported..
Instead this:
[InlineData(new int[] { 1, 2, 3, 4, 5, 6, 7, ..... }, Error.Key.InvalidParameters)]
I want to automatically generate data. What am I doing wrong?
public static IEnumerable<object[]> SampleData()
{
yield return new object[] { Enumerable.Range(1,200) };
}
[Theory]
[InlineData(new int[] { }, Error.Key.EmptyList)]
[InlineData(new int[] { -5 }, Error.Key.InvalidParameters)]
[MemberData(nameof(SampleData), Error.Key.InvalidParameters)]
public void ExampleTest(IEnumerable<int> ids, Error.Key expected)
{
// Arrange -> InlineData
// Act
var ex = Assert.Throws<ValidationException>(() => sut.SampleValidation(ids));
// Assert
Assert.Equal(expected.ToString(), ex.Key);
}
Also, I tried this:
public static (IEnumerable<int>, ValidationError.Key) CombinationData()
{
yield return (Enumerable.Range(1, 200), ValidationError.Key.InvalidParameters);
}
but this gives me an error: The body of 'SampleData()' cannot be an iterator block because '(IEnumerable<int>, Error.Key)' is not an iterator interface type