Skip to content

Commit

Permalink
bugfix: fix issue #290
Browse files Browse the repository at this point in the history
  • Loading branch information
Meir017 committed Jan 17, 2024
1 parent a391d11 commit 2eee45f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,17 @@ public class TestClass
{
public static void Main()
{
IEnumerable<string> expectedOrderedNames = new[] { ""Alpha"", ""Bravo"", ""Charlie"" };
IEnumerable<Item> actual = GetSortedItems();
IEnumerable<Item> expectedOrderedNames = new[] { new Item(""Alpha""), new Item(""Bravo""), new Item(""Charlie"") };
IEnumerable<Parent> actual = GetSortedItems();
actual.Select(x => x.Name).Should().Equal(expectedOrderedNames);
actual.Select(x => x.Item).Should().Equal(expectedOrderedNames);
}
static IEnumerable<Item> GetSortedItems() {
yield return new Item(""Bravo"", Guid.NewGuid());
yield return new Item(""Charlie"", Guid.NewGuid());
yield return new Item(""Alpha"", Guid.NewGuid());
static IEnumerable<Parent> GetSortedItems()
{
yield return new Parent(""Bravo"");
yield return new Parent(""Charlie"");
yield return new Parent(""Alpha"");
}
}
Expand All @@ -481,10 +482,20 @@ public class Item
public string Name { get; set; }
public Guid Id { get; set; }
public Item(string name, Guid id)
public Item(string name)
{
Name = name;
Id = id;
Id = Guid.NewGuid();
}
}
public class Parent
{
public Item Item { get; set; }
public Parent(string name)
{
Item = new Item(name);
}
}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static void AnalyzeInvocation(OperationAnalysisContext context, FluentAs
case nameof(Enumerable.OrderByDescending) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata) && invocationBeforeShould.Arguments[0].IsSameArgumentReference(assertion.Arguments[0]):
context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual));
return;
case nameof(Enumerable.Select) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata):
case nameof(Enumerable.Select) when IsEnumerableMethodWithPredicate(invocationBeforeShould, metadata) && assertion.Arguments[0].IsLambda():
context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect));
return;
}
Expand Down

0 comments on commit 2eee45f

Please sign in to comment.