Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 15 additions & 16 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.3.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />

<PackageVersion Include="FluentAssertions" Version="6.1.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.1" />

<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="NUnit.Analyzers" Version="3.6.1" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.3.0" />
<PackageVersion Include="NUnit" Version="4.2.2" />

<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageVersion Include="MSTest.TestFramework" Version="3.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.0" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.0" />

<PackageVersion Include="xunit.assert" Version="2.4.2" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="xunit.assert" Version="2.9.0" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />

<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />

<PackageVersion Include="BenchmarkDotNet" Version="0.13.5" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" PrivateAssets="all" />
Expand Down
48 changes: 32 additions & 16 deletions src/FluentAssertions.Analyzers.Tests/TestAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ public class AssertionDiagnosticAttribute : Attribute, ITestDataSource
{
public string Assertion { get; }

public bool Ignore { get; }

public AssertionDiagnosticAttribute(string assertion, bool ignore = false) => (Assertion, Ignore) = (assertion, ignore);
public AssertionDiagnosticAttribute(string assertion) => Assertion = assertion;

public IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
if (Ignore) yield break;

foreach (var assertion in TestCasesInputUtils.GetTestCases(Assertion))
{
yield return new object[] { assertion };
Expand All @@ -43,20 +39,24 @@ public IEnumerable<object[]> GetData(MethodInfo methodInfo)
public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"{data[0]}\")";
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class IgnoreAssertionDiagnosticAttribute : Attribute
{
public string Assertion { get; }

public IgnoreAssertionDiagnosticAttribute(string assertion) => Assertion = assertion;
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class AssertionCodeFixAttribute : Attribute, ITestDataSource
{
public string OldAssertion { get; }
public string NewAssertion { get; }

public bool Ignore { get; }

public AssertionCodeFixAttribute(string oldAssertion, string newAssertion, bool ignore = false) => (OldAssertion, NewAssertion, Ignore) = (oldAssertion, newAssertion, ignore);
public AssertionCodeFixAttribute(string oldAssertion, string newAssertion) => (OldAssertion, NewAssertion) = (oldAssertion, newAssertion);

public IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
if (Ignore) yield break;

foreach (var (oldAssertion, newAssertion) in TestCasesInputUtils.GetTestCases(OldAssertion, NewAssertion))
{
yield return new object[] { oldAssertion, newAssertion };
Expand All @@ -66,22 +66,27 @@ public IEnumerable<object[]> GetData(MethodInfo methodInfo)
public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"old: {data[0]}\", new: {data[1]}\")";
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class IgnoreAssertionCodeFixAttribute : Attribute
{
public string OldAssertion { get; }
public string NewAssertion { get; }

public IgnoreAssertionCodeFixAttribute(string oldAssertion, string newAssertion) => (OldAssertion, NewAssertion) = (oldAssertion, newAssertion);
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class AssertionMethodCodeFixAttribute : Attribute, ITestDataSource
{
public string MethodArguments { get; }
public string OldAssertion { get; }
public string NewAssertion { get; }

public bool Ignore { get; }

public AssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion, bool ignore = false)
=> (MethodArguments, OldAssertion, NewAssertion, Ignore) = (methodArguments, oldAssertion, newAssertion, ignore);
public AssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion)
=> (MethodArguments, OldAssertion, NewAssertion) = (methodArguments, oldAssertion, newAssertion);

public IEnumerable<object[]> GetData(MethodInfo methodInfo)
{
if (Ignore) yield break;

foreach (var (oldAssertion, newAssertion) in TestCasesInputUtils.GetTestCases(OldAssertion, NewAssertion))
{
yield return new object[] { MethodArguments, oldAssertion, newAssertion };
Expand All @@ -91,6 +96,17 @@ public IEnumerable<object[]> GetData(MethodInfo methodInfo)
public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"arguments\":{data[0]}, \"old: {data[1]}\", new: {data[2]}\")";
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class IgnoreAssertionMethodCodeFixAttribute : Attribute
{
public string MethodArguments { get; }
public string OldAssertion { get; }
public string NewAssertion { get; }

public IgnoreAssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion)
=> (MethodArguments, OldAssertion, NewAssertion) = (methodArguments, oldAssertion, newAssertion);
}

public static class TestCasesInputUtils
{
private static readonly string Empty = string.Empty;
Expand Down
21 changes: 10 additions & 11 deletions src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ public class CollectionTests
[Implemented]
public void CollectionShouldNotContainProperty_WhereShouldBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_WhereShouldBeEmpty);

[DataTestMethod]
[AssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});", ignore: true)]
[AssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)]
[AssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)]
[AssertionDiagnostic("actual.ToList().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)]
// TODO: all test cases are ignored
// [DataTestMethod]
[IgnoreAssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});")]
[IgnoreAssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")]
[IgnoreAssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")]
[IgnoreAssertionDiagnostic("actual.ToList().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")]
[Implemented]
public void CollectionShouldNotContainProperty_ShouldOnlyContainNot_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_ShouldOnlyContainNot);

Expand All @@ -199,20 +200,18 @@ public class CollectionTests
[AssertionCodeFix(
oldAssertion: "actual.Where(x => x.BooleanProperty).Should().BeEmpty({0});",
newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});")]
[AssertionCodeFix(
[IgnoreAssertionCodeFix(
oldAssertion: "actual.Should().OnlyContain(x => !x.BooleanProperty{0});",
newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});",
ignore: true)]
newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});")]
[AssertionCodeFix(
oldAssertion: "actual.AsEnumerable().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();",
newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")]
[AssertionCodeFix(
oldAssertion: "actual.AsEnumerable().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();",
newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")]
[AssertionCodeFix(
[IgnoreAssertionCodeFix(
oldAssertion: "actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();",
newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();",
ignore: true)]
newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")]
[Implemented]
public void CollectionShouldNotContainProperty_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock(oldAssertion, newAssertion);

Expand Down
Loading