From 2508462bc75718efb821507da4ce933449e4238b Mon Sep 17 00:00:00 2001 From: Mary Georgiou <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:14:00 +0200 Subject: [PATCH] S1144: Add FP repro for #9416 (#9417) --- .../Rules/UnusedPrivateMemberTest.cs | 28 ++++++++++++++++++- .../NuGetMetadataFactory.cs | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) 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",