I have a really simple .runsettings file for nunit that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
<Parameter name="someParameterName" value="someExampleValue" />
<Parameter name="variable1" value="someExampleValue" />
<Parameter name="variable2" value="someExampleValue" />
</TestRunParameters>
</RunSettings>
What I am hoping to do is loop over the parameters instead of accessing by name.
This works if I only want a single value:
var value = TestContext.Parameters["someParameterName"];
It feels like this should work to loop over them but it doesn't:
var allParams = TestContext.Parameters;
foreach (var item in allParams) {
//I'll want to get the items name and value here.
}
I get this error:
Compiler Error CS1579 foreach statement cannot operate on variables of type 'type1' because 'type2' does not contain a public definition for 'identifier'
What am I missing??
This is because
TestContext.Parameters
returnsTestParameters
, which is not a collection.The best you can do is:
And the output will be like,