There are two different problems here.
The error "An attribute argument must be a constant expression, typeof expression or array expression of an attribute parameter type" is coming from the compiler. It describes a limitation of any attribute constructors in .NET, not just NUnit's. If you want to pass arguments in the constructor itself, then you must use constant values.
However, it seems you don't want to pass the args in the constructor. Instead, you would like to refer to a list declared separately. NUnit has a set of attributes for doing exactly that. You should use one of them, for example, ValueSourceAttribute
...
public class ObjectBaseCalls : ApiTestBase
{
static ReadOnlyCollection<string> AllTypes = new ReadOnlyCollection<string>(new List<string>() { "Value1", "Value 2" });
[Test]
public void ObjectCanBePostedAndGeted([ValueSource(nameof(AllTypes))] string type)
{
//My test
}
}
Alternatively, since you only have a single argument to the method, youcould use TestCaseSourceAttribute
...
public class ObjectBaseCalls : ApiTestBase
{
static ReadOnlyCollection<string> AllTypes = new ReadOnlyCollection<string>(new List<string>() { "Value1", "Value 2" });
[TestCaseSource(nameof(AllTypes))]
public void ObjectCanBePostedAndGeted(string type)
{
//My test
}
}
Either of these should work. Which one you use here is a matter of stylistic preference.
The second problem is with your use of PairWiseAttribute
. It is used (along with several other "combining attributes" when you have a test with multiple parameters specified using Values
or ValueSource
and you want NUnit to combine them in various ways. In the situation with a single parameter, it does nothing. That's why I removed it from my examples above.
If you actually intended to write a test with more than one parameter and have NUnit decide how to combine them, I think you need to ask a different question where you explain what you are trying to accomplish.