Skip to content

GetFirstAttributeOrDefault implementation isn't consistent with doc comment #4333

@Youssef1313

Description

@Youssef1313

Doc says:

/// Throws when multiple attributes are found (the attribute must allow multiple).

Implementation:

        Attribute[] cachedAttributes = GetCustomAttributesCached(attributeProvider, inherit);

        foreach (Attribute cachedAttribute in cachedAttributes)
        {
            if (cachedAttribute is TAttribute cachedAttributeAsTAttribute)
            {
                return cachedAttributeAsTAttribute;
            }
        }

        return null;

This method is called for the following attributes:

  • AsyncStateMachineAttribute
    • Already doesn't allow multiple. So it's okay.
  • TimeoutAttribute
    • Already doesn't allow multiple. So it's okay.
  • PriorityAttribute
    • Already doesn't allow multiple. So it's okay.
  • ClassInitializeAttribute
    • Already doesn't allow multiple. So it's okay.
  • ClassCleanupAttribute
    • Already doesn't allow multiple. So it's okay.
  • TestClassAttribute
    • We should throw if multiple are found. We cannot force it to not allow multiple because it's not sealed.
  • TestMethodAttribute
    • We should throw if multiple are found. We cannot force it to not allow multiple because it's not sealed.

Metadata

Metadata

Assignees

Labels

Area: MSTestIssues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions