From acd9bd1bfe1f56c861f68ca6aab9b8f45fdd5a14 Mon Sep 17 00:00:00 2001 From: Rex Lorenzo Date: Wed, 13 May 2026 00:31:03 -0700 Subject: [PATCH 1/2] chore(tests): narrow catch(Exception) to specific types in test helpers --- test/CTS/AssessmentControllerTest.cs | 4 ++-- test/ClinicalScheduler/EmailNotificationTest.cs | 4 ++-- test/ClinicalScheduler/RotationServiceTest.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/CTS/AssessmentControllerTest.cs b/test/CTS/AssessmentControllerTest.cs index 289fcd92f..c9b412246 100644 --- a/test/CTS/AssessmentControllerTest.cs +++ b/test/CTS/AssessmentControllerTest.cs @@ -263,7 +263,7 @@ private static bool IsForbidResult(ActionResult a) Assert.True(result != null || forbidResult != null); } - catch (Exception) + catch (Xunit.Sdk.XunitException) { return false; } @@ -279,7 +279,7 @@ private static bool IsNotFoundResult(ActionResult a) var result = a.Result as NotFoundResult; Assert.Equal((int)HttpStatusCode.NotFound, result?.StatusCode); } - catch (Exception) + catch (Xunit.Sdk.XunitException) { return false; } diff --git a/test/ClinicalScheduler/EmailNotificationTest.cs b/test/ClinicalScheduler/EmailNotificationTest.cs index be00573e6..7993f8b8a 100644 --- a/test/ClinicalScheduler/EmailNotificationTest.cs +++ b/test/ClinicalScheduler/EmailNotificationTest.cs @@ -281,7 +281,7 @@ await _context.Persons.AddAsync(new Models.ClinicalScheduler.Person { result = await _service.RemoveInstructorScheduleAsync(savedSchedule.InstructorScheduleId); } - catch (Exception ex) + catch (Exception ex) when (ex is InvalidOperationException or Microsoft.EntityFrameworkCore.DbUpdateException or Microsoft.Data.SqlClient.SqlException or OperationCanceledException) { caughtException = ex; System.Console.WriteLine($"Exception caught: {ex.GetType().Name}: {ex.Message}"); @@ -463,7 +463,7 @@ await _context.Persons.AddAsync(new Models.ClinicalScheduler.Person { result = await _service.RemoveInstructorScheduleAsync(savedPrimarySchedule.InstructorScheduleId); } - catch (Exception ex) + catch (Exception ex) when (ex is InvalidOperationException or Microsoft.EntityFrameworkCore.DbUpdateException or Microsoft.Data.SqlClient.SqlException or OperationCanceledException) { caughtException = ex; System.Console.WriteLine($"Exception caught: {ex.GetType().Name}: {ex.Message}"); diff --git a/test/ClinicalScheduler/RotationServiceTest.cs b/test/ClinicalScheduler/RotationServiceTest.cs index 4c17e1580..895e4baac 100644 --- a/test/ClinicalScheduler/RotationServiceTest.cs +++ b/test/ClinicalScheduler/RotationServiceTest.cs @@ -95,7 +95,7 @@ private void SeedTestData() } _context.SaveChanges(); } - catch (Exception ex) + catch (Exception ex) when (ex is Microsoft.EntityFrameworkCore.DbUpdateException or InvalidOperationException) { // Log the exception and provide a clear error message for debugging Console.WriteLine($"Error seeding test data: {ex.Message}"); From 33c47fb383979476b27bd163ce15a008280c1205 Mon Sep 17 00:00:00 2001 From: Rex Lorenzo Date: Wed, 13 May 2026 02:19:09 -0700 Subject: [PATCH 2/2] chore(resharper): drop redundant namespace qualifiers in test catch filters Removed 'Microsoft.EntityFrameworkCore.' and 'Microsoft.Data.SqlClient.' prefixes from the catch when-filters added in codeql/15. Added 'using Microsoft.Data.SqlClient;' to EmailNotificationTest. --- test/ClinicalScheduler/EmailNotificationTest.cs | 5 +++-- test/ClinicalScheduler/RotationServiceTest.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/ClinicalScheduler/EmailNotificationTest.cs b/test/ClinicalScheduler/EmailNotificationTest.cs index 7993f8b8a..508242f0a 100644 --- a/test/ClinicalScheduler/EmailNotificationTest.cs +++ b/test/ClinicalScheduler/EmailNotificationTest.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using NSubstitute; using NSubstitute.ExceptionExtensions; @@ -281,7 +282,7 @@ await _context.Persons.AddAsync(new Models.ClinicalScheduler.Person { result = await _service.RemoveInstructorScheduleAsync(savedSchedule.InstructorScheduleId); } - catch (Exception ex) when (ex is InvalidOperationException or Microsoft.EntityFrameworkCore.DbUpdateException or Microsoft.Data.SqlClient.SqlException or OperationCanceledException) + catch (Exception ex) when (ex is InvalidOperationException or DbUpdateException or SqlException or OperationCanceledException) { caughtException = ex; System.Console.WriteLine($"Exception caught: {ex.GetType().Name}: {ex.Message}"); @@ -463,7 +464,7 @@ await _context.Persons.AddAsync(new Models.ClinicalScheduler.Person { result = await _service.RemoveInstructorScheduleAsync(savedPrimarySchedule.InstructorScheduleId); } - catch (Exception ex) when (ex is InvalidOperationException or Microsoft.EntityFrameworkCore.DbUpdateException or Microsoft.Data.SqlClient.SqlException or OperationCanceledException) + catch (Exception ex) when (ex is InvalidOperationException or DbUpdateException or SqlException or OperationCanceledException) { caughtException = ex; System.Console.WriteLine($"Exception caught: {ex.GetType().Name}: {ex.Message}"); diff --git a/test/ClinicalScheduler/RotationServiceTest.cs b/test/ClinicalScheduler/RotationServiceTest.cs index 895e4baac..905415e8f 100644 --- a/test/ClinicalScheduler/RotationServiceTest.cs +++ b/test/ClinicalScheduler/RotationServiceTest.cs @@ -95,7 +95,7 @@ private void SeedTestData() } _context.SaveChanges(); } - catch (Exception ex) when (ex is Microsoft.EntityFrameworkCore.DbUpdateException or InvalidOperationException) + catch (Exception ex) when (ex is DbUpdateException or InvalidOperationException) { // Log the exception and provide a clear error message for debugging Console.WriteLine($"Error seeding test data: {ex.Message}");