fluentassertions / fluentassertions.analyzers

Analyzers based on the FluentAssertions best practices docs
https://www.fluentassertions.com/tips
MIT License
136 stars 21 forks source link

False positive for "Use `.Should().HaveSameCount()`" #300

Closed FantasyTeddy closed 7 months ago

FantasyTeddy commented 7 months ago

Description

The analysis rule FAA0001: Use .Should().HaveSameCount() is triggered for inputs that are actually combined values:

// Arrange
var expectedFirstHalf = new List<int> {0};
var expectedSecondHalf = new List<int> {1};

// Act
var actual = new List<int> {10, 11};

// Assert
actual.Should().HaveCount(expectedFirstHalf.Count() + expectedSecondHalf.Count());

Expected behavior:

Since the input (expectedFirstHalf.Count() + expectedSecondHalf.Count()) is actually a calculated value, the analysis rule should not be triggered.

Actual behavior:

The rule is triggered and the code fix crashes.

Versions

Meir017 commented 7 months ago

@FantasyTeddy Thanks for reporting this!