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
57 changes: 57 additions & 0 deletions src/FluentAssertions.Analyzers.Tests/Tips/SanityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,62 @@ public class MyCollectionType { }";
})
);
}

[TestMethod]
[Implemented(Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/290")]
public void ShouldNotReportIssue290()
{
const string source = @"
using FluentAssertions;
using FluentAssertions.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
public class TestClass
{
public static void Main()
{
IEnumerable<Item> expectedOrderedNames = new[] { new Item(""Alpha""), new Item(""Bravo""), new Item(""Charlie"") };
IEnumerable<Parent> actual = GetSortedItems();

actual.Select(x => x.Item).Should().Equal(expectedOrderedNames);
}

static IEnumerable<Parent> GetSortedItems()
{
yield return new Parent(""Bravo"");
yield return new Parent(""Charlie"");
yield return new Parent(""Alpha"");
}
}

public class Item
{
public string Name { get; set; }
public Guid Id { get; set; }

public Item(string name)
{
Name = name;
Id = Guid.NewGuid();
}
}

public class Parent
{
public Item Item { get; set; }

public Parent(string name)
{
Item = new Item(name);
}
}";

DiagnosticVerifier.VerifyDiagnostic(new DiagnosticVerifierArguments()
.WithSources(source)
.WithAllAnalyzers()
.WithPackageReferences(PackageReference.FluentAssertions_6_12_0)
);
}
}
}
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers/Tips/DiagnosticMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private DiagnosticMetadata(string message, string helpLink, [CallerMemberName] s
public static DiagnosticMetadata CollectionShouldHaveElementAt_SkipFirstShouldBe { get; } = new("Use .Should().HaveElementAt()", GetHelpLink("Collections-26"));
public static DiagnosticMetadata CollectionShouldBeInAscendingOrder_OrderByShouldEqual { get; } = new("Use .Should().BeInAscendingOrder()", GetHelpLink("Collections-27"));
public static DiagnosticMetadata CollectionShouldBeInDescendingOrder_OrderByDescendingShouldEqual { get; } = new("Use .Should().BeInDescendingOrder()", GetHelpLink("Collections-28"));
public static DiagnosticMetadata CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect { get; } = new("Use .Should().BeEquivalentTo()", GetHelpLink("Collections-29"));
public static DiagnosticMetadata CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect { get; } = new("Use .Should().Equal()", GetHelpLink("Collections-29"));
public static DiagnosticMetadata CollectionShouldNotIntersectWith_IntersectShouldBeEmpty { get; } = new("Use .Should().NotIntersectWith()", GetHelpLink("Collections-30"));
public static DiagnosticMetadata CollectionShouldIntersectWith_IntersectShouldNotBeEmpty { get; } = new("Use .Should().IntersectWith()", GetHelpLink("Collections-31"));
public static DiagnosticMetadata CollectionShouldNotContainNulls_SelectShouldNotContainNulls { get; } = new("Use .Should().NotContainNulls()", GetHelpLink("Collections-32"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ 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].Value is IInvocationOperation { TargetMethod.Name: nameof(Enumerable.Select), Arguments.Length: 2 } expectedInvocation && expectedInvocation.Arguments[1].IsLambda():
context.ReportDiagnostic(CreateDiagnostic(assertion, DiagnosticMetadata.CollectionShouldEqualOtherCollectionByComparer_SelectShouldEqualOtherCollectionSelect));
return;
}
Expand Down