From c285b295296539e23ba8c6dce27f6c1031bd56c9 Mon Sep 17 00:00:00 2001 From: Pavel Mikula <57188685+pavel-mikula-sonarsource@users.noreply.github.com> Date: Mon, 16 Nov 2020 12:07:13 +0100 Subject: [PATCH] Add C# 9 unit tests for S4055 (#3752) --- ...uldNotBePassedAsLocalizedParametersTest.cs | 7 +++++ ...otBePassedAsLocalizedParameters.CSharp9.cs | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/LiteralsShouldNotBePassedAsLocalizedParameters.CSharp9.cs diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/LiteralsShouldNotBePassedAsLocalizedParametersTest.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/LiteralsShouldNotBePassedAsLocalizedParametersTest.cs index 3e6922f0726..d22fbc093ef 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/LiteralsShouldNotBePassedAsLocalizedParametersTest.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/Rules/LiteralsShouldNotBePassedAsLocalizedParametersTest.cs @@ -35,5 +35,12 @@ public void LiteralsShouldNotBePassedAsLocalizedParameters() => Verifier.VerifyAnalyzer(@"TestCases\LiteralsShouldNotBePassedAsLocalizedParameters.cs", new LiteralsShouldNotBePassedAsLocalizedParameters(), additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives()); + + [TestMethod] + [TestCategory("Rule")] + public void LiteralsShouldNotBePassedAsLocalizedParameters_CSharp9() => + Verifier.VerifyAnalyzerFromCSharp9Console(@"TestCases\LiteralsShouldNotBePassedAsLocalizedParameters.CSharp9.cs", + new LiteralsShouldNotBePassedAsLocalizedParameters(), + additionalReferences: MetadataReferenceFacade.GetSystemComponentModelPrimitives()); } } diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/LiteralsShouldNotBePassedAsLocalizedParameters.CSharp9.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/LiteralsShouldNotBePassedAsLocalizedParameters.CSharp9.cs new file mode 100644 index 00000000000..456ffbf32cf --- /dev/null +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/LiteralsShouldNotBePassedAsLocalizedParameters.CSharp9.cs @@ -0,0 +1,27 @@ +using System.ComponentModel; + +TopLevelLocalFunction("literal", "literal"); //Noncompliant + //Noncompliant@-1 + +void TopLevelLocalFunction([Localizable(true)] string param1, string message) +{ +} + +record Record +{ + [Localizable(true)] + public string Property1 { get; set; } + public string Property2 { get; set; } + + public void Method() + { + Property1 = "lorem"; // Noncompliant + Property2 = "ipsum"; + + LocalFunctionWithAttribute("literal"); //Noncompliant + + void LocalFunctionWithAttribute([Localizable(true)] string param1) + { + } + } +}