-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4e675f
commit f79180f
Showing
3 changed files
with
53 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
analyzers/tests/SonarAnalyzer.Test/TestCases/StringLiteralShouldNotBeDuplicated.Dapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Dapper; | ||
using System.Data.SqlClient; | ||
|
||
// https://github.com/SonarSource/sonar-dotnet/issues/9569 | ||
public class RepeatedParameterNamesInDatabase | ||
{ | ||
public void ExecuteSqlCommandsForUsers(SqlConnection connection) | ||
{ | ||
var query = "SELECT * FROM Users WHERE Name = @name"; | ||
var param = new DynamicParameters(); | ||
param.Add("@name", "John Doe"); // Noncompliant - FP: @Name refers to parameters in different SQL tables. | ||
var result = connection.Query<User>(query, param); // Renaming one does not necessitate renaming of parameters with the same name from other tables. | ||
} | ||
|
||
public void ExecuteSqlCommandsForCompanies(SqlConnection connection) | ||
{ | ||
var query = "SELECT * FROM Companies WHERE Name = @name"; | ||
var param = new DynamicParameters(); | ||
param.Add("@name", "Constosco"); // Secondary - FP | ||
var result = connection.Query<Company>(query, param); | ||
} | ||
|
||
public void ExecuteSqlCommandsForProducts(SqlConnection connection) | ||
{ | ||
var query = "SELECT * FROM Companies WHERE Name = @name"; | ||
var param = new DynamicParameters(); | ||
param.Add("@name", "CleanBot 9000"); // Secondary - FP | ||
var result = connection.Query<Product>(query, param); | ||
} | ||
|
||
public void ExecuteSqlCommandsForCountries(SqlConnection connection) | ||
{ | ||
var query = "SELECT * FROM Countries WHERE Name = @name"; | ||
var param = new DynamicParameters(); | ||
param.Add("@name", "Norway"); // Secondary - FP | ||
var result = connection.Query<Country>(query, param); | ||
} | ||
|
||
public class Product { } | ||
public class Country { } | ||
public class Company { } | ||
public class User { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters