MemberData should use nameof operator for member name
This rule is triggered by [MemberData]
which uses a string for the member name.
Using nameof
instead of a string literal value allows rename refactoring to change the values in [MemberData]
in the event the developer renames the data member name.
To fix a violation of this rule, convert from the string literal to nameof
.
using System.Collections.Generic;
using Xunit;
public class xUnit1014
{
public static IEnumerable<object[]> TestData;
[Theory]
[MemberData("TestData")]
public void TestMethod(string greeting, int age) { }
}
Example(s) of code that violates the rule.
using System.Collections.Generic;
using Xunit;
public class xUnit1014
{
public static IEnumerable<object[]> TestData;
[Theory]
[MemberData(nameof(TestData))]
public void TestMethod(string greeting, int age) { }
}