Skip to content

Commit

Permalink
Add C# 9 unit tests for S4055 (SonarSource#3752)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mikula-sonarsource authored and Corniel Nobel committed Nov 30, 2020
1 parent 5e72b07 commit c285b29
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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)
{
}
}
}

0 comments on commit c285b29

Please sign in to comment.