-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTestFrameworkReferences.cs
More file actions
53 lines (50 loc) · 2.13 KB
/
TestFrameworkReferences.cs
File metadata and controls
53 lines (50 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis;
namespace TestHelper
{
/// <summary>
/// Registry of supported test frameworks for analyzer testing.
/// Used both to inject real assembly references into in-memory Roslyn compilations
/// and as data source for parameterized tests via [DynamicData].
///
/// To add a new test framework: add one entry to <see cref="All"/>,
/// add the NuGet package to Directory.Packages.props and the test .csproj
/// (with IncludeAssets="compile" PrivateAssets="all"), and add the namespace
/// to <see cref="IntelliTect.Analyzer.Analyzers.NamingMethodPascal"/>'s namespace list.
/// </summary>
public static class TestFrameworkReferences
{
public record TestFramework(
string Name,
string TestAttribute,
string UsingDirective,
MetadataReference Reference);
public static IReadOnlyList<TestFramework> All { get; } =
[
new("MSTest",
"[TestMethod]",
"using Microsoft.VisualStudio.TestTools.UnitTesting;",
MetadataReference.CreateFromFile(
typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute).Assembly.Location)),
new("xUnit",
"[Fact]",
"using Xunit;",
MetadataReference.CreateFromFile(
typeof(Xunit.FactAttribute).Assembly.Location)),
new("NUnit",
"[Test]",
"using NUnit.Framework;",
MetadataReference.CreateFromFile(
typeof(NUnit.Framework.TestAttribute).Assembly.Location)),
new("TUnit",
"[Test]",
"using TUnit.Core;",
MetadataReference.CreateFromFile(
typeof(TUnit.Core.TestAttribute).Assembly.Location)),
];
/// <summary>All test framework assembly references, for use in <see cref="DiagnosticVerifier"/>.</summary>
public static MetadataReference[] AllReferences =>
[.. All.Select(f => f.Reference)];
}
}