diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.cs index 399a7316b13..6a44b63f6da 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.cs @@ -39,6 +39,13 @@ void SameIndexOnList(List list) list[0] = 42; // Noncompliant } + void ListAddFP(List list) + { + // FP - List.Add method should not raise any issue when used with same elements + list.Add(42); // Secondary + list.Add(42); // Noncompliant + } + void SameIndexOnArray(CustomIndexerOneArg obj) { obj["foo"] = 42; // Compliant, not a collection or dictionary diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.vb b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.vb index dec223de545..878657bc1ca 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.vb +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/DoNotOverwriteCollectionElements.vb @@ -62,6 +62,11 @@ Namespace Tests.TestCases list(0) = 1 ' Noncompliant End Sub + Private Sub ListAddFP(ByVal list As List(Of String)) + list.Add("MyText") ' Secondary + list.Add("MyText") ' Noncompliant + End Sub + Private Sub SameIndexSpacedOut(ByVal names() As String) names("a") = "a" ' Secondary names("b") = "b"