Skip to content

Use Microsoft.CodeAnalysis.Testing for tests #389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/FluentAssertions.Analyzers.Tests/CodeFixVerifierArguments.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions.Analyzers.TestUtils;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;

namespace FluentAssertions.Analyzers.Tests;

@@ -26,10 +28,28 @@ public CodeFixVerifierArguments() { }
CodeFixProviders.Add(new TCodeFixProvider());
return this;
}

public CodeFixVerifierArguments WithFixedSources(params string[] fixedSources)
{
FixedSources.AddRange(fixedSources);
return this;
}
}

public class CodeFixVerifierNewArguments<TCodeFix, TAnalyzer>
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFix : CodeFixProvider, new()
{
public List<string> Sources { get; } = new();
public List<string> FixedSources { get; } = new();
public List<PackageIdentity> PackageReferences { get; } = new();
public DiagnosticResult ExpectedDiagnostic { get; private set; }

public CodeFixVerifierNewArguments(DiagnosticResult expectedDiagnostic) => ExpectedDiagnostic = expectedDiagnostic;

public CodeFixVerifierNewArguments<TCodeFix, TAnalyzer> WithPackages(params PackageReference[] packages)
{
PackageReferences.AddRange(packages.Select(x => new PackageIdentity(x.Name, x.Version)));
return this;
}
}
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers.Tests/DiagnosticResult.cs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public DiagnosticResultLocation(string path, int line, int column)
/// <summary>
/// Struct that stores information about a Diagnostic appearing in a source
/// </summary>
public struct DiagnosticResult
public struct LegacyDiagnosticResult
{
private DiagnosticResultLocation[] locations;

50 changes: 34 additions & 16 deletions src/FluentAssertions.Analyzers.Tests/DiagnosticVerifier.cs
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@
using System.Threading;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using System.Threading.Tasks;

namespace FluentAssertions.Analyzers.Tests
{
@@ -20,6 +23,13 @@ namespace FluentAssertions.Analyzers.Tests
/// </summary>
public static class DiagnosticVerifier
{
private class CodeFixVerifier<TCodeFix, TAnalyzer> : CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFix : CodeFixProvider, new()
{

}

#region CodeFixVerifier

public static void VerifyCSharpFix<TCodeFixProvider, TDiagnosticAnalyzer>(string oldSource, string newSource)
@@ -38,6 +48,28 @@ public static void VerifyCSharpFix<TCodeFixProvider, TDiagnosticAnalyzer>(string
public static void VerifyFix(CodeFixVerifierArguments arguments)
=> VerifyFix(arguments, arguments.DiagnosticAnalyzers.Single(), arguments.CodeFixProviders.Single(), arguments.FixedSources.Single());

public static async Task VerifyFixAsync<TCodeFix, TAnalyzer>(CodeFixVerifierNewArguments<TCodeFix, TAnalyzer> arguments)
where TAnalyzer : DiagnosticAnalyzer, new()
where TCodeFix : CodeFixProvider, new()
{
var test = new CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net80.AddPackages(arguments.PackageReferences.ToImmutableArray()),
ExpectedDiagnostics = { arguments.ExpectedDiagnostic },
};
foreach (var source in arguments.Sources)
{
test.TestState.Sources.Add(source);
}
foreach (var fixedSource in arguments.FixedSources)
{
test.FixedState.Sources.Add(fixedSource);
}

// TODO: add support for diagnostics (merge test code-fixers with test analyzers).
await test.RunAsync();
}

public static void VerifyNoFix(CodeFixVerifierArguments arguments)
=> VerifyNoFix(arguments, arguments.DiagnosticAnalyzers.Single(), arguments.CodeFixProviders.Single());
private static void VerifyNoFix(CsProjectArguments arguments, DiagnosticAnalyzer analyzer, CodeFixProvider codeFixProvider)
@@ -274,20 +306,6 @@ private static Diagnostic[] GetSortedDiagnosticsFromDocuments(DiagnosticAnalyzer

#region Verifier wrappers

/// <summary>
/// Called to test a C# DiagnosticAnalyzer when applied on the single inputted string as a source
/// Note: input a DiagnosticResult for each Diagnostic expected
/// </summary>
/// <param name="source">A class in the form of a string to run the analyzer on</param>
/// <param name="expected"> DiagnosticResults that should appear after the analyzer is run on the source</param>
public static void VerifyCSharpDiagnostic<TDiagnosticAnalyzer>(string source, params DiagnosticResult[] expected) where TDiagnosticAnalyzer : DiagnosticAnalyzer, new()
{
VerifyDiagnostic(new DiagnosticVerifierArguments()
.WithDiagnosticAnalyzer<TDiagnosticAnalyzer>()
.WithSources(source)
.WithExpectedDiagnostics(expected));
}

public static void VerifyDiagnostic(DiagnosticVerifierArguments arguments)
{
var project = CsProjectGenerator.CreateProject(arguments);
@@ -297,7 +315,7 @@ public static void VerifyDiagnostic(DiagnosticVerifierArguments arguments)
VerifyDiagnosticResults(diagnostics, arguments.DiagnosticAnalyzers.ToArray(), arguments.ExpectedDiagnostics.ToArray());
}

public static void VerifyCSharpDiagnosticUsingAllAnalyzers(string source, params DiagnosticResult[] expected)
public static void VerifyCSharpDiagnosticUsingAllAnalyzers(string source, params LegacyDiagnosticResult[] expected)
{
VerifyDiagnostic(new DiagnosticVerifierArguments()
.WithAllAnalyzers()
@@ -310,7 +328,7 @@ public static void VerifyCSharpDiagnosticUsingAllAnalyzers(string source, params

#region Actual comparisons and verifications

private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, DiagnosticAnalyzer[] analyzers, params DiagnosticResult[] expectedResults)
private static void VerifyDiagnosticResults(IEnumerable<Diagnostic> actualResults, DiagnosticAnalyzer[] analyzers, params LegacyDiagnosticResult[] expectedResults)
{
int expectedCount = expectedResults.Length;
int actualCount = actualResults.Count();
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace FluentAssertions.Analyzers.Tests;

public class DiagnosticVerifierArguments : CsProjectArguments
{
public List<DiagnosticResult> ExpectedDiagnostics { get; } = new();
public List<LegacyDiagnosticResult> ExpectedDiagnostics { get; } = new();

public List<DiagnosticAnalyzer> DiagnosticAnalyzers { get; } = new();

@@ -25,7 +25,7 @@ public DiagnosticVerifierArguments WithAllAnalyzers()
return this;
}

public DiagnosticVerifierArguments WithExpectedDiagnostics(params DiagnosticResult[] expectedDiagnostics)
public DiagnosticVerifierArguments WithExpectedDiagnostics(params LegacyDiagnosticResult[] expectedDiagnostics)
{
ExpectedDiagnostics.AddRange(expectedDiagnostics);
return this;
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="xunit.assert" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" />
</ItemGroup>

<ItemGroup>
7 changes: 2 additions & 5 deletions src/FluentAssertions.Analyzers.Tests/Tips/AsyncVoidTests.cs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public void AssignAsyncVoidLambdaToAction_TestAnalyzer(string assertion)
{
var source = GenerateCode.AsyncFunctionStatement(assertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = AsyncVoidAnalyzer.DiagnosticId,
Message = AsyncVoidAnalyzer.Message,
@@ -59,10 +59,7 @@ public void AssignAsyncVoidLambdaToAction_TestAnalyzer(string assertion)
[NotImplemented]
public void AssignAsyncVoidLambdaToAction_TestCodeFix(string oldAssertion, string newAssertion)
{
var oldSource = GenerateCode.AsyncFunctionStatement(oldAssertion);
var newSource = GenerateCode.AsyncFunctionStatement(newAssertion);

DiagnosticVerifier.VerifyCSharpFix<AsyncVoidCodeFix, AsyncVoidAnalyzer>(oldSource, newSource);
// no-op
}
}
}
38 changes: 26 additions & 12 deletions src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
using System.Text;
using System.Threading.Tasks;
using FluentAssertions.Analyzers.TestUtils;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FluentAssertions.Analyzers.Tests
{
[TestClass]
public class CollectionTests
{
[DataTestMethod]
[AssertionDiagnostic("actual.Any().Should().BeTrue({0});")]
[AssertionDiagnostic("actual.AsEnumerable().Any().Should().BeTrue({0}).And.ToString();")]
[AssertionDiagnostic("actual.ToList().Any().Should().BeTrue({0}).And.ToString();")]
[AssertionDiagnostic("actual.ToArray().Any().Should().BeTrue({0}).And.ToString();")]
[Implemented]
public void ExpressionBodyAssertion_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticExpressionBody(assertion, DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue);
private static CodeFixVerifierNewArguments<FluentAssertionsCodeFixProvider, FluentAssertionsAnalyzer> CreateCodeFixArguments(string source, string expected, DiagnosticMetadata metadata, LinePosition location)
=> new CodeFixVerifierNewArguments<FluentAssertionsCodeFixProvider, FluentAssertionsAnalyzer>(new DiagnosticResult(FluentAssertionsAnalyzer.DiagnosticId, DiagnosticSeverity.Info)
.WithMessage(metadata.Message)
.WithLocation(location)
)
{
Sources = { source },
FixedSources = { expected },

}.WithPackages(PackageReference.FluentAssertions_6_12_0);

[DataTestMethod]
[AssertionCodeFix(
@@ -30,7 +36,15 @@ public class CollectionTests
oldAssertion: "actual.ToArray().Any().Should().BeTrue({0}).And.ToString();",
newAssertion: "actual.ToArray().Should().NotBeEmpty({0}).And.ToString();")]
[Implemented]
public void ExpressionBodyAssertion_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixExpressionBody(oldAssertion, newAssertion);
public async Task ExpressionBodyAssertion_TestCodeFix(string oldAssertion, string newAssertion)
{
var oldSource = GenerateCode.GenericIListExpressionBodyAssertion(oldAssertion);
var newSource = GenerateCode.GenericIListExpressionBodyAssertion(newAssertion);

var arguments = CreateCodeFixArguments(oldSource, newSource, DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue, new LinePosition(9, 15));

await DiagnosticVerifier.VerifyFixAsync(arguments);
}

[DataTestMethod]
[AssertionDiagnostic("actual.Any().Should().BeTrue({0});")]
@@ -634,7 +648,7 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR
{
var source = GenerateCode.GenericIEnumerableAssertion(assertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = DiagnosticMetadata.CollectionShouldContainSingle_ShouldHaveCount1.Message,
@@ -1023,7 +1037,7 @@ private void VerifyCSharpDiagnosticCodeBlock(string sourceAssertion, DiagnosticM
{
var source = GenerateCode.GenericIListCodeBlockAssertion(sourceAssertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
@@ -1040,7 +1054,7 @@ private void VerifyCSharpDiagnosticExpressionBody(string sourceAssertion, Diagno
{
var source = GenerateCode.GenericIListExpressionBodyAssertion(sourceAssertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
VisitorName = metadata.Name,
@@ -1057,7 +1071,7 @@ private void VerifyArrayCSharpDiagnosticCodeBlock(string sourceAssertion, Diagno
{
var source = GenerateCode.GenericArrayCodeBlockAssertion(sourceAssertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ private void VerifyCSharpDiagnostic(string sourceAssersion, DiagnosticMetadata m
{
var source = GenerateCode.GenericIDictionaryAssertion(sourceAssersion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
Original file line number Diff line number Diff line change
@@ -283,7 +283,7 @@ private void VerifyCSharpDiagnostic(string sourceAssertion, DiagnosticMetadata m
{
var source = GenerateCode.ExceptionAssertion(sourceAssertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
36 changes: 35 additions & 1 deletion src/FluentAssertions.Analyzers.Tests/Tips/MsTestTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
using FluentAssertions.Analyzers.TestUtils;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;
using System.Threading.Tasks;

namespace FluentAssertions.Analyzers.Tests.Tips
{
[TestClass]
public class MsTestTests
{
private class AllAnalyzersTest : AnalyzerTest<DefaultVerifier>
{
protected override string DefaultFileExt => "cs";
public override string Language => LanguageNames.CSharp;
private readonly AnalyzerOptions analyzerOptions;
public AllAnalyzersTest(IDictionary<string, string> analyzerConfigOptions = null)
{
analyzerOptions = analyzerConfigOptions != null ? new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty, new TestAnalyzerConfigOptionsProvider(analyzerConfigOptions)) : null;
}

protected override CompilationOptions CreateCompilationOptions() => new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true);
protected override ParseOptions CreateParseOptions() => new CSharpParseOptions(LanguageVersion.Latest, DocumentationMode.Diagnose);
protected override IEnumerable<DiagnosticAnalyzer> GetDiagnosticAnalyzers() => CodeAnalyzersUtils.GetAllAnalyzers();

protected override AnalyzerOptions GetAnalyzerOptions(Project project) => analyzerOptions ?? project.AnalyzerOptions;
}

private class MsTestAnalyzerTest : Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerTest<AssertAnalyzer, DefaultVerifier>
{
private readonly AnalyzerOptions analyzerOptions;
public MsTestAnalyzerTest(IDictionary<string, string> values = null)
{
analyzerOptions = values != null ? new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty, new TestAnalyzerConfigOptionsProvider(values)) : null;
}

protected override AnalyzerOptions GetAnalyzerOptions(Project project) => analyzerOptions;
}

[TestMethod]
[Implemented]
public void SupportExcludingMethods()
@@ -866,7 +900,7 @@ private void VerifyCSharpDiagnostic(string source)
.WithAllAnalyzers()
.WithSources(source)
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.MSTestTestFramework_3_1_1)
.WithExpectedDiagnostics(new DiagnosticResult
.WithExpectedDiagnostics(new LegacyDiagnosticResult
{
Id = AssertAnalyzer.MSTestsRule.Id,
Message = AssertAnalyzer.Message,
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public void NullConditionalMayNotExecuteTest(string assertion)
.WithDiagnosticAnalyzer<FluentAssertionsAnalyzer>()
.WithSources(Code(assertion))
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
.WithExpectedDiagnostics(new DiagnosticResult
.WithExpectedDiagnostics(new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = DiagnosticMetadata.NullConditionalMayNotExecute.Message,
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers.Tests/Tips/NumericTests.cs
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ private void VerifyCSharpDiagnostic(string sourceAssertion, DiagnosticMetadata m
.WithSources(source)
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
.WithExpectedDiagnostics(new DiagnosticResult
.WithExpectedDiagnostics(new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs
Original file line number Diff line number Diff line change
@@ -1954,7 +1954,7 @@ private void VerifyDiagnostic(string source, PackageReference nunit)
.WithAllAnalyzers()
.WithSources(source)
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0, nunit)
.WithExpectedDiagnostics(new DiagnosticResult
.WithExpectedDiagnostics(new LegacyDiagnosticResult
{
Id = AssertAnalyzer.NUnitRule.Id,
Message = AssertAnalyzer.Message,
6 changes: 3 additions & 3 deletions src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs
Original file line number Diff line number Diff line change
@@ -313,7 +313,7 @@ public static void True(bool input)
.WithSources(source, globalUsings)
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.XunitAssert_2_5_1, PackageReference.FluentAssertions_6_12_0)
.WithExpectedDiagnostics(new DiagnosticResult()
.WithExpectedDiagnostics(new LegacyDiagnosticResult()
{
Id = AssertAnalyzer.XunitRule.Id,
Message = AssertAnalyzer.Message,
@@ -360,7 +360,7 @@ public class TestType3
.WithSources(source)
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
.WithExpectedDiagnostics(new DiagnosticResult()
.WithExpectedDiagnostics(new LegacyDiagnosticResult()
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = DiagnosticMetadata.CollectionShouldNotBeEmpty_AnyShouldBeTrue.Message,
@@ -439,7 +439,7 @@ public class MyCollectionType { }";
.WithSources(source)
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
.WithExpectedDiagnostics(new DiagnosticResult()
.WithExpectedDiagnostics(new LegacyDiagnosticResult()
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = DiagnosticMetadata.NullConditionalMayNotExecute.Message,
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ public void ShouldEquals_ShouldEqual_EnumerableType_TestCodeFix()
private void VerifyCSharpDiagnosticExpressionBody(string sourceAssertion, int line, int column, DiagnosticMetadata metadata)
{
var source = GenerateCode.ObjectStatement(sourceAssertion);
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers.Tests/Tips/StringTests.cs
Original file line number Diff line number Diff line change
@@ -179,7 +179,7 @@ private void VerifyCSharpDiagnostic(string sourceAssertion, DiagnosticMetadata m
{
var source = GenerateCode.StringAssertion(sourceAssertion);

DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new DiagnosticResult
DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(source, new LegacyDiagnosticResult
{
Id = FluentAssertionsAnalyzer.DiagnosticId,
Message = metadata.Message,
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs
Original file line number Diff line number Diff line change
@@ -789,7 +789,7 @@ private void VerifyCSharpDiagnostic(string methodArguments, string assertion)
.WithAllAnalyzers()
.WithSources(source)
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0, PackageReference.XunitAssert_2_5_1)
.WithExpectedDiagnostics(new DiagnosticResult
.WithExpectedDiagnostics(new LegacyDiagnosticResult
{
Id = AssertAnalyzer.XunitRule.Id,
Message = AssertAnalyzer.Message,

Unchanged files with check annotations Beta

namespace FluentAssertions.Analyzers;
public class SkipInvocationNodeAction(InvocationExpressionSyntax skipInvocation) : IEditAction

Check failure on line 6 in src/FluentAssertions.Analyzers/Tips/Editing/SkipInvocationNodeAction.cs

GitHub Actions / Performance regression check

{ expected

Check failure on line 6 in src/FluentAssertions.Analyzers/Tips/Editing/SkipInvocationNodeAction.cs

GitHub Actions / Performance regression check

} expected

Check failure on line 6 in src/FluentAssertions.Analyzers/Tips/Editing/SkipInvocationNodeAction.cs

GitHub Actions / Performance regression check

Tuple must contain at least two elements.
{
public void Apply(DocumentEditor editor, InvocationExpressionSyntax invocationExpression)
{
});
}
private sealed class AnalyzerContext(Compilation compilation)

Check failure on line 100 in src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs

GitHub Actions / Performance regression check

{ expected

Check failure on line 100 in src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs

GitHub Actions / Performance regression check

} expected

Check failure on line 100 in src/FluentAssertions.Analyzers/Tips/AssertAnalyzer.cs

GitHub Actions / Performance regression check

Tuple must contain at least two elements.
{
private readonly INamedTypeSymbol _xunitAssertSymbol = compilation.GetTypeByMetadataName("Xunit.Assert");
{
public static CreateChangedDocument RenameMethodToSubjectShouldAssertion(IInvocationOperation invocation, CodeFixContext context, string newName, int subjectIndex, int[] argumentsToRemove)
{
return ctx => RewriteExpressionCore(invocation, [

Check failure on line 18 in src/FluentAssertions.Analyzers/Tips/DocumentEditorUtils.cs

GitHub Actions / Performance regression check

Invalid expression term '['
..Array.ConvertAll(argumentsToRemove, arg => EditAction.RemoveInvocationArgument(arg)),
EditAction.SubjectShouldAssertion(subjectIndex, newName)
], context, ctx);
=> RenameMethodToSubjectShouldGenericAssertion(invocation, invocation.TargetMethod.TypeArguments, context, newName, subjectIndex, argumentsToRemove);
public static CreateChangedDocument RenameMethodToSubjectShouldGenericAssertion(IInvocationOperation invocation, ImmutableArray<ITypeSymbol> genericTypes, CodeFixContext context, string newName, int subjectIndex, int[] argumentsToRemove)
{
return ctx => RewriteExpressionCore(invocation, [

Check failure on line 28 in src/FluentAssertions.Analyzers/Tips/DocumentEditorUtils.cs

GitHub Actions / Performance regression check

Invalid expression term '['
..Array.ConvertAll(argumentsToRemove, arg => EditAction.RemoveInvocationArgument(arg)),
EditAction.SubjectShouldGenericAssertion(subjectIndex, newName, genericTypes)
], context, ctx);
public static CreateChangedDocument RenameMethodToSubjectShouldAssertionWithOptionsLambda(IInvocationOperation invocation, CodeFixContext context, string newName, int subjectIndex, int optionsIndex)
{
return ctx => RewriteExpressionCore(invocation, [

Check failure on line 36 in src/FluentAssertions.Analyzers/Tips/DocumentEditorUtils.cs

GitHub Actions / Performance regression check

Invalid expression term '['
EditAction.SubjectShouldAssertion(subjectIndex, newName),
EditAction.CreateEquivalencyAssertionOptionsLambda(optionsIndex)
], context, ctx);
}
}
public class EditActionContext(DocumentEditor editor, InvocationExpressionSyntax invocationExpression) {

Check failure on line 61 in src/FluentAssertions.Analyzers/Tips/DocumentEditorUtils.cs

GitHub Actions / Performance regression check

{ expected
public DocumentEditor Editor { get; } = editor;
public InvocationExpressionSyntax InvocationExpression { get; } = invocationExpression;
return false;
}
}
public class AssertThatRewriter(IInvocationOperation invocation, CodeFixContext context, IOperation constraint)

Check warning on line 674 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

GitHub Actions / build (macos-latest)

Parameter 'constraint' is unread.

Check warning on line 674 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

GitHub Actions / build (ubuntu-latest)

Parameter 'constraint' is unread.

Check warning on line 674 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

GitHub Actions / build (windows-latest)

Parameter 'constraint' is unread.
{
public CreateChangedDocument Should(string assertion)
{
}
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(AsyncVoidCodeFix)), Shared]
public class AsyncVoidCodeFix : CodeFixProvider

Check warning on line 74 in src/FluentAssertions.Analyzers/Tips/AsyncVoid.cs

GitHub Actions / build (macos-latest)

'AsyncVoidCodeFix' registers one or more code fixes, but does not override the method 'CodeFixProvider.GetFixAllProvider'. Override this method and provide a non-null FixAllProvider for FixAll support, potentially 'WellKnownFixAllProviders.BatchFixer', or 'null' to explicitly disable FixAll support.

Check warning on line 74 in src/FluentAssertions.Analyzers/Tips/AsyncVoid.cs

GitHub Actions / build (ubuntu-latest)

'AsyncVoidCodeFix' registers one or more code fixes, but does not override the method 'CodeFixProvider.GetFixAllProvider'. Override this method and provide a non-null FixAllProvider for FixAll support, potentially 'WellKnownFixAllProviders.BatchFixer', or 'null' to explicitly disable FixAll support.

Check warning on line 74 in src/FluentAssertions.Analyzers/Tips/AsyncVoid.cs

GitHub Actions / build (windows-latest)

'AsyncVoidCodeFix' registers one or more code fixes, but does not override the method 'CodeFixProvider.GetFixAllProvider'. Override this method and provide a non-null FixAllProvider for FixAll support, potentially 'WellKnownFixAllProviders.BatchFixer', or 'null' to explicitly disable FixAll support.
{
public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create(AsyncVoidAnalyzer.DiagnosticId);
public override Task RegisterCodeFixesAsync(CodeFixContext context)
Assert.That(collection, Is.Empty);
Assert.That(collection, Has.Count.EqualTo(0));
Assert.That(collection, Has.Count.Zero);
CollectionAssert.IsEmpty(collection);

Check warning on line 274 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 274 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 274 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)
// new assertion:
collection.Should().BeEmpty();
var collection = new List<int> { 1, 2, 3 };
// old assertion:
CollectionAssert.IsEmpty(collection);

Check warning on line 332 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 332 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 332 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)
}
[Test, ExpectedAssertionException]
Assert.That(collection, Is.Not.Empty);
Assert.That(collection, Has.Count.GreaterThan(0));
Assert.That(collection, Has.Count.Not.Zero);
CollectionAssert.IsNotEmpty(collection);

Check warning on line 357 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 357 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 357 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)
// new assertion:
collection.Should().NotBeEmpty();
var collection = new List<int>();
// old assertion:
CollectionAssert.IsNotEmpty(collection);

Check warning on line 415 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 415 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 415 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)
}
[Test, ExpectedAssertionException]
var obj2 = obj1;
// old assertion:
ClassicAssert.AreSame(obj1, obj2);

Check warning on line 524 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, ClassicAssert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 524 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, ClassicAssert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 524 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, ClassicAssert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)
// new assertion:
obj1.Should().BeSameAs(obj2);
object obj2 = "foo";
// old assertion:
ClassicAssert.AreSame(obj1, obj2);

Check warning on line 538 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, ClassicAssert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 538 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, ClassicAssert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 538 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, ClassicAssert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)
}
[Test, ExpectedAssertionException]
object obj2 = "foo";
// old assertion:
ClassicAssert.AreNotSame(obj1, obj2);

Check warning on line 560 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, ClassicAssert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 560 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, ClassicAssert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 560 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, ClassicAssert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)
// new assertion:
obj1.Should().NotBeSameAs(obj2);
object obj2 = "foo";
// old assertion:
ClassicAssert.AreNotSame(obj1, obj2);

Check warning on line 574 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, ClassicAssert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 574 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, ClassicAssert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 574 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, ClassicAssert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)
}
[Test, ExpectedAssertionException]
var expected = new[] { 1, 2, 3 };
// old assertion:
CollectionAssert.AreEqual(expected, collection);

Check warning on line 794 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 794 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 794 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)
Assert.That(collection, Is.EqualTo(expected));
// new assertion:
var expected = new[] { 1, 2, 4 };
// old assertion:
CollectionAssert.AreEqual(expected, collection);

Check warning on line 809 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 809 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)

Check warning on line 809 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit4/Nunit4AnalyzerTests.cs

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(...), instead of the classic model, CollectionAssert(...) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2049.md)
}
[Test, ExpectedAssertionException]