-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: consolidate sync and async variations of MsSql integration tes…
…ts (#2095) * Consolidate MsSql sync/async tests * Remove unused test app * Consolidate async/sync query param tests * More consolidation
- Loading branch information
1 parent
ddee81d
commit eadaf4b
Showing
17 changed files
with
209 additions
and
1,291 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Collections.Generic; | ||
|
@@ -16,17 +16,9 @@ | |
namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MsSql | ||
{ | ||
[Library] | ||
public class MicrosoftDataSqlClientExerciser | ||
public class MicrosoftDataSqlClientExerciser : MsSqlExerciserBase | ||
{ | ||
|
||
private const string InsertPersonMsSql = "INSERT INTO {0} (FirstName, LastName, Email) VALUES('Testy', 'McTesterson', '[email protected]')"; | ||
private const string DeletePersonMsSql = "DELETE FROM {0} WHERE Email = '[email protected]'"; | ||
private const string CountPersonMsSql = "SELECT COUNT(*) FROM {0} WITH(nolock)"; | ||
private static readonly string CreateProcedureStatement = @"CREATE OR ALTER PROCEDURE [dbo].[{0}] {1} AS RETURN 0"; | ||
private const string CreatePersonTableMsSql = "CREATE TABLE {0} (FirstName varchar(20) NOT NULL, LastName varchar(20) NOT NULL, Email varchar(50) NOT NULL)"; | ||
private const string DropPersonTableMsSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP TABLE {0}"; | ||
private const string DropProcedureSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP PROCEDURE {0}"; | ||
|
||
[LibraryMethod] | ||
[Transaction] | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
|
@@ -38,7 +30,7 @@ public string MsSql(string tableName) | |
{ | ||
connection.Open(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'", connection)) | ||
using (var command = new SqlCommand(SelectPersonByFirstNameMsSql, connection)) | ||
{ | ||
|
||
using (var reader = command.ExecuteReader()) | ||
|
@@ -88,7 +80,7 @@ public async Task<string> MsSqlAsync(string tableName) | |
{ | ||
await connection.OpenAsync(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'", connection)) | ||
using (var command = new SqlCommand(SelectPersonByLastNameMsSql, connection)) | ||
{ | ||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
|
@@ -137,7 +129,7 @@ public string MsSqlWithParameterizedQuery(bool paramsWithAtSign) | |
{ | ||
connection.Open(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN", connection)) | ||
using (var command = new SqlCommand(SelectPersonByParameterizedFirstNameMsSql, connection)) | ||
{ | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@FN" : "FN", "O'Keefe")); | ||
using (var reader = command.ExecuteReader()) | ||
|
@@ -160,17 +152,17 @@ public string MsSqlWithParameterizedQuery(bool paramsWithAtSign) | |
[LibraryMethod] | ||
[Transaction] | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
public async Task<string> MsSqlAsync_WithParameterizedQuery(string tableName, bool paramsWithAtSign) | ||
public async Task<string> MsSqlAsync_WithParameterizedQuery(bool paramsWithAtSign) | ||
{ | ||
var teamMembers = new List<string>(); | ||
|
||
using (var connection = new SqlConnection(MsSqlConfiguration.MsSqlConnectionString)) | ||
{ | ||
await connection.OpenAsync(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN", connection)) | ||
using (var command = new SqlCommand(SelectPersonByParameterizedLastNameMsSql, connection)) | ||
{ | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@FN" : "FN", "O'Keefe")); | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@LN" : "LN", "Lee")); | ||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
while (await reader.ReadAsync()) | ||
|
@@ -183,25 +175,6 @@ public async Task<string> MsSqlAsync_WithParameterizedQuery(string tableName, bo | |
} | ||
} | ||
} | ||
|
||
var insertSql = string.Format(InsertPersonMsSql, tableName); | ||
var countSql = string.Format(CountPersonMsSql, tableName); | ||
var deleteSql = string.Format(DeletePersonMsSql, tableName); | ||
|
||
using (var command = new SqlCommand(insertSql, connection)) | ||
{ | ||
var insertCount = await command.ExecuteNonQueryAsync(); | ||
} | ||
|
||
using (var command = new SqlCommand(countSql, connection)) | ||
{ | ||
var teamMemberCount = await command.ExecuteScalarAsync(); | ||
} | ||
|
||
using (var command = new SqlCommand(deleteSql, connection)) | ||
{ | ||
var deleteCount = await command.ExecuteNonQueryAsync(); | ||
} | ||
} | ||
|
||
return string.Join(",", teamMembers); | ||
|
21 changes: 21 additions & 0 deletions
21
...s/Common/MultiFunctionApplicationHelpers/NetStandardLibraries/MsSql/MsSqlExerciserBase.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,21 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MsSql | ||
{ | ||
public class MsSqlExerciserBase | ||
{ | ||
|
||
protected const string SelectPersonByFirstNameMsSql = "SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'"; | ||
protected const string SelectPersonByLastNameMsSql = "SELECT * FROM NewRelic.dbo.TeamMembers WHERE LastName = 'Doe'"; | ||
protected const string SelectPersonByParameterizedFirstNameMsSql = "SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN"; | ||
protected const string SelectPersonByParameterizedLastNameMsSql = "SELECT * FROM NewRelic.dbo.TeamMembers WHERE LastName = @LN"; | ||
protected const string InsertPersonMsSql = "INSERT INTO {0} (FirstName, LastName, Email) VALUES('Testy', 'McTesterson', '[email protected]')"; | ||
protected const string DeletePersonMsSql = "DELETE FROM {0} WHERE Email = '[email protected]'"; | ||
protected const string CountPersonMsSql = "SELECT COUNT(*) FROM {0} WITH(nolock)"; | ||
protected static readonly string CreateProcedureStatement = @"CREATE OR ALTER PROCEDURE [dbo].[{0}] {1} AS RETURN 0"; | ||
protected const string CreatePersonTableMsSql = "CREATE TABLE {0} (FirstName varchar(20) NOT NULL, LastName varchar(20) NOT NULL, Email varchar(50) NOT NULL)"; | ||
protected const string DropPersonTableMsSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP TABLE {0}"; | ||
protected const string DropProcedureSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP PROCEDURE {0}"; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if NETFRAMEWORK | ||
|
@@ -19,16 +19,8 @@ | |
namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MsSql | ||
{ | ||
[Library] | ||
public class SystemDataExerciser | ||
public class SystemDataExerciser : MsSqlExerciserBase | ||
{ | ||
private const string InsertPersonMsSql = "INSERT INTO {0} (FirstName, LastName, Email) VALUES('Testy', 'McTesterson', '[email protected]')"; | ||
private const string DeletePersonMsSql = "DELETE FROM {0} WHERE Email = '[email protected]'"; | ||
private const string CountPersonMsSql = "SELECT COUNT(*) FROM {0} WITH(nolock)"; | ||
private static readonly string CreateProcedureStatement = @"CREATE OR ALTER PROCEDURE [dbo].[{0}] {1} AS RETURN 0"; | ||
private const string CreatePersonTableMsSql = "CREATE TABLE {0} (FirstName varchar(20) NOT NULL, LastName varchar(20) NOT NULL, Email varchar(50) NOT NULL)"; | ||
private const string DropPersonTableMsSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP TABLE {0}"; | ||
private const string DropProcedureSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP PROCEDURE {0}"; | ||
|
||
[LibraryMethod] | ||
[Transaction] | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
|
@@ -40,7 +32,7 @@ public string MsSql(string tableName) | |
{ | ||
connection.Open(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'", connection)) | ||
using (var command = new SqlCommand(SelectPersonByFirstNameMsSql, connection)) | ||
{ | ||
|
||
using (var reader = command.ExecuteReader()) | ||
|
@@ -90,7 +82,7 @@ public async Task<string> MsSqlAsync(string tableName) | |
{ | ||
await connection.OpenAsync(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'", connection)) | ||
using (var command = new SqlCommand(SelectPersonByLastNameMsSql, connection)) | ||
{ | ||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
|
@@ -139,7 +131,7 @@ public string MsSqlWithParameterizedQuery(bool paramsWithAtSign) | |
{ | ||
connection.Open(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN", connection)) | ||
using (var command = new SqlCommand(SelectPersonByParameterizedFirstNameMsSql, connection)) | ||
{ | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@FN" : "FN", "O'Keefe")); | ||
using (var reader = command.ExecuteReader()) | ||
|
@@ -163,17 +155,17 @@ public string MsSqlWithParameterizedQuery(bool paramsWithAtSign) | |
[LibraryMethod] | ||
[Transaction] | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
public async Task<string> MsSqlAsync_WithParameterizedQuery(string tableName, bool paramsWithAtSign) | ||
public async Task<string> MsSqlAsync_WithParameterizedQuery(bool paramsWithAtSign) | ||
{ | ||
var teamMembers = new List<string>(); | ||
|
||
using (var connection = new SqlConnection(MsSqlConfiguration.MsSqlConnectionString)) | ||
{ | ||
await connection.OpenAsync(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN", connection)) | ||
using (var command = new SqlCommand(SelectPersonByParameterizedLastNameMsSql, connection)) | ||
{ | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@FN" : "FN", "O'Keefe")); | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@LN" : "LN", "Lee")); | ||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
while (await reader.ReadAsync()) | ||
|
@@ -186,25 +178,6 @@ public async Task<string> MsSqlAsync_WithParameterizedQuery(string tableName, bo | |
} | ||
} | ||
} | ||
|
||
var insertSql = string.Format(InsertPersonMsSql, tableName); | ||
var countSql = string.Format(CountPersonMsSql, tableName); | ||
var deleteSql = string.Format(DeletePersonMsSql, tableName); | ||
|
||
using (var command = new SqlCommand(insertSql, connection)) | ||
{ | ||
var insertCount = await command.ExecuteNonQueryAsync(); | ||
} | ||
|
||
using (var command = new SqlCommand(countSql, connection)) | ||
{ | ||
var teamMemberCount = await command.ExecuteScalarAsync(); | ||
} | ||
|
||
using (var command = new SqlCommand(deleteSql, connection)) | ||
{ | ||
var deleteCount = await command.ExecuteNonQueryAsync(); | ||
} | ||
} | ||
|
||
return string.Join(",", teamMembers); | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#if NETCOREAPP3_1_OR_GREATER | ||
|
@@ -13,22 +13,12 @@ | |
using NewRelic.Agent.IntegrationTests.Shared.ReflectionHelpers; | ||
using NewRelic.Api.Agent; | ||
using System.Threading; | ||
using System.Data.OleDb; | ||
using System.Data.Odbc; | ||
|
||
namespace MultiFunctionApplicationHelpers.NetStandardLibraries.MsSql | ||
{ | ||
[Library] | ||
public class SystemDataSqlClientExerciser | ||
public class SystemDataSqlClientExerciser : MsSqlExerciserBase | ||
{ | ||
private const string InsertPersonMsSql = "INSERT INTO {0} (FirstName, LastName, Email) VALUES('Testy', 'McTesterson', '[email protected]')"; | ||
private const string DeletePersonMsSql = "DELETE FROM {0} WHERE Email = '[email protected]'"; | ||
private const string CountPersonMsSql = "SELECT COUNT(*) FROM {0} WITH(nolock)"; | ||
private static readonly string CreateProcedureStatement = @"CREATE OR ALTER PROCEDURE [dbo].[{0}] {1} AS RETURN 0"; | ||
private const string CreatePersonTableMsSql = "CREATE TABLE {0} (FirstName varchar(20) NOT NULL, LastName varchar(20) NOT NULL, Email varchar(50) NOT NULL)"; | ||
private const string DropPersonTableMsSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP TABLE {0}"; | ||
private const string DropProcedureSql = "IF (OBJECT_ID('{0}') IS NOT NULL) DROP PROCEDURE {0}"; | ||
|
||
[LibraryMethod] | ||
[Transaction] | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
|
@@ -40,7 +30,7 @@ public string MsSql(string tableName) | |
{ | ||
connection.Open(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'", connection)) | ||
using (var command = new SqlCommand(SelectPersonByFirstNameMsSql, connection)) | ||
{ | ||
|
||
using (var reader = command.ExecuteReader()) | ||
|
@@ -90,7 +80,7 @@ public async Task<string> MsSqlAsync(string tableName) | |
{ | ||
await connection.OpenAsync(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = 'John'", connection)) | ||
using (var command = new SqlCommand(SelectPersonByLastNameMsSql, connection)) | ||
{ | ||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
|
@@ -139,7 +129,7 @@ public string MsSqlWithParameterizedQuery(bool paramsWithAtSign) | |
{ | ||
connection.Open(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN", connection)) | ||
using (var command = new SqlCommand(SelectPersonByParameterizedFirstNameMsSql, connection)) | ||
{ | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@FN" : "FN", "O'Keefe")); | ||
using (var reader = command.ExecuteReader()) | ||
|
@@ -163,17 +153,17 @@ public string MsSqlWithParameterizedQuery(bool paramsWithAtSign) | |
[LibraryMethod] | ||
[Transaction] | ||
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)] | ||
public async Task<string> MsSqlAsync_WithParameterizedQuery(string tableName, bool paramsWithAtSign) | ||
public async Task<string> MsSqlAsync_WithParameterizedQuery(bool paramsWithAtSign) | ||
{ | ||
var teamMembers = new List<string>(); | ||
|
||
using (var connection = new SqlConnection(MsSqlConfiguration.MsSqlConnectionString)) | ||
{ | ||
await connection.OpenAsync(); | ||
|
||
using (var command = new SqlCommand("SELECT * FROM NewRelic.dbo.TeamMembers WHERE FirstName = @FN", connection)) | ||
using (var command = new SqlCommand(SelectPersonByParameterizedLastNameMsSql, connection)) | ||
{ | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@FN" : "FN", "O'Keefe")); | ||
command.Parameters.Add(new SqlParameter(paramsWithAtSign ? "@LN" : "LN", "Lee")); | ||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
while (await reader.ReadAsync()) | ||
|
@@ -186,25 +176,6 @@ public async Task<string> MsSqlAsync_WithParameterizedQuery(string tableName, bo | |
} | ||
} | ||
} | ||
|
||
var insertSql = string.Format(InsertPersonMsSql, tableName); | ||
var countSql = string.Format(CountPersonMsSql, tableName); | ||
var deleteSql = string.Format(DeletePersonMsSql, tableName); | ||
|
||
using (var command = new SqlCommand(insertSql, connection)) | ||
{ | ||
var insertCount = await command.ExecuteNonQueryAsync(); | ||
} | ||
|
||
using (var command = new SqlCommand(countSql, connection)) | ||
{ | ||
var teamMemberCount = await command.ExecuteScalarAsync(); | ||
} | ||
|
||
using (var command = new SqlCommand(deleteSql, connection)) | ||
{ | ||
var deleteCount = await command.ExecuteNonQueryAsync(); | ||
} | ||
} | ||
|
||
return string.Join(",", teamMembers); | ||
|
21 changes: 0 additions & 21 deletions
21
...grationTests/UnboundedApplications/BasicMvcCoreApplication/BasicMvcCoreApplication.csproj
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.