Rupanjan Hari
Rupanjan Hari

Reputation: 31

Access a custom attributes value that allows multiple use from inside context PropertyBag in NUnit

I have this custom attribute

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class TestServer : PropertyAttribute
{
    public ServerType Sever { get; set; }
    public TestServer(ServerType server) : base("ServerType", server.ToString())
    {
        this.Sever  = server;
    }
}

As you can see from the code that multiple Attributes are usable on the same class. Thus when I'm going to access the property value 'ServerType' from the TestContext.CurrentContext.Test.Properties.Get("ServerType") it's giving me only one value that is the first one. But it doesn't mean, the test class doesn't retain the rest. I can even even run NUnit Test Selection Language based on these values and it even shows up in the 'result.xml' which generates after a test run

here is the 'properties' section in the xml.

Can, anyone help me with this? I want to access multiple property values for the same property type from inside the 'TestContext'.

Upvotes: 3

Views: 488

Answers (1)

Chris
Chris

Reputation: 6062

You should be able to retrieve a list of all values using the indexer notation:

TestContext.CurrentContext.Test.Properties["ServerType"]

Upvotes: 1

Related Questions