Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: update dependencies
  • Loading branch information
Meir017 committed Sep 13, 2024
commit aa0dae22cf2ecf81a929ce7506f09fd6f823e927
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
18 changes: 8 additions & 10 deletions src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ public class CollectionTests
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)]
[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 +199,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