diff --git a/analyzers/tests/SonarAnalyzer.Test/Rules/UnusedPrivateMemberTest.cs b/analyzers/tests/SonarAnalyzer.Test/Rules/UnusedPrivateMemberTest.cs index 3172bce608e..09681bfb868 100644 --- a/analyzers/tests/SonarAnalyzer.Test/Rules/UnusedPrivateMemberTest.cs +++ b/analyzers/tests/SonarAnalyzer.Test/Rules/UnusedPrivateMemberTest.cs @@ -154,7 +154,9 @@ private void SomeMethod(bool condition) { } // Compliant protected override void Up(MigrationBuilder migrationBuilder) { } } } - """).AddReferences(EntityFrameworkCoreReferences("7.0.14")).VerifyNoIssues(); + """) + .AddReferences(EntityFrameworkCoreReferences("7.0.14")) + .VerifyNoIssues(); [DataTestMethod] [DataRow(ProjectType.Product)] @@ -203,6 +205,30 @@ public void UnusedPrivateMember_FromCSharp12() => .WithOptions(ParseOptionsHelper.FromCSharp12) .VerifyNoIssues(); + [TestMethod] + public void UnusedPrivateMemeber_EntityFramework_DontRaiseOnUnusedEntityPropertiesPrivateSetters() => + builder.AddSnippet(""" + // Repro https://github.com/SonarSource/sonar-dotnet/issues/9416 + using Microsoft.EntityFrameworkCore; + + internal class MyContext : DbContext + { + public DbSet Blogs { get; set; } + } + + public class Blog + { + public Blog(int id, string name) + { + Name = name; + } + + public int Id { get; private set; } // Noncompliant FP + public string Name { get; private set; } + } + """) + .AddReferences(NuGetMetadataReference.MicrosoftEntityFrameworkCore("8.0.6")) + .Verify(); #endif [TestMethod] diff --git a/analyzers/tests/SonarAnalyzer.TestFramework/MetadataReferences/NuGetMetadataFactory.cs b/analyzers/tests/SonarAnalyzer.TestFramework/MetadataReferences/NuGetMetadataFactory.cs index 76fd122e5a9..484aab8f598 100644 --- a/analyzers/tests/SonarAnalyzer.TestFramework/MetadataReferences/NuGetMetadataFactory.cs +++ b/analyzers/tests/SonarAnalyzer.TestFramework/MetadataReferences/NuGetMetadataFactory.cs @@ -36,6 +36,7 @@ internal static partial class NuGetMetadataFactory "netstandard2.0", "net7.0", "net6.0", + "net8.0", "net47", "net461", "netstandard1.6",