Skip to content

Commit 4272ad6

Browse files
Test fix and logging improvement (#545)
1 parent 8fe0d26 commit 4272ad6

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

test/Common/TestUtils.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ public static string GetUniqueDBName(string namePrefix)
4343
/// <param name="commandText">The scalar T-SQL command.</param>
4444
/// <param name="catchException">Optional exception handling. Pass back 'true' to handle the
4545
/// exception, 'false' to throw. If Null is passed in then all exceptions are thrown.</param>
46+
/// <param name="message">Optional message to write when this query is executed. Defaults to writing the query commandText</param>
4647
/// <returns>The number of rows affected</returns>
4748
public static int ExecuteNonQuery(
4849
IDbConnection connection,
4950
string commandText,
50-
Predicate<Exception> catchException = null)
51+
Predicate<Exception> catchException = null,
52+
string message = null)
5153
{
5254
if (connection == null)
5355
{
@@ -57,6 +59,7 @@ public static int ExecuteNonQuery(
5759
{
5860
throw new ArgumentNullException(nameof(commandText));
5961
}
62+
message ??= $"Executing non-query {commandText}";
6063

6164
using (IDbCommand cmd = connection.CreateCommand())
6265
{
@@ -65,8 +68,8 @@ public static int ExecuteNonQuery(
6568

6669
cmd.CommandText = commandText;
6770
cmd.CommandType = CommandType.Text;
68-
cmd.CommandTimeout = 60000; // Increase from default 30s to prevent timeouts while connecting to Azure SQL DB
69-
Console.WriteLine($"Executing non-query {commandText}");
71+
cmd.CommandTimeout = 60; // Increase from default 30s to prevent timeouts while connecting to Azure SQL DB
72+
Console.WriteLine(message);
7073
return cmd.ExecuteNonQuery();
7174
}
7275
catch (Exception ex)

test/Integration/IntegrationTestBase.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@ protected async Task<HttpResponseMessage> SendPostRequest(string requestUri, str
354354
/// <summary>
355355
/// Executes a command against the current connection.
356356
/// </summary>
357-
protected void ExecuteNonQuery(string commandText)
357+
/// <param name="command">Command text to execute</param>
358+
/// <param name="message">Optional message to write when this query is executed. Defaults to writing the query commandText</param>
359+
protected void ExecuteNonQuery(string commandText, string message = null)
358360
{
359-
TestUtils.ExecuteNonQuery(this.Connection, commandText);
361+
TestUtils.ExecuteNonQuery(this.Connection, commandText, message: message);
360362
}
361363

362364
/// <summary>
@@ -460,7 +462,7 @@ protected void InsertProducts(Product[] products)
460462
queryBuilder.AppendLine($"INSERT INTO dbo.Products VALUES({p.ProductID}, '{p.Name}', {p.Cost});");
461463
}
462464

463-
this.ExecuteNonQuery(queryBuilder.ToString());
465+
this.ExecuteNonQuery(queryBuilder.ToString(), $"Inserting {products.Length} products");
464466
}
465467

466468
protected static Product[] GetProducts(int n, int cost)

test/Integration/SqlTriggerBindingIntegrationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ ALTER TABLE [dbo].[{tableName}]
530530

531531
protected void InsertProducts(int firstId, int lastId)
532532
{
533+
string message = $"Inserting products with ID from {firstId}-{lastId}";
533534
// Only 1000 items are allowed to be inserted into a single INSERT statement so if we have more than 1000 batch them up into separate statements
534535
var builder = new StringBuilder();
535536
do
@@ -538,7 +539,7 @@ protected void InsertProducts(int firstId, int lastId)
538539
builder.Append($"INSERT INTO [dbo].[Products] VALUES {string.Join(",\n", Enumerable.Range(firstId, batchCount).Select(id => $"({id}, 'Product {id}', {id * 100})"))}; ");
539540
firstId += batchCount;
540541
} while (firstId < lastId);
541-
this.ExecuteNonQuery(builder.ToString());
542+
this.ExecuteNonQuery(builder.ToString(), message);
542543
}
543544

544545
protected void UpdateProducts(int firstId, int lastId)

0 commit comments

Comments
 (0)