Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 3, 2025

This PR fixes an issue where custom matrix exclusion attributes that inherit from MatrixExclusionAttribute were not being recognized, and enum values in exclusions were not being properly compared.

Problem

When users create custom exclusion attributes like:

public class MatrixExclusionStatusAttribute : MatrixExclusionAttribute
{
    public MatrixExclusionStatusAttribute(Status status) : base(status) { }
}

[Test]
[MatrixDataSource]
[MatrixExclusionStatus(Status.Draft)]  // Should exclude Draft enum value
public async Task Should_Filter_By_Status(Status status) { }

The exclusion was not working - all 5 enum values were being generated instead of the expected 4 (excluding Draft).

Root Cause

Two issues in MatrixDataSourceAttribute.GetExclusions():

  1. Inheritance not recognized: Used OfType<MatrixExclusionAttribute>() which only matches exact types, not derived classes
  2. Enum type mismatch: Matrix generation converts enums to underlying types (0, 1, 2, 3, 4) but exclusion comparison used original enum values (Status.Draft, Status.Pending, etc.), causing comparison failures

Solution

  1. Support inheritance: Changed OfType<MatrixExclusionAttribute>() to Where(x => x is MatrixExclusionAttribute) to recognize derived attributes
  2. Fix enum comparison: Added IsExcluded() method that converts enum values to their underlying types before comparison, matching the matrix generation behavior

Verification

Before fix:

Should_Filter_By_Status(0)      // Draft included ❌
Should_Filter_By_Status(1)
Should_Filter_By_Status(2)
Should_Filter_By_Status(3)
Should_Filter_By_Status(4)

After fix:

Should_Filter_By_Status(1)      // Draft (0) excluded ✅
Should_Filter_By_Status(2)
Should_Filter_By_Status(3)
Should_Filter_By_Status(4)

Existing matrix exclusion functionality remains unchanged and working correctly.

Fixes #2663.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI temporarily deployed to Pull Requests August 3, 2025 19:52 Inactive
Copilot AI changed the title [WIP] MatrixExclusion does not exclude Fix MatrixExclusion inheritance and enum comparison for custom exclusion attributes Aug 3, 2025
Copilot AI requested a review from thomhurst August 3, 2025 19:55
Copilot AI temporarily deployed to Pull Requests August 3, 2025 19:56 Inactive
@thomhurst thomhurst marked this pull request as ready for review August 3, 2025 21:39
@thomhurst thomhurst enabled auto-merge (squash) August 3, 2025 21:39
@thomhurst thomhurst disabled auto-merge August 4, 2025 00:14
@thomhurst thomhurst merged commit a495678 into main Aug 4, 2025
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MatrixExclusion does not exclude

2 participants