Skip to content

Commit

Permalink
Add C# 9 test cases for S3994..7, S4005
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Oct 30, 2020
1 parent d0fe741 commit 55a795b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using csharp::SonarAnalyzer.Rules.CSharp;
using SonarAnalyzer.UnitTest.MetadataReferences;
using SonarAnalyzer.UnitTest.TestFramework;
using Microsoft.CodeAnalysis;

namespace SonarAnalyzer.UnitTest.Rules
{
Expand All @@ -36,6 +37,15 @@ public void UseUriInsteadOfString() =>
new UseUriInsteadOfString(),
additionalReferences: MetadataReferenceFacade.GetSystemDrawing());

[TestMethod]
[TestCategory("Rule")]
public void UseUriInsteadOfString_CSharp9() =>
Verifier.VerifyAnalyzer(@"TestCases\UseUriInsteadOfString.CSharp9.cs",
new UseUriInsteadOfString(),
ParseOptionsHelper.FromCSharp9,
additionalReferences: MetadataReferenceFacade.GetSystemDrawing(),
outputKind: OutputKind.ConsoleApplication);

[TestMethod]
[TestCategory("Rule")]
public void UseUriInsteadOfString_InvalidCode() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
S3994 p = new("www.sonarsource.com"); // Compliant - FN

string GetUrl(string url) => ""; // Compliant - FN

public record S3994
{
public S3994(string uri) { } // Noncompliant {{Either change this parameter type to 'System.Uri' or provide an overload which takes a 'System.Uri' parameter.}}

public S3994(string uri, bool blah) { } // Noncompliant {{Either change this parameter type to 'System.Uri' or provide an overload which takes a 'System.Uri' parameter.}}

public virtual string Url { get; set; } // Noncompliant {{Change this property type to 'System.Uri'.}}
// ^^^^^^
}

0 comments on commit 55a795b

Please sign in to comment.