From acd9bd1bfe1f56c861f68ca6aab9b8f45fdd5a14 Mon Sep 17 00:00:00 2001 From: Rex Lorenzo Date: Wed, 13 May 2026 00:31:03 -0700 Subject: [PATCH 1/3] 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/3] 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}"); From e1282eadb25b9369534bb835fd1bf1899c3604e5 Mon Sep 17 00:00:00 2001 From: Rex Lorenzo Date: Wed, 13 May 2026 00:36:51 -0700 Subject: [PATCH 3/3] refactor: remove useless upcasts via record types and default(T) --- .../Controllers/CliniciansController.cs | 2 +- web/Areas/Effort/Services/VerificationService.cs | 2 +- web/Areas/Students/Services/PhotoExportService.cs | 10 ++++++---- web/EmailTemplates/Views/Shared/_EmailLayout.cshtml | 7 +++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/web/Areas/ClinicalScheduler/Controllers/CliniciansController.cs b/web/Areas/ClinicalScheduler/Controllers/CliniciansController.cs index a762b76f1..c64f13e01 100644 --- a/web/Areas/ClinicalScheduler/Controllers/CliniciansController.cs +++ b/web/Areas/ClinicalScheduler/Controllers/CliniciansController.cs @@ -201,7 +201,7 @@ public async Task GetClinicianSchedule(string mothraId, [FromQuer fullName = $"Clinician {mothraId}", firstName = "", lastName = "", - role = (string?)null + role = default(string) }; } else diff --git a/web/Areas/Effort/Services/VerificationService.cs b/web/Areas/Effort/Services/VerificationService.cs index a84eac6b5..21afaa320 100644 --- a/web/Areas/Effort/Services/VerificationService.cs +++ b/web/Areas/Effort/Services/VerificationService.cs @@ -232,7 +232,7 @@ await _auditService.LogRecordChangeAsync( // Set verification timestamp var verifiedDate = DateTime.Now; - var oldValues = new { EffortVerified = (DateTime?)null }; + var oldValues = new { EffortVerified = default(DateTime?) }; instructor.EffortVerified = verifiedDate; diff --git a/web/Areas/Students/Services/PhotoExportService.cs b/web/Areas/Students/Services/PhotoExportService.cs index cf55dbb5d..7f4ad256d 100644 --- a/web/Areas/Students/Services/PhotoExportService.cs +++ b/web/Areas/Students/Services/PhotoExportService.cs @@ -891,6 +891,8 @@ public PhotoExportService( /// Loads all student photos upfront in parallel for faster export generation. /// Returns a dictionary keyed by student MailId for quick lookup during rendering. /// + private sealed record PhotoLookupResult(string MailId, byte[]? PhotoBytes); + private async Task> BatchLoadPhotosAsync(List students) { var photoCache = new Dictionary(); @@ -903,22 +905,22 @@ private async Task> BatchLoadPhotosAsync(List @* UC Davis Weill Header Image *@ + @{ + var baseUrl = ViewBag.BaseUrl as string; + } - @if (!string.IsNullOrWhiteSpace((string?)ViewBag.BaseUrl)) + @if (!string.IsNullOrWhiteSpace(baseUrl)) { - UC Davis Weill School of Veterinary Medicine