Skip to content

Commit ae8970e

Browse files
committed
Add /xunit.analyzer/rules/xUnit1052
1 parent 834f8e4 commit ae8970e

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

site/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@
160160
href: /xunit.analyzers/rules/xUnit1050
161161
- name: xUnit1051
162162
href: /xunit.analyzers/rules/xUnit1051
163+
- name: xUnit1052
164+
href: /xunit.analyzers/rules/xUnit1052
163165
- name: Assertion
164166
items:
165167
- name: xUnit2000

site/xunit.analyzers/rules/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ title: Roslyn Analyzer Rules
5959
| [xUnit1049](/xunit.analyzers/rules/xUnit1049) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} | ::Error::{.label .label-Error} | Do not use 'async void' for test methods as it is no longer supported
6060
| [xUnit1050](/xunit.analyzers/rules/xUnit1050) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} | ::Info::{.label .label-Info} | The class referenced by the ClassData attribute returns untyped data rows
6161
| [xUnit1051](/xunit.analyzers/rules/xUnit1051) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} | ::Warning::{.label .label-Warning} | Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
62+
| [xUnit1052](/xunit.analyzers/rules/xUnit1052) | ::v2::{.label .label-version-False} ::v3::{.label .label-version-True} | ::Warning::{.label .label-Warning} | Avoid using 'TheoryData<...>' with types that implement 'ITheoryDataRow'
6263

6364
## Assertion Analyzers (2xxx)
6465

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
analyzer: true
3+
title: xUnit1052
4+
description: Avoid using 'TheoryData<...>' with types that implement 'ITheoryDataRow'
5+
category: Usage
6+
severity: Warning
7+
v2: false
8+
v3: true
9+
---
10+
11+
## Cause
12+
13+
A violation of this rule occurs when creating a data source from `TheoryData<...>` which includes `ITheoryDataRow` (or any type which implements it).
14+
15+
## Reason for rule
16+
17+
`ITheoryDataRule` (and derived types, like `TheoryDataRule<...>`) are intended to be used directly from a collection, like `IEnumerable<>` or `List<>`.
18+
19+
## How to fix violations
20+
21+
To fix a violation of this rule, replace `TheoryData` with `IEnumeable` (or a standard generic collection).
22+
23+
## Examples
24+
25+
### Violates
26+
27+
```csharp
28+
using Xunit;
29+
30+
public class xUnit1052
31+
{
32+
public static TheoryData<TheoryDataRow<int>> Data => [/*...*/];
33+
}
34+
```
35+
36+
### Does not violate
37+
38+
```csharp
39+
using System.Collections.Generic;
40+
using Xunit;
41+
42+
public class xUnit1052
43+
{
44+
public static IEnumerable<TheoryDataRow<int>> Data => [/*...*/];
45+
}
46+
```

0 commit comments

Comments
 (0)