MemberData should not have parameters if the referenced member is not a method
This rule is triggered when your [MemberData]
attribute points to a non-method, but provides method arguments.
[MemberData]
which points to a method can pass parameter values to that method; when it points to a field or a property, method parameters will be ignored (and thus should be removed).
To fix a violation of this rule, you may:
[MemberData]
attributeusing System.Collections.Generic;
using Xunit;
public class xUnit1021
{
public static IEnumerable<object[]> TestData { get; set; }
[Theory]
[MemberData(nameof(TestData), "Hello world", 123)]
public void TestMethod(int _) { }
}
using System.Collections.Generic;
using Xunit;
public class xUnit1021
{
public static IEnumerable<object[]> TestData { get; set; }
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(int _) { }
}
using System.Collections.Generic;
using Xunit;
public class xUnit1021
{
public static IEnumerable<object[]> TestData(string greeting, int age) { }
[Theory]
[MemberData(nameof(TestData), "Hello world", 123)]
public void TestMethod(int _) { }
}