-
Notifications
You must be signed in to change notification settings - Fork 508
/
StyleCopCodeFixVerifier`2.cs
62 lines (51 loc) · 2.82 KB
/
StyleCopCodeFixVerifier`2.cs
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
54
55
56
57
58
59
60
61
62
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
namespace StyleCop.Analyzers.Test.Verifiers
{
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using TestHelper;
using Xunit;
internal static class StyleCopCodeFixVerifier<TAnalyzer, TCodeFix>
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFix : CodeFixProvider, new()
{
internal static DiagnosticResult[] EmptyDiagnosticResults
=> DiagnosticVerifier<TAnalyzer>.EmptyDiagnosticResults;
internal static DiagnosticResult Diagnostic(string diagnosticId = null)
=> DiagnosticVerifier<TAnalyzer>.Diagnostic(diagnosticId);
internal static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> DiagnosticVerifier<TAnalyzer>.Diagnostic(descriptor);
internal static DiagnosticResult CompilerError(string errorIdentifier)
=> DiagnosticVerifier<TAnalyzer>.CompilerError(errorIdentifier);
internal static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult expected, CancellationToken cancellationToken)
=> StyleCopDiagnosticVerifier<TAnalyzer>.VerifyCSharpDiagnosticAsync(source, expected, cancellationToken);
internal static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
=> StyleCopDiagnosticVerifier<TAnalyzer>.VerifyCSharpDiagnosticAsync(source, expected, cancellationToken);
internal static Task VerifyCSharpFixAsync(string source, DiagnosticResult expected, string fixedSource, CancellationToken cancellationToken)
=> VerifyCSharpFixAsync(source, new[] { expected }, fixedSource, cancellationToken);
internal static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
{
var test = new CSharpTest
{
TestCode = source,
FixedCode = fixedSource,
};
test.ExpectedDiagnostics.AddRange(expected);
return test.RunAsync(cancellationToken);
}
internal class CSharpTest : StyleCopDiagnosticVerifier<TAnalyzer>.CSharpTest
{
protected override IEnumerable<CodeFixProvider> GetCodeFixProviders()
{
var codeFixProvider = new TCodeFix();
Assert.NotSame(WellKnownFixAllProviders.BatchFixer, codeFixProvider.GetFixAllProvider());
return new[] { codeFixProvider };
}
}
}
}