Skip to content

Commit 25db6a8

Browse files
authored
Add provider-first property and scope migration helpers (#81)
* Add property-state and typed scope helpers * Fix disposals * Extend FMOQ0013 typed service helper fixes * Extend FMOQ0013 scope helper migrations * Harden FMOQ0013 scope pairing
1 parent dcfa259 commit 25db6a8

25 files changed

Lines changed: 2439 additions & 126 deletions

FastMoq.Analyzers.Tests/AnalyzerTestHelpers.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ public static async Task<ImmutableArray<Diagnostic>> GetDiagnosticsAsync(Documen
4141
.ConfigureAwait(false);
4242
}
4343

44-
public static async Task<string> ApplyCodeFixAsync(string source, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string diagnosticId, bool includeAzureFunctionsHelpers = false)
44+
public static async Task<string> ApplyCodeFixAsync(string source, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string diagnosticId, bool includeAzureFunctionsHelpers = false, int diagnosticOccurrence = 0, string? diagnosticMessageContains = null)
4545
{
4646
var document = CreateDocument(source, includeAzureFunctionsHelpers);
4747
var diagnostics = await GetDiagnosticsAsync(document, analyzer).ConfigureAwait(false);
48-
var diagnostic = diagnostics.Single(item => item.Id == diagnosticId);
48+
var diagnostic = diagnostics
49+
.Where(item => item.Id == diagnosticId)
50+
.Where(item => diagnosticMessageContains is null || item.GetMessage().Contains(diagnosticMessageContains, StringComparison.Ordinal))
51+
.OrderBy(item => item.Location.SourceSpan.Start)
52+
.ElementAt(diagnosticOccurrence);
4953

5054
var actions = new List<CodeAction>();
5155
var context = new CodeFixContext(document, diagnostic, (action, _) => actions.Add(action), CancellationToken.None);
@@ -59,11 +63,15 @@ public static async Task<string> ApplyCodeFixAsync(string source, DiagnosticAnal
5963
return changedRoot!.NormalizeWhitespace().ToFullString();
6064
}
6165

62-
public static async Task<ImmutableArray<string>> GetCodeFixTitlesAsync(string source, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string diagnosticId, bool includeAzureFunctionsHelpers = false)
66+
public static async Task<ImmutableArray<string>> GetCodeFixTitlesAsync(string source, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider, string diagnosticId, bool includeAzureFunctionsHelpers = false, int diagnosticOccurrence = 0, string? diagnosticMessageContains = null)
6367
{
6468
var document = CreateDocument(source, includeAzureFunctionsHelpers);
6569
var diagnostics = await GetDiagnosticsAsync(document, analyzer).ConfigureAwait(false);
66-
var diagnostic = diagnostics.Single(item => item.Id == diagnosticId);
70+
var diagnostic = diagnostics
71+
.Where(item => item.Id == diagnosticId)
72+
.Where(item => diagnosticMessageContains is null || item.GetMessage().Contains(diagnosticMessageContains, StringComparison.Ordinal))
73+
.OrderBy(item => item.Location.SourceSpan.Start)
74+
.ElementAt(diagnosticOccurrence);
6775

6876
var actions = new List<CodeAction>();
6977
var context = new CodeFixContext(document, diagnostic, (action, _) => actions.Add(action), CancellationToken.None);

0 commit comments

Comments
 (0)