Skip to content
Merged
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
Next Next commit
feat: improve TryGetFirstDescendent logic
  • Loading branch information
Meir017 committed Oct 7, 2024
commit 7cb5a7edae9037257302ec8ae93b8f402d2965b1
28 changes: 25 additions & 3 deletions src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,32 @@ public class CollectionTests
[AssertionDiagnostic("actual.ToArray().Count().Should().Be(1{0}).And.ToString();")]
[Implemented]
public void CollectionShouldHaveCount_CountShouldBe1_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldContainSingle_CountShouldBe1);

[DataTestMethod]
[AssertionDiagnostic("actual.ToArray().Length.Should().Be(1{0}).And.ToString();")]
[AssertionDiagnostic("(array.Count() + 1).Should().Be(0{0}).And.ToString();")]
[AssertionDiagnostic("(array.Count() + 1).Should().Be(1{0}).And.ToString();")]
[AssertionDiagnostic("(array.Count() + 1).Should().Be(expectedSize{0}).And.ToString();")]
[AssertionDiagnostic("(list.Count + 1).Should().Be(0{0}).And.ToString();")]
[AssertionDiagnostic("(list.Count + 1).Should().Be(1{0}).And.ToString();")]
[AssertionDiagnostic("(list.Count + 1).Should().Be(expectedSize{0}).And.ToString();")]
[Implemented]
public void CollectionShouldHaveCount_LengthShouldBe_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldHaveCount_LengthShouldBe);
public void CollectionShouldHaveCount_CountShouldBe_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(new StringBuilder()
.AppendLine("using System;")
.AppendLine("using System.Collections.Generic;")
.AppendLine("using System.Linq;")
.AppendLine("using FluentAssertions;")
.AppendLine("using FluentAssertions.Extensions;")
.AppendLine("namespace TestNamespace")
.AppendLine("{")
.AppendLine(" public class TestClass")
.AppendLine(" {")
.AppendLine(" public void TestMethod(string[] array, List<string> list, int expectedSize)")
.AppendLine(" {")
.AppendLine(assertion)
.AppendLine(" }")
.AppendLine(" }")
.AppendLine("}")
.ToString());

[DataTestMethod]
[AssertionDiagnostic(@"var array = new string[0, 0]; array.Length.Should().Be(0{0});")]
Expand All @@ -330,6 +351,7 @@ public class CollectionTests
[AssertionDiagnostic(@"var array = new string[2, 2]; array.Length.Should().Be(0{0});")]
[AssertionDiagnostic(@"var array = new string[3, 3, 3]; array.Length.Should().Be(0{0});")]
[AssertionDiagnostic(@"int[] array1 = [1, 2, 3]; int[] array2 = [4, 5, 6]; int[] both = [..array1, ..array2]; (array1.Length + array2.Length).Should().Be(both.Length{0});")]
[AssertionDiagnostic("(actual.Count() + 1).Should().Be(1{0}).And.ToString();")]
[Implemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/309")]
public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer(string assertion) => DiagnosticVerifier.VerifyCSharpDiagnosticUsingAllAnalyzers(new StringBuilder()
.AppendLine("using System;")
Expand Down
Loading