-
Notifications
You must be signed in to change notification settings - Fork 0
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
Riku Virtanen
committed
Mar 1, 2024
1 parent
629ff69
commit edf75c1
Showing
9 changed files
with
100 additions
and
311 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
41 changes: 2 additions & 39 deletions
41
...ds.MicrosoftSQL.ExecuteQuery/Frends.MicrosoftSQL.ExecuteQuery.Tests/ExceptionUnitTests.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
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
39 changes: 39 additions & 0 deletions
39
...rosoftSQL.ExecuteQuery/Frends.MicrosoftSQL.ExecuteQuery.Tests/Lib/ExecuteQueryTestBase.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,39 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Frends.MicrosoftSQL.ExecuteQuery.Tests.Lib; | ||
|
||
public class ExecuteQueryTestBase | ||
{ | ||
internal static readonly string _connString = Helper.CreateConnectionString(); | ||
internal static readonly string _tableName = "TestTable"; | ||
|
||
[TestInitialize] | ||
public void Init() | ||
{ | ||
using var connection = new SqlConnection(_connString); | ||
Check failure Code scanning / CodeQL Insecure SQL connection High Connection string Error loading related location Loading |
||
connection.Open(); | ||
var createTable = connection.CreateCommand(); | ||
createTable.CommandText = $@"IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='{_tableName}') BEGIN CREATE TABLE {_tableName} ( Id int, LastName varchar(255), FirstName varchar(255) ); END"; | ||
createTable.ExecuteNonQuery(); | ||
connection.Close(); | ||
connection.Dispose(); | ||
} | ||
|
||
[TestCleanup] | ||
public void CleanUp() | ||
{ | ||
using var connection = new SqlConnection(_connString); | ||
Check failure Code scanning / CodeQL Insecure SQL connection High Connection string Error loading related location Loading |
||
connection.Open(); | ||
var createTable = connection.CreateCommand(); | ||
createTable.CommandText = $@"IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='{_tableName}') BEGIN DROP TABLE IF EXISTS {_tableName}; END"; | ||
createTable.ExecuteNonQuery(); | ||
connection.Close(); | ||
connection.Dispose(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Frends.MicrosoftSQL.ExecuteQuery/Frends.MicrosoftSQL.ExecuteQuery.Tests/Lib/Helper.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,23 @@ | ||
using System.Data.SqlClient; | ||
|
||
namespace Frends.MicrosoftSQL.ExecuteQuery.Tests.Lib; | ||
|
||
internal class Helper | ||
{ | ||
internal static string CreateConnectionString() | ||
{ | ||
return "Server=127.0.0.1,1433;Database=Master;User Id=SA;Password=Salakala123!"; | ||
Check failure Code scanning / CodeQL Hard-coded connection string with credentials Critical
'ConnectionString' property includes hard-coded credentials set in
object creation of type SqlConnection Error loading related location Loading 'ConnectionString' property includes hard-coded credentials set in object creation of type SqlConnection Error loading related location Loading 'ConnectionString' property includes hard-coded credentials set in object creation of type SqlConnection Error loading related location Loading 'ConnectionString' property includes hard-coded credentials set in object creation of type SqlConnection Error loading related location Loading 'ConnectionString' property includes hard-coded credentials set in object creation of type SqlConnection Error loading related location Loading |
||
} | ||
|
||
internal static int GetRowCount(string connString, string table) | ||
{ | ||
using var connection = new SqlConnection(connString); | ||
Check failure Code scanning / CodeQL Insecure SQL connection High Connection string Error loading related location Loading |
||
connection.Open(); | ||
var getRows = connection.CreateCommand(); | ||
getRows.CommandText = $"SELECT COUNT(*) FROM {table}"; | ||
var count = (int)getRows.ExecuteScalar(); | ||
connection.Close(); | ||
connection.Dispose(); | ||
return count; | ||
} | ||
} |
Oops, something went wrong.