From 727ecb1a6da2cee90fac1499790ac270d4e2aa25 Mon Sep 17 00:00:00 2001 From: BrianMaki Date: Thu, 2 Jan 2025 10:00:29 -0800 Subject: [PATCH] Fix sonar warnings for Admin for AB#16872. --- .../Communications/BroadcastDialog.razor.cs | 32 +++++------- .../Delegation/DelegateTable.razor.cs | 10 ++-- .../AddressConfirmationDialog.razor.cs | 46 ++++++++++------- .../Client/Pages/AgentAccessPage.razor.cs | 16 +++--- .../Client/Pages/BetaAccessPage.razor.cs | 16 +++--- .../Admin/Client/Pages/DashboardPage.razor.cs | 31 +++++------- .../Client/Pages/DelegationPage.razor.cs | 16 +++--- Apps/Admin/Client/Pages/SupportPage.razor.cs | 46 ++++++++++------- .../Client/Services/DateConversionService.cs | 18 +++---- Apps/Admin/Client/Utils/BreakpointUtility.cs | 2 + Apps/Admin/Client/Utils/FormattingUtility.cs | 7 +++ Apps/Admin/Client/Utils/StoreUtility.cs | 49 +++++++++---------- .../Server/Controllers/SupportController.cs | 2 + .../RestImmunizationAdminDelegate.cs | 2 + .../Delegates/RestVaccineStatusDelegate.cs | 2 + .../Server/MapProfiles/BetaFeatureProfile.cs | 2 + .../Server/Services/AdminReportService.cs | 2 +- .../Server/Services/CovidSupportService.cs | 12 ++--- .../Server/Services/DelegationService.cs | 10 ++-- .../Server/Services/InactiveUserService.cs | 10 ++-- Apps/Admin/Server/Services/SupportService.cs | 27 +++++----- .../Server/Services/UserFeedbackService.cs | 2 +- .../RestImmunizationAdminDelegateTests.cs | 3 +- .../RestVaccineStatusDelegateTests.cs | 3 +- .../Tests/Services/AdminReportServiceTests.cs | 6 +-- .../Tests/Services/AgentAccessServiceTests.cs | 4 +- .../Tests/Services/BetaFeatureServiceTests.cs | 6 +-- .../Services/CommunicationServiceTests.cs | 3 +- .../Services/ConfigurationServiceTests.cs | 3 +- .../Services/CovidSupportServiceTests.cs | 5 +- .../Tests/Services/CsvExportServiceTests.cs | 15 +++--- .../Tests/Services/DashboardServiceTests.cs | 32 ++++++------ .../Tests/Services/DelegationServiceTests.cs | 4 +- .../Services/InactiveUserServiceTests.cs | 3 +- .../Tests/Services/SupportServiceTests.cs | 8 +-- .../Services/UserFeedbackServiceTests.cs | 8 +-- 36 files changed, 224 insertions(+), 239 deletions(-) diff --git a/Apps/Admin/Client/Components/Communications/BroadcastDialog.razor.cs b/Apps/Admin/Client/Components/Communications/BroadcastDialog.razor.cs index c622c4b74c..2cc6b5e7fb 100644 --- a/Apps/Admin/Client/Components/Communications/BroadcastDialog.razor.cs +++ b/Apps/Admin/Client/Components/Communications/BroadcastDialog.razor.cs @@ -17,6 +17,7 @@ namespace HealthGateway.Admin.Client.Components.Communications; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using Fluxor; using Fluxor.Blazor.Web.Components; @@ -47,21 +48,18 @@ public partial class BroadcastDialog : FluxorComponent BroadcastActionType.ExternalLink, ]; + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] private Func ValidateActionUrl => urlString => { - switch (this.Broadcast.ActionType) + return this.Broadcast.ActionType switch { - case BroadcastActionType.InternalLink: - case BroadcastActionType.ExternalLink: - return urlString.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase) - && Uri.TryCreate(this.ActionUrlString, UriKind.Absolute, out Uri? _) - ? null - : "URL is invalid"; - case BroadcastActionType.None: - default: - return urlString.Length == 0 ? null : "Selected Action Type does not support Action URL"; - } + BroadcastActionType.InternalLink or BroadcastActionType.ExternalLink => urlString.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase) + && Uri.TryCreate(this.ActionUrlString, UriKind.Absolute, out Uri? _) + ? null + : "URL is invalid", + _ => urlString.Length == 0 ? null : "Selected Action Type does not support Action URL", + }; }; [CascadingParameter] @@ -149,14 +147,10 @@ private void RetrieveFormValues() ? null : (this.ExpiryDate.Value + this.ExpiryTime.Value).ToUniversalTime(); - if (this.ActionUrlString.Length > 0 && Uri.TryCreate(this.ActionUrlString, UriKind.Absolute, out Uri? result)) - { - this.Broadcast.ActionUrl = result; - } - else - { - this.Broadcast.ActionUrl = null; - } + this.Broadcast.ActionUrl = this.ActionUrlString.Length > 0 && + Uri.TryCreate(this.ActionUrlString, UriKind.Absolute, out Uri? result) + ? result + : null; } private void HandleClickCancel() diff --git a/Apps/Admin/Client/Components/Delegation/DelegateTable.razor.cs b/Apps/Admin/Client/Components/Delegation/DelegateTable.razor.cs index 9ffb916f0b..e0470b3c9e 100644 --- a/Apps/Admin/Client/Components/Delegation/DelegateTable.razor.cs +++ b/Apps/Admin/Client/Components/Delegation/DelegateTable.razor.cs @@ -17,6 +17,7 @@ namespace HealthGateway.Admin.Client.Components.Delegation { using System; using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Linq; using Fluxor; using Fluxor.Blazor.Web.Components; @@ -49,6 +50,7 @@ public partial class DelegateTable : FluxorComponent private IEnumerable Rows => this.Data.Select(d => new DelegateRow(d)); + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] private static Color GetStatusColor(DelegationStatus status) { return status switch @@ -73,11 +75,9 @@ public DelegateRow(ExtendedDelegateInfo model) this.DateOfBirth = model.Birthdate; this.PersonalHealthNumber = model.PersonalHealthNumber; this.Address = AddressUtility.GetAddressAsSingleLine(model.PhysicalAddress ?? model.PostalAddress); - this.DelegationStatus = model.DelegationStatus switch - { - DelegationStatus.Unknown => DelegationStatus.Allowed, - _ => model.DelegationStatus, - }; + this.DelegationStatus = model.DelegationStatus == DelegationStatus.Unknown + ? DelegationStatus.Allowed + : model.DelegationStatus; this.ToBeRemoved = model.StagedDelegationStatus == DelegationStatus.Disallowed; } diff --git a/Apps/Admin/Client/Components/Support/AddressConfirmationDialog.razor.cs b/Apps/Admin/Client/Components/Support/AddressConfirmationDialog.razor.cs index c52b07f695..eb1cd0309a 100644 --- a/Apps/Admin/Client/Components/Support/AddressConfirmationDialog.razor.cs +++ b/Apps/Admin/Client/Components/Support/AddressConfirmationDialog.razor.cs @@ -109,6 +109,7 @@ public partial class AddressConfirmationDialog : F private IMask? PostalCodeMask { get; set; } + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] private string Country { get => this.country; @@ -188,6 +189,16 @@ private static string GetCountryNameFromInput(string input) return string.Empty; } + private static string? ValidateCanadianPostalCode(string postalCode) + { + return !AddressUtility.PostalCodeRegex().IsMatch(postalCode) ? "Incomplete postal code" : null; + } + + private static string? ValidateUsPostalCode(string postalCode) + { + return !AddressUtility.ZipCodeRegex().IsMatch(postalCode) ? "Incomplete zip code" : null; + } + private void PopulateInputs(Address address) { this.AddressLines = string.Join(Environment.NewLine, address.StreetLines); @@ -211,14 +222,16 @@ private void PopulateInputs(Address address) private string GetCountryToOutput() { - if (this.SelectedCountryCode == CountryCode.CA && this.OutputCanadaAsEmptyString) - { - return string.Empty; - } + string? canadaOutput = this.SelectedCountryCode == CountryCode.CA && this.OutputCanadaAsEmptyString + ? string.Empty + : null; - return this.OutputCountryCodeFormat ? this.SelectedCountryCode.ToString() : AddressUtility.GetCountryName(this.SelectedCountryCode); + return canadaOutput ?? (this.OutputCountryCodeFormat + ? this.SelectedCountryCode.ToString() + : AddressUtility.GetCountryName(this.SelectedCountryCode)); } + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] private Address GetAddressModel() { return new() @@ -245,22 +258,17 @@ private void HandleCountryChanged(string value) this.OtherState = string.Empty; } + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] private string? ValidatePostalCode(string postalCode) { - if (string.IsNullOrWhiteSpace(postalCode)) - { - return "Required"; - } - - switch (this.SelectedCountryCode) - { - case CountryCode.CA: - return !AddressUtility.PostalCodeRegex().IsMatch(postalCode) ? "Incomplete postal code" : null; - case CountryCode.US: - return !AddressUtility.ZipCodeRegex().IsMatch(postalCode) ? "Incomplete zip code" : null; - default: - return null; - } + return string.IsNullOrWhiteSpace(postalCode) + ? "Required" + : this.SelectedCountryCode switch + { + CountryCode.CA => ValidateCanadianPostalCode(postalCode), + CountryCode.US => ValidateUsPostalCode(postalCode), + _ => null, + }; } private void HandleActionSuccess(TSuccessAction successAction) diff --git a/Apps/Admin/Client/Pages/AgentAccessPage.razor.cs b/Apps/Admin/Client/Pages/AgentAccessPage.razor.cs index 43f4c2ff30..83bab27814 100644 --- a/Apps/Admin/Client/Pages/AgentAccessPage.razor.cs +++ b/Apps/Admin/Client/Pages/AgentAccessPage.razor.cs @@ -40,17 +40,13 @@ public partial class AgentAccessPage : FluxorComponent private static Func ValidateQueryParameter => parameter => { - if (string.IsNullOrWhiteSpace(parameter)) - { - return "Search parameter is required"; - } - - if (StringManipulator.StripWhitespace(parameter).Length < 3) - { - return "Query must contain at least 3 characters"; - } + string? lengthValidationResult = StringManipulator.StripWhitespace(parameter).Length < 3 + ? "Query must contain at least 3 characters" + : null; - return null; + return string.IsNullOrWhiteSpace(parameter) + ? "Search parameter is required" + : lengthValidationResult; }; [Inject] diff --git a/Apps/Admin/Client/Pages/BetaAccessPage.razor.cs b/Apps/Admin/Client/Pages/BetaAccessPage.razor.cs index 740b70a41c..d0078745d3 100644 --- a/Apps/Admin/Client/Pages/BetaAccessPage.razor.cs +++ b/Apps/Admin/Client/Pages/BetaAccessPage.razor.cs @@ -36,17 +36,13 @@ public partial class BetaAccessPage : FluxorComponent { private static Func ValidateQueryParameter => parameter => { - if (string.IsNullOrWhiteSpace(parameter)) - { - return "Email is required"; - } - - if (!NaiveEmailValidator.IsValid(StringManipulator.StripWhitespace(parameter))) - { - return "Invalid email format"; - } + string? emailValidationResult = !NaiveEmailValidator.IsValid(StringManipulator.StripWhitespace(parameter)) + ? "Invalid email format" + : null; - return null; + return string.IsNullOrWhiteSpace(parameter) + ? "Email is required" + : emailValidationResult; }; [Inject] diff --git a/Apps/Admin/Client/Pages/DashboardPage.razor.cs b/Apps/Admin/Client/Pages/DashboardPage.razor.cs index ca22ead45c..e36cedc22e 100644 --- a/Apps/Admin/Client/Pages/DashboardPage.razor.cs +++ b/Apps/Admin/Client/Pages/DashboardPage.razor.cs @@ -134,24 +134,19 @@ private int UniqueDays } } - private IEnumerable TableData - { - get - { - return this.DailyUsageCounts.UserRegistrations.Select(x => new DailyDataRow { Date = x.Key, UserRegistrations = x.Value }) - .Concat(this.DailyUsageCounts.UserLogins.Select(x => new DailyDataRow { Date = x.Key, UserLogins = x.Value })) - .Concat(this.DailyUsageCounts.DependentRegistrations.Select(x => new DailyDataRow { Date = x.Key, DependentRegistrations = x.Value })) - .GroupBy(x => x.Date) - .Select( - g => new DailyDataRow - { - Date = g.Key, - UserRegistrations = g.Sum(x => x.UserRegistrations), - UserLogins = g.Sum(x => x.UserLogins), - DependentRegistrations = g.Sum(x => x.DependentRegistrations), - }); - } - } + private IEnumerable TableData => + this.DailyUsageCounts.UserRegistrations.Select(x => new DailyDataRow { Date = x.Key, UserRegistrations = x.Value }) + .Concat(this.DailyUsageCounts.UserLogins.Select(x => new DailyDataRow { Date = x.Key, UserLogins = x.Value })) + .Concat(this.DailyUsageCounts.DependentRegistrations.Select(x => new DailyDataRow { Date = x.Key, DependentRegistrations = x.Value })) + .GroupBy(x => x.Date) + .Select( + g => new DailyDataRow + { + Date = g.Key, + UserRegistrations = g.Sum(x => x.UserRegistrations), + UserLogins = g.Sum(x => x.UserLogins), + DependentRegistrations = g.Sum(x => x.DependentRegistrations), + }); /// protected override void OnInitialized() diff --git a/Apps/Admin/Client/Pages/DelegationPage.razor.cs b/Apps/Admin/Client/Pages/DelegationPage.razor.cs index f9121eee37..c0218c981d 100644 --- a/Apps/Admin/Client/Pages/DelegationPage.razor.cs +++ b/Apps/Admin/Client/Pages/DelegationPage.razor.cs @@ -43,17 +43,13 @@ public partial class DelegationPage : FluxorComponent private static Func ValidateQueryParameter => parameter => { - if (string.IsNullOrWhiteSpace(parameter)) - { - return "PHN is required"; - } - - if (!PhnValidator.Validate(StringManipulator.StripWhitespace(parameter)).IsValid) - { - return "Invalid PHN"; - } + string? phnValidationResult = !PhnValidator.Validate(StringManipulator.StripWhitespace(parameter)).IsValid + ? "Invalid PHN" + : null; - return null; + return string.IsNullOrWhiteSpace(parameter) + ? "PHN is required" + : phnValidationResult; }; [Inject] diff --git a/Apps/Admin/Client/Pages/SupportPage.razor.cs b/Apps/Admin/Client/Pages/SupportPage.razor.cs index 16f41a755c..591c9a52be 100644 --- a/Apps/Admin/Client/Pages/SupportPage.razor.cs +++ b/Apps/Admin/Client/Pages/SupportPage.razor.cs @@ -18,6 +18,7 @@ namespace HealthGateway.Admin.Client.Pages using System; using System.Collections.Generic; using System.Collections.Immutable; + using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading.Tasks; using Fluxor; @@ -109,24 +110,8 @@ private PatientQueryType SelectedQueryType private Func ValidateQueryParameter => parameter => { - if (string.IsNullOrWhiteSpace(parameter)) - { - return "Search parameter is required"; - } - - if (this.PhnOrDependentSelected && !PhnValidator.Validate(StringManipulator.StripWhitespace(parameter)).IsValid) - { - return "Invalid PHN"; - } - - return this.SelectedQueryType switch - { - PatientQueryType.Email or PatientQueryType.Sms when StringManipulator.StripWhitespace(parameter).Length < 5 - => "Email/SMS must be minimum 5 characters", - PatientQueryType.Sms when !StringManipulator.IsPositiveNumeric(parameter) - => "SMS must contain digits only", - _ => null, - }; + string? result = ValidateParameterInput(parameter) ?? ValidatePhn(parameter, this.PhnOrDependentSelected); + return result ?? ValidateQueryType(parameter, this.SelectedQueryType); }; private AuthenticationState? AuthenticationState { get; set; } @@ -167,6 +152,31 @@ protected override async ValueTask DisposeAsyncCore(bool disposing) await base.DisposeAsyncCore(disposing); } + private static string? ValidateParameterInput(string parameter) + { + return string.IsNullOrWhiteSpace(parameter) ? "Search parameter is required" : null; + } + + private static string? ValidatePhn(string parameter, bool phnOrDependentSelected) + { + return phnOrDependentSelected && !PhnValidator.Validate(StringManipulator.StripWhitespace(parameter)).IsValid + ? "Invalid PHN" + : null; + } + + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] + private static string? ValidateQueryType(string parameter, PatientQueryType selectedQueryType) + { + return selectedQueryType switch + { + PatientQueryType.Email or PatientQueryType.Sms when StringManipulator.StripWhitespace(parameter).Length < 5 + => "Email/SMS must be minimum 5 characters", + PatientQueryType.Sms when !StringManipulator.IsPositiveNumeric(parameter) + => "SMS must contain digits only", + _ => null, + }; + } + private void Clear() { this.Dispatcher.Dispatch(new PatientSupportActions.ResetStateAction()); diff --git a/Apps/Admin/Client/Services/DateConversionService.cs b/Apps/Admin/Client/Services/DateConversionService.cs index e4079a4986..8ac1bec372 100644 --- a/Apps/Admin/Client/Services/DateConversionService.cs +++ b/Apps/Admin/Client/Services/DateConversionService.cs @@ -32,17 +32,8 @@ public DateTime ConvertFromUtc(DateTime utcDateTime) /// public DateTime? ConvertFromUtc(DateTime? utcDateTime, bool returnNowIfNull = false) { - if (utcDateTime != null) - { - return this.ConvertFromUtc(utcDateTime.Value); - } - - if (returnNowIfNull) - { - return this.ConvertFromUtc(DateTime.UtcNow); - } - - return null; + DateTime? dateTimeToConvert = GetDateTimeToConvert(utcDateTime, returnNowIfNull); + return dateTimeToConvert.HasValue ? this.ConvertFromUtc(dateTimeToConvert.Value) : null; } /// @@ -50,5 +41,10 @@ public string ConvertToShortFormatFromUtc(DateTime? utcDateTime, string fallback { return utcDateTime == null ? fallbackString : DateFormatter.ToShortDateAndTime(this.ConvertFromUtc(utcDateTime.Value)); } + + private static DateTime? GetDateTimeToConvert(DateTime? utcDateTime, bool returnNowIfNull) + { + return utcDateTime ?? (returnNowIfNull ? DateTime.UtcNow : null); + } } } diff --git a/Apps/Admin/Client/Utils/BreakpointUtility.cs b/Apps/Admin/Client/Utils/BreakpointUtility.cs index a5627a2728..b09cceea01 100644 --- a/Apps/Admin/Client/Utils/BreakpointUtility.cs +++ b/Apps/Admin/Client/Utils/BreakpointUtility.cs @@ -15,6 +15,7 @@ // ------------------------------------------------------------------------- namespace HealthGateway.Admin.Client.Utils { + using System.Diagnostics.CodeAnalysis; using MudBlazor; /// @@ -59,6 +60,7 @@ public static class BreakpointUtility /// A string containing the override code for the breakpoint or null if the breakpoint has no associated override /// code. /// + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string? GetOverrideCode(this Breakpoint breakpoint) { return breakpoint switch diff --git a/Apps/Admin/Client/Utils/FormattingUtility.cs b/Apps/Admin/Client/Utils/FormattingUtility.cs index a9a322a351..0a03ef852d 100644 --- a/Apps/Admin/Client/Utils/FormattingUtility.cs +++ b/Apps/Admin/Client/Utils/FormattingUtility.cs @@ -15,6 +15,7 @@ // ------------------------------------------------------------------------- namespace HealthGateway.Admin.Client.Utils { + using System.Diagnostics.CodeAnalysis; using HealthGateway.Admin.Common.Constants; using HealthGateway.Common.Data.Constants; using HealthGateway.Common.Data.Models; @@ -55,6 +56,7 @@ public static string FormatBroadcastEnabled(bool enabled) /// /// The communication status to format. /// A string formatted for display. + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string FormatCommunicationStatus(CommunicationStatus status) { return status switch @@ -69,6 +71,7 @@ public static string FormatCommunicationStatus(CommunicationStatus status) /// /// The communication type to format. /// A string formatted for display. + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string FormatCommunicationType(CommunicationType? communicationType) { return communicationType switch @@ -85,6 +88,7 @@ public static string FormatCommunicationType(CommunicationType? communicationTyp /// /// The data source to format. /// A string formatted for display. + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string FormatDataSource(DataSource dataSource) { return dataSource switch @@ -110,6 +114,7 @@ public static string FormatDataSource(DataSource dataSource) /// /// The identity provider to format. /// A string formatted for display. + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string FormatKeycloakIdentityProvider(KeycloakIdentityProvider identityProvider) { return identityProvider switch @@ -125,6 +130,7 @@ public static string FormatKeycloakIdentityProvider(KeycloakIdentityProvider ide /// /// The patient status to format. /// A string formatted for display. + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string FormatPatientStatus(PatientStatus status) { return status switch @@ -141,6 +147,7 @@ public static string FormatPatientStatus(PatientStatus status) /// /// The query type to format. /// A string formatted for display. + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public static string FormatPatientQueryType(PatientQueryType queryType) { return queryType switch diff --git a/Apps/Admin/Client/Utils/StoreUtility.cs b/Apps/Admin/Client/Utils/StoreUtility.cs index f5f37c95f1..79fa13c6fb 100644 --- a/Apps/Admin/Client/Utils/StoreUtility.cs +++ b/Apps/Admin/Client/Utils/StoreUtility.cs @@ -48,32 +48,7 @@ public static RequestError FormatRequestError(RequestResultError? resultError) /// The generated . public static RequestError FormatRequestError(Exception? exception, RequestResultError? resultError = null) { - if (resultError is not null) - { - return new() - { - Message = resultError.ResultMessage, - Details = new() - { - { "errorCode", resultError.ErrorCode }, - { "traceId", resultError.TraceId }, - { "actionCode", resultError.ActionCodeValue ?? string.Empty }, - }, - }; - } - - if (exception is not null) - { - return new() - { - Message = exception.Message, - }; - } - - return new() - { - Message = "Unknown error", - }; + return resultError is not null ? CreateRequestError(resultError) : CreateRequestError(exception); } /// @@ -100,5 +75,27 @@ public static async Task LoadPatientSupportAction( await SessionUtility.SetSessionStorageItem(jsRuntime, SessionUtility.SupportQueryType, patientQueryType.ToString()); await SessionUtility.SetSessionStorageItem(jsRuntime, SessionUtility.SupportQueryString, patientQueryString); } + + private static RequestError CreateRequestError(RequestResultError resultError) + { + return new() + { + Message = resultError.ResultMessage, + Details = new() + { + { "errorCode", resultError.ErrorCode }, + { "traceId", resultError.TraceId }, + { "actionCode", resultError.ActionCodeValue ?? string.Empty }, + }, + }; + } + + private static RequestError CreateRequestError(Exception? exception) + { + return new() + { + Message = exception?.Message ?? "Unknown error", + }; + } } } diff --git a/Apps/Admin/Server/Controllers/SupportController.cs b/Apps/Admin/Server/Controllers/SupportController.cs index 72ddff20e3..6507f105c8 100644 --- a/Apps/Admin/Server/Controllers/SupportController.cs +++ b/Apps/Admin/Server/Controllers/SupportController.cs @@ -16,6 +16,7 @@ namespace HealthGateway.Admin.Server.Controllers { using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Security.Claims; using System.Threading; using System.Threading.Tasks; @@ -41,6 +42,7 @@ namespace HealthGateway.Admin.Server.Controllers [Route("v{version:apiVersion}/api/[controller]")] [Produces("application/json")] [Authorize(Roles = "AdminUser,AdminReviewer,SupportUser")] + [SuppressMessage("Major Code Smell", "S6960:This controller has multiple responsibilities and could be split into 2 smaller controllers", Justification = "Team decision")] public class SupportController(ICovidSupportService covidSupportService, ISupportService supportService) : ControllerBase { /// diff --git a/Apps/Admin/Server/Delegates/RestImmunizationAdminDelegate.cs b/Apps/Admin/Server/Delegates/RestImmunizationAdminDelegate.cs index a730eed8bf..8f8571b470 100644 --- a/Apps/Admin/Server/Delegates/RestImmunizationAdminDelegate.cs +++ b/Apps/Admin/Server/Delegates/RestImmunizationAdminDelegate.cs @@ -17,6 +17,7 @@ namespace HealthGateway.Admin.Server.Delegates { using System; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -47,6 +48,7 @@ public class RestImmunizationAdminDelegate( private static ActivitySource ActivitySource { get; } = new(typeof(RestImmunizationAdminDelegate).FullName); /// + [SuppressMessage("Style", "IDE0046:Simplify 'if' statement", Justification = "Team decision")] public async Task GetVaccineDetailsWithRetriesAsync(string phn, string accessToken, bool refresh = false, CancellationToken ct = default) { using Activity? activity = ActivitySource.StartActivity(); diff --git a/Apps/Admin/Server/Delegates/RestVaccineStatusDelegate.cs b/Apps/Admin/Server/Delegates/RestVaccineStatusDelegate.cs index fe9bce50c4..1fc9d4699f 100644 --- a/Apps/Admin/Server/Delegates/RestVaccineStatusDelegate.cs +++ b/Apps/Admin/Server/Delegates/RestVaccineStatusDelegate.cs @@ -17,6 +17,7 @@ namespace HealthGateway.Admin.Server.Delegates { using System; using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using HealthGateway.Admin.Server.Api; @@ -42,6 +43,7 @@ public class RestVaccineStatusDelegate( private static ActivitySource ActivitySource { get; } = new(typeof(RestVaccineStatusDelegate).FullName); /// + [SuppressMessage("Style", "IDE0046:Simplify 'if' statement", Justification = "Team decision")] public async Task> GetVaccineStatusWithRetriesAsync(string phn, DateTime dateOfBirth, string accessToken, CancellationToken ct = default) { using Activity? activity = ActivitySource.StartActivity(); diff --git a/Apps/Admin/Server/MapProfiles/BetaFeatureProfile.cs b/Apps/Admin/Server/MapProfiles/BetaFeatureProfile.cs index 7846c95273..495a23902a 100644 --- a/Apps/Admin/Server/MapProfiles/BetaFeatureProfile.cs +++ b/Apps/Admin/Server/MapProfiles/BetaFeatureProfile.cs @@ -16,12 +16,14 @@ namespace HealthGateway.Admin.Server.MapProfiles { using System; + using System.Diagnostics.CodeAnalysis; using AutoMapper; using HealthGateway.Admin.Common.Constants; /// /// An AutoMapper profile class which defines mapping between DB and UI Models. /// + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public class BetaFeatureProfile : Profile { /// diff --git a/Apps/Admin/Server/Services/AdminReportService.cs b/Apps/Admin/Server/Services/AdminReportService.cs index bfb65f6fb2..5557b89437 100644 --- a/Apps/Admin/Server/Services/AdminReportService.cs +++ b/Apps/Admin/Server/Services/AdminReportService.cs @@ -67,7 +67,7 @@ public async Task> GetBlockedAccessReportAsync( IList records = await blockedAccessDelegate.GetAllAsync(ct); return records .Where(r => r.DataSources.Count > 0) - .Select(r => new BlockedAccessRecord(r.Hdid, r.DataSources.ToList())); + .Select(r => new BlockedAccessRecord(r.Hdid, [.. r.DataSources])); } } } diff --git a/Apps/Admin/Server/Services/CovidSupportService.cs b/Apps/Admin/Server/Services/CovidSupportService.cs index af1d612b26..8805488698 100644 --- a/Apps/Admin/Server/Services/CovidSupportService.cs +++ b/Apps/Admin/Server/Services/CovidSupportService.cs @@ -16,6 +16,7 @@ namespace HealthGateway.Admin.Server.Services { using System; + using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using HealthGateway.AccountDataAccess.Patient; @@ -89,15 +90,10 @@ private async Task GetPatientAsync(string phn, CancellationToken c private async Task GetVaccineStatusResultAsync(string phn, DateTime birthdate, string accessToken, CancellationToken ct) { PhsaResult phsaResult = await vaccineStatusDelegate.GetVaccineStatusWithRetriesAsync(phn, birthdate, accessToken, ct); - - if (phsaResult.Result == null) - { - throw new NotFoundException(ErrorMessages.CannotGetVaccineStatus); - } - - return phsaResult.Result; + return phsaResult.Result ?? throw new NotFoundException(ErrorMessages.CannotGetVaccineStatus); } + [SuppressMessage("Style", "IDE0046:Simplify 'if' statement", Justification = "Team decision")] private VaccinationStatus GetVaccinationStatus(VaccineStatusResult result) { logger.LogDebug("Vaccination Status Indicator: {VaccinationStatusIndicator}", result.StatusIndicator); @@ -118,6 +114,7 @@ VaccineState.NotFound or VaccineState.DataMismatch or VaccineState.Threshold or }; } + [SuppressMessage("Style", "IDE0046:Simplify 'if' statement", Justification = "Team decision")] private async Task GetVaccineProofAsync(VaccinationStatus vaccinationStatus, string qrCode, CancellationToken ct) { VaccineProofRequest request = new() @@ -127,6 +124,7 @@ private async Task GetVaccineProofAsync(VaccinationStatus }; RequestResult vaccineProof = await vaccineProofDelegate.GenerateAsync(this.vaccineCardConfig.PrintTemplate, request, ct); + if (vaccineProof.ResultStatus != ResultType.Success || vaccineProof.ResourcePayload == null) { throw new NotFoundException(vaccineProof.ResultError?.ResultMessage ?? ErrorMessages.CannotGetVaccineProof); diff --git a/Apps/Admin/Server/Services/DelegationService.cs b/Apps/Admin/Server/Services/DelegationService.cs index 6fecc38713..510c480b7b 100644 --- a/Apps/Admin/Server/Services/DelegationService.cs +++ b/Apps/Admin/Server/Services/DelegationService.cs @@ -17,6 +17,7 @@ namespace HealthGateway.Admin.Server.Services { using System; using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -211,13 +212,7 @@ public async Task ProtectDependentAsync(string dependentHdid, IEnum public async Task UnprotectDependentAsync(string dependentHdid, string reason, CancellationToken ct = default) { string authenticatedUserId = authenticationDelegate.FetchAuthenticatedUserId() ?? UserId.DefaultUser; - Dependent? dependent = await delegationDelegate.GetDependentAsync(dependentHdid, true, ct); - - if (dependent == null) - { - throw new NotFoundException($"Dependent not found for hdid: {dependentHdid}"); - } - + Dependent dependent = await delegationDelegate.GetDependentAsync(dependentHdid, true, ct) ?? throw new NotFoundException($"Dependent not found for hdid: {dependentHdid}"); dependent.Protected = false; dependent.UpdatedBy = authenticatedUserId; dependent.AllowedDelegations = []; @@ -253,6 +248,7 @@ public async Task UnprotectDependentAsync(string dependentHdid, str return mappingService.MapToAgentAction(agentAudit); } + [SuppressMessage("Style", "IDE0010:Populate switch", Justification = "Team decision")] private static void ValidatePatientResult(RequestResult patientResult) { switch (patientResult) diff --git a/Apps/Admin/Server/Services/InactiveUserService.cs b/Apps/Admin/Server/Services/InactiveUserService.cs index 7b8d872fe2..3e4e5e6cc6 100644 --- a/Apps/Admin/Server/Services/InactiveUserService.cs +++ b/Apps/Admin/Server/Services/InactiveUserService.cs @@ -158,19 +158,17 @@ private void PopulateUserDetails(List inactiveUsers, List< private void AddInactiveUser( List inactiveUsers, IEnumerable activeUserProfiles, - ICollection identityAccessUsers, + List identityAccessUsers, IdentityAccessRole role) { this.logger.LogDebug("Keycloak {Role} count: {Count}...", role, identityAccessUsers.Count); // Filter identities from keycloak where inactive (database) user's username does not match keycloak user's username // and active (database) user's username does not match keycloak users username - IEnumerable adminUserProfiles = identityAccessUsers - .Where(x1 => inactiveUsers.TrueForAll(x2 => x1.Username != x2.Username) && activeUserProfiles.All(x2 => x1.Username != x2.Username)) - .Select(user => this.mappingService.MapToAdminUserProfileView(user)); - - foreach (AdminUserProfileView adminUserProfile in adminUserProfiles) + foreach (UserRepresentation user in identityAccessUsers + .Where(x1 => inactiveUsers.TrueForAll(x2 => x1.Username != x2.Username) && activeUserProfiles.All(x2 => x1.Username != x2.Username))) { + AdminUserProfileView adminUserProfile = this.mappingService.MapToAdminUserProfileView(user); adminUserProfile.RealmRoles = role.ToString(); inactiveUsers.Add(adminUserProfile); } diff --git a/Apps/Admin/Server/Services/SupportService.cs b/Apps/Admin/Server/Services/SupportService.cs index 5116da1ef7..a3532eb19b 100644 --- a/Apps/Admin/Server/Services/SupportService.cs +++ b/Apps/Admin/Server/Services/SupportService.cs @@ -17,6 +17,7 @@ namespace HealthGateway.Admin.Server.Services { using System; using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using System.Threading; @@ -72,16 +73,11 @@ public async Task GetPatientSupportDetailsAsync( PatientSupportDetailsQuery query, CancellationToken ct = default) { - PatientModel patient; - - if (query.QueryType == ClientRegistryType.Hdid) - { - patient = await this.GetPatientAsync(new(Hdid: query.QueryParameter, Source: PatientDetailSource.All, UseCache: false), ct); - } - else - { - patient = await this.GetPatientAsync(new(query.QueryParameter, Source: PatientDetailSource.Empi, UseCache: false), ct); - } + PatientModel patient = await this.GetPatientAsync( + query.QueryType == ClientRegistryType.Hdid + ? new(Hdid: query.QueryParameter, Source: PatientDetailSource.All, UseCache: false) + : new(query.QueryParameter, Source: PatientDetailSource.Empi, UseCache: false), + ct); Task? getVaccineDetails = query.IncludeCovidDetails ? this.GetVaccineDetailsAsync(patient, query.RefreshVaccineDetails, ct) : null; @@ -109,6 +105,7 @@ public async Task GetPatientSupportDetailsAsync( } /// + [SuppressMessage("Style", "IDE0072:Populate switch", Justification = "Team decision")] public async Task> GetPatientsAsync(PatientQueryType queryType, string queryString, CancellationToken ct = default) { if (queryType is PatientQueryType.Hdid or PatientQueryType.Phn) @@ -206,6 +203,7 @@ private async Task> GetAllDependentInfo return dependentInfo; } + [SuppressMessage("Style", "IDE0046:'if' statement can be simplified", Justification = "Team decision")] private async Task GetVaccineDetailsAsync(PatientModel patient, bool refresh, CancellationToken ct) { if (string.IsNullOrEmpty(patient.Phn) || patient.Birthdate == DateTime.MinValue) @@ -233,12 +231,9 @@ private async Task GetAccessTokenAsync(CancellationToken ct) ? null : await userProfileDelegate.GetUserProfileAsync(hdid, ct: ct); - if (patient == null && profile == null) - { - return null; - } - - return mappingService.MapToPatientSupportResult(patient, profile); + return patient == null && profile == null + ? null + : mappingService.MapToPatientSupportResult(patient, profile); } private async Task GetPatientSupportResultAsync(UserProfile profile, CancellationToken ct) diff --git a/Apps/Admin/Server/Services/UserFeedbackService.cs b/Apps/Admin/Server/Services/UserFeedbackService.cs index 0dd46e44f6..715bc5b134 100644 --- a/Apps/Admin/Server/Services/UserFeedbackService.cs +++ b/Apps/Admin/Server/Services/UserFeedbackService.cs @@ -103,7 +103,7 @@ public async Task>> GetAllTagsAsync(Cancellati { IEnumerable adminTags = await adminTagDelegate.GetAllAsync(ct); - IList adminTagViews = adminTags.Select(mappingService.MapToAdminTagView).ToList(); + List adminTagViews = adminTags.Select(mappingService.MapToAdminTagView).ToList(); return new RequestResult> { diff --git a/Apps/Admin/Tests/Delegates/RestImmunizationAdminDelegateTests.cs b/Apps/Admin/Tests/Delegates/RestImmunizationAdminDelegateTests.cs index f038f49062..72f1f7b2ba 100644 --- a/Apps/Admin/Tests/Delegates/RestImmunizationAdminDelegateTests.cs +++ b/Apps/Admin/Tests/Delegates/RestImmunizationAdminDelegateTests.cs @@ -17,7 +17,6 @@ namespace HealthGateway.Admin.Tests.Delegates { using System; using System.Collections.Generic; - using System.Linq; using System.Threading; using System.Threading.Tasks; using HealthGateway.Admin.Common.Models.CovidSupport; @@ -190,7 +189,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } } diff --git a/Apps/Admin/Tests/Delegates/RestVaccineStatusDelegateTests.cs b/Apps/Admin/Tests/Delegates/RestVaccineStatusDelegateTests.cs index 44b99821a8..3650b33e1d 100644 --- a/Apps/Admin/Tests/Delegates/RestVaccineStatusDelegateTests.cs +++ b/Apps/Admin/Tests/Delegates/RestVaccineStatusDelegateTests.cs @@ -18,7 +18,6 @@ namespace HealthGateway.Admin.Tests.Delegates using System; using System.Collections.Generic; using System.Globalization; - using System.Linq; using System.Threading; using System.Threading.Tasks; using HealthGateway.Admin.Server.Api; @@ -151,7 +150,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } } diff --git a/Apps/Admin/Tests/Services/AdminReportServiceTests.cs b/Apps/Admin/Tests/Services/AdminReportServiceTests.cs index e936245072..4a3b633196 100644 --- a/Apps/Admin/Tests/Services/AdminReportServiceTests.cs +++ b/Apps/Admin/Tests/Services/AdminReportServiceTests.cs @@ -132,9 +132,9 @@ private static IAdminReportService GetAdminReportService( Mock? blockedAccessDelegateMock = null, Mock? patientRepositoryMock = null) { - delegationDelegateMock = delegationDelegateMock ?? new(); - blockedAccessDelegateMock = blockedAccessDelegateMock ?? new(); - patientRepositoryMock = patientRepositoryMock ?? new(); + delegationDelegateMock ??= new(); + blockedAccessDelegateMock ??= new(); + patientRepositoryMock ??= new(); return new AdminReportService( delegationDelegateMock.Object, diff --git a/Apps/Admin/Tests/Services/AgentAccessServiceTests.cs b/Apps/Admin/Tests/Services/AgentAccessServiceTests.cs index a2932a574e..fb26107b29 100644 --- a/Apps/Admin/Tests/Services/AgentAccessServiceTests.cs +++ b/Apps/Admin/Tests/Services/AgentAccessServiceTests.cs @@ -236,8 +236,8 @@ private static IAgentAccessService GetAgentAccessService( Mock? authenticationDelegateMock = null, Mock? keycloakAdminApiMock = null) { - authenticationDelegateMock = authenticationDelegateMock ?? new(); - keycloakAdminApiMock = keycloakAdminApiMock ?? new(); + authenticationDelegateMock ??= new(); + keycloakAdminApiMock ??= new(); return new AgentAccessService( authenticationDelegateMock.Object, diff --git a/Apps/Admin/Tests/Services/BetaFeatureServiceTests.cs b/Apps/Admin/Tests/Services/BetaFeatureServiceTests.cs index 0a046aec2f..2bb53fa52f 100644 --- a/Apps/Admin/Tests/Services/BetaFeatureServiceTests.cs +++ b/Apps/Admin/Tests/Services/BetaFeatureServiceTests.cs @@ -285,7 +285,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } @@ -358,8 +358,8 @@ private static IBetaFeatureService GetBetaFeatureService( Mock? profileDelegateMock = null, Mock? betaFeatureAccessDelegateMock = null) { - profileDelegateMock = profileDelegateMock ?? new(); - betaFeatureAccessDelegateMock = betaFeatureAccessDelegateMock ?? new(); + profileDelegateMock ??= new(); + betaFeatureAccessDelegateMock ??= new(); return new BetaFeatureService( profileDelegateMock.Object, diff --git a/Apps/Admin/Tests/Services/CommunicationServiceTests.cs b/Apps/Admin/Tests/Services/CommunicationServiceTests.cs index e2abb9d618..673280fe77 100644 --- a/Apps/Admin/Tests/Services/CommunicationServiceTests.cs +++ b/Apps/Admin/Tests/Services/CommunicationServiceTests.cs @@ -17,7 +17,6 @@ namespace HealthGateway.Admin.Tests.Services { using System; using System.Collections.Generic; - using System.Linq; using System.Threading; using System.Threading.Tasks; using DeepEqual.Syntax; @@ -306,7 +305,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } } diff --git a/Apps/Admin/Tests/Services/ConfigurationServiceTests.cs b/Apps/Admin/Tests/Services/ConfigurationServiceTests.cs index 8908934415..cfbe7410ae 100644 --- a/Apps/Admin/Tests/Services/ConfigurationServiceTests.cs +++ b/Apps/Admin/Tests/Services/ConfigurationServiceTests.cs @@ -16,7 +16,6 @@ namespace HealthGateway.Admin.Tests.Services { using System.Collections.Generic; - using System.Linq; using HealthGateway.Admin.Common.Models; using HealthGateway.Admin.Server.Services; using Microsoft.Extensions.Configuration; @@ -61,7 +60,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } } diff --git a/Apps/Admin/Tests/Services/CovidSupportServiceTests.cs b/Apps/Admin/Tests/Services/CovidSupportServiceTests.cs index 4a7a48ba36..8291367e69 100644 --- a/Apps/Admin/Tests/Services/CovidSupportServiceTests.cs +++ b/Apps/Admin/Tests/Services/CovidSupportServiceTests.cs @@ -18,7 +18,6 @@ namespace HealthGateway.Admin.Tests.Services using System; using System.Collections.Generic; using System.Globalization; - using System.Linq; using System.Threading; using System.Threading.Tasks; using HealthGateway.AccountDataAccess.Patient; @@ -553,7 +552,7 @@ private static MailDocumentRequest GenerateMailDocumentRequest() PersonalHealthNumber = Phn, MailAddress = new() { - StreetLines = new[] { "9105 ROTTERDAM PLACE" }, + StreetLines = ["9105 ROTTERDAM PLACE"], City = "VANCOUVER", Country = string.Empty, PostalCode = "V3X 4J5", @@ -659,7 +658,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } } diff --git a/Apps/Admin/Tests/Services/CsvExportServiceTests.cs b/Apps/Admin/Tests/Services/CsvExportServiceTests.cs index 5024f0898f..bce1209951 100644 --- a/Apps/Admin/Tests/Services/CsvExportServiceTests.cs +++ b/Apps/Admin/Tests/Services/CsvExportServiceTests.cs @@ -19,7 +19,6 @@ namespace HealthGateway.Admin.Tests.Services using System; using System.Collections.Generic; using System.IO; - using System.Linq; using System.Threading; using System.Threading.Tasks; using DeepEqual.Syntax; @@ -354,7 +353,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } @@ -366,12 +365,12 @@ private static ICsvExportService GetCsvExportService( Mock? inactiveUserServiceMock = null, Mock? feedbackDelegateMock = null) { - profileDelegateMock = profileDelegateMock ?? new(); - commentDelegateMock = commentDelegateMock ?? new(); - noteDelegateMock = noteDelegateMock ?? new(); - ratingDelegateMock = ratingDelegateMock ?? new(); - inactiveUserServiceMock = inactiveUserServiceMock ?? new(); - feedbackDelegateMock = feedbackDelegateMock ?? new(); + profileDelegateMock ??= new(); + commentDelegateMock ??= new(); + noteDelegateMock ??= new(); + ratingDelegateMock ??= new(); + inactiveUserServiceMock ??= new(); + feedbackDelegateMock ??= new(); return new CsvExportService( Configuration, diff --git a/Apps/Admin/Tests/Services/DashboardServiceTests.cs b/Apps/Admin/Tests/Services/DashboardServiceTests.cs index 3e437db5ac..8e20a3ff6c 100644 --- a/Apps/Admin/Tests/Services/DashboardServiceTests.cs +++ b/Apps/Admin/Tests/Services/DashboardServiceTests.cs @@ -17,7 +17,6 @@ namespace HealthGateway.Admin.Tests.Services { using System; using System.Collections.Generic; - using System.Linq; using System.Threading; using System.Threading.Tasks; using DeepEqual.Syntax; @@ -55,7 +54,7 @@ public async Task ShouldGetAllTimeCounts() Dependents = dependentCount, }; - IDashboardService service = SetupGetAllTimeCountsMock(userProfileCount, closedUserProfileCount, dependentCount); + IDashboardService service = SetupDashboardServiceForAllTimeCounts(userProfileCount, closedUserProfileCount, dependentCount); // Act AllTimeCounts actual = await service.GetAllTimeCountsAsync(); @@ -104,7 +103,7 @@ public async Task ShouldGetDailyUsageCounts() DependentRegistrations = new SortedDictionary(dependentRegistrationCounts), }; - IDashboardService service = SetupDailyUsageCountsMock(userRegistrationCounts, userLoginCounts, dependentRegistrationCounts); + IDashboardService service = SetupDashboardServiceForDailyUsageCounts(userRegistrationCounts, userLoginCounts, dependentRegistrationCounts); // Act DailyUsageCounts actual = await service.GetDailyUsageCountsAsync(startDate, endDate); @@ -128,7 +127,7 @@ public async Task ShouldGetRecurringUserCount() const int userCount = 10; const int expected = 10; - IDashboardService service = SetupGetRecurringUserCountMock(dayCount, userCount); + IDashboardService service = SetupDashboardServiceForRecurringUserCount(dayCount, userCount); // Act int actual = await service.GetRecurringUserCountAsync(dayCount, startDate, endDate); @@ -156,7 +155,7 @@ public async Task ShouldGetAppLoginCounts() AppLoginCounts expected = new(webCount, mobileCount + androidCount + iosCount, androidCount, iosCount, salesforceCount); - IDashboardService service = SetupGetAppLoginCountsMock(webCount, mobileCount, androidCount, iosCount, salesforceCount); + IDashboardService service = SetupDashboardServiceForAppLoginCounts(webCount, mobileCount, androidCount, iosCount, salesforceCount); // Act AppLoginCounts actual = await service.GetAppLoginCountsAsync(startDate, endDate); @@ -185,7 +184,7 @@ public async Task ShouldGetRatingsSummary() { "5", fiveStarCount }, }; - IDashboardService service = SetupGetRatingsSummaryMock(threeStarCount, fiveStarCount); + IDashboardService service = SetupDashboardServiceForRatingsSummary(threeStarCount, fiveStarCount); // Act IDictionary actual = await service.GetRatingsSummaryAsync(startDate, endDate); @@ -206,8 +205,9 @@ public async Task ShouldGetAgeCounts() DateOnly startDatePlus5Years = startDate.AddYears(5); DateOnly endDate = new(2024, 1, 15); - const int startDateAge = 14; - const int startDatePlus5YearsAge = 9; + int currentYear = DateTime.UtcNow.Year; + int startDateAge = currentYear - startDate.Year; + int startDatePlus5YearsAge = currentYear - startDatePlus5Years.Year; const int startDateAgeCount = 5; const int startDatePlus5YearsAgeCount = 1; @@ -217,7 +217,7 @@ public async Task ShouldGetAgeCounts() { startDatePlus5YearsAge, startDatePlus5YearsAgeCount }, }; - IDashboardService service = SetupGetAgeCountsMock(startDate, startDatePlus5Years, startDateAgeCount, startDatePlus5YearsAgeCount); + IDashboardService service = SetupDashboardServiceForAgeCounts(startDate, startDatePlus5Years, startDateAgeCount, startDatePlus5YearsAgeCount); // Act IDictionary actual = await service.GetAgeCountsAsync(startDate, endDate); @@ -235,7 +235,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } @@ -255,7 +255,7 @@ private static IDashboardService GetDashboardService( ratingDelegateMock.Object); } - private static IDashboardService SetupGetAllTimeCountsMock(int userProfileCount, int closedUserProfileCount, int dependentCount) + private static IDashboardService SetupDashboardServiceForAllTimeCounts(int userProfileCount, int closedUserProfileCount, int dependentCount) { Mock userProfileDelegateMock = new(); userProfileDelegateMock.Setup(s => s.GetUserProfileCountAsync(It.IsAny())).ReturnsAsync(userProfileCount); @@ -267,7 +267,7 @@ private static IDashboardService SetupGetAllTimeCountsMock(int userProfileCount, return GetDashboardService(dependentDelegateMock, userProfileDelegateMock); } - private static IDashboardService SetupDailyUsageCountsMock( + private static IDashboardService SetupDashboardServiceForDailyUsageCounts( IDictionary userRegistrationCounts, IDictionary userLoginCounts, IDictionary dependentRegistrationCounts) @@ -284,7 +284,7 @@ private static IDashboardService SetupDailyUsageCountsMock( return GetDashboardService(dependentDelegateMock, userProfileDelegateMock); } - private static IDashboardService SetupGetRecurringUserCountMock(int dayCount, int userCount) + private static IDashboardService SetupDashboardServiceForRecurringUserCount(int dayCount, int userCount) { Mock userProfileDelegateMock = new(); userProfileDelegateMock.Setup(s => s.GetRecurringUserCountAsync(dayCount, It.IsAny(), It.IsAny(), It.IsAny())) @@ -293,7 +293,7 @@ private static IDashboardService SetupGetRecurringUserCountMock(int dayCount, in return GetDashboardService(userProfileDelegateMock: userProfileDelegateMock); } - private static IDashboardService SetupGetAppLoginCountsMock(int webCount, int mobileCount, int androidCount, int iosCount, int salesforceCount) + private static IDashboardService SetupDashboardServiceForAppLoginCounts(int webCount, int mobileCount, int androidCount, int iosCount, int salesforceCount) { IDictionary lastLoginClientCounts = new Dictionary { @@ -311,7 +311,7 @@ private static IDashboardService SetupGetAppLoginCountsMock(int webCount, int mo return GetDashboardService(userProfileDelegateMock: userProfileDelegateMock); } - private static IDashboardService SetupGetRatingsSummaryMock(int threeStarCount, int fiveStarCount) + private static IDashboardService SetupDashboardServiceForRatingsSummary(int threeStarCount, int fiveStarCount) { IDictionary summary = new Dictionary { @@ -326,7 +326,7 @@ private static IDashboardService SetupGetRatingsSummaryMock(int threeStarCount, return GetDashboardService(ratingDelegateMock: ratingsDelegateMock); } - private static IDashboardService SetupGetAgeCountsMock(DateOnly startDate, DateOnly startDatePlus5Years, int startDateAgeCount, int startDatePlus5YearsAgeCount) + private static IDashboardService SetupDashboardServiceForAgeCounts(DateOnly startDate, DateOnly startDatePlus5Years, int startDateAgeCount, int startDatePlus5YearsAgeCount) { IDictionary yearOfBirthCounts = new Dictionary { diff --git a/Apps/Admin/Tests/Services/DelegationServiceTests.cs b/Apps/Admin/Tests/Services/DelegationServiceTests.cs index d8e56c59ae..9405e82803 100644 --- a/Apps/Admin/Tests/Services/DelegationServiceTests.cs +++ b/Apps/Admin/Tests/Services/DelegationServiceTests.cs @@ -575,7 +575,7 @@ private static IConfigurationRoot GetIConfigurationRoot(bool isChangeFeedEnabled }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } @@ -844,7 +844,7 @@ private static DelegationService GetDelegationService( delegationDelegate.Setup(p => p.GetDependentAsync(resourceOwnerHdid, true, CancellationToken.None)).ReturnsAsync(dependent); - messageSender = messageSender ?? new(); + messageSender ??= new(); return new( GetIConfigurationRoot(isChangeFeedEnabled), diff --git a/Apps/Admin/Tests/Services/InactiveUserServiceTests.cs b/Apps/Admin/Tests/Services/InactiveUserServiceTests.cs index 1d01043b7d..c350f85a2d 100644 --- a/Apps/Admin/Tests/Services/InactiveUserServiceTests.cs +++ b/Apps/Admin/Tests/Services/InactiveUserServiceTests.cs @@ -17,7 +17,6 @@ namespace HealthGateway.Admin.Tests.Services { using System; using System.Collections.Generic; - using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -234,7 +233,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } diff --git a/Apps/Admin/Tests/Services/SupportServiceTests.cs b/Apps/Admin/Tests/Services/SupportServiceTests.cs index db34f02820..81bfd60a1b 100644 --- a/Apps/Admin/Tests/Services/SupportServiceTests.cs +++ b/Apps/Admin/Tests/Services/SupportServiceTests.cs @@ -148,11 +148,11 @@ public async Task ShouldGetPatientSupportDetails( IList messagingVerifications = GenerateMessagingVerifications(SmsNumber, Email); VaccineDetails vaccineDetails = GenerateVaccineDetails(GenerateVaccineDose()); AgentAuditQuery auditQuery = new(Hdid); - IEnumerable agentAudits = new[] { GenerateAgentAudit() }; - IEnumerable blockedDataSources = new[] - { + IEnumerable agentAudits = [GenerateAgentAudit()]; + IEnumerable blockedDataSources = + [ DataSource.Immunization, - }; + ]; ResourceDelegateQuery resourceDelegateQuery = new() { ByDelegateHdid = patientQuery.Hdid, IncludeDependent = true }; ResourceDelegateQueryResult resourceDelegateQueryResult = GenerateResourceDelegatesForDelegate(patientQuery.Hdid, [Hdid2]); PatientDetailsQuery dependentPatientQuery = diff --git a/Apps/Admin/Tests/Services/UserFeedbackServiceTests.cs b/Apps/Admin/Tests/Services/UserFeedbackServiceTests.cs index 2bab6a132c..ac5b54604b 100644 --- a/Apps/Admin/Tests/Services/UserFeedbackServiceTests.cs +++ b/Apps/Admin/Tests/Services/UserFeedbackServiceTests.cs @@ -429,7 +429,7 @@ private static IConfigurationRoot GetIConfigurationRoot() }; return new ConfigurationBuilder() - .AddInMemoryCollection(myConfiguration.ToList()) + .AddInMemoryCollection(myConfiguration) .Build(); } @@ -438,9 +438,9 @@ private static IUserFeedbackService GetUserFeedbackService( Mock? adminTagDelegateMock = null, Mock? userProfileDelegateMock = null) { - feedbackDelegateMock = feedbackDelegateMock ?? new(); - adminTagDelegateMock = adminTagDelegateMock ?? new(); - userProfileDelegateMock = userProfileDelegateMock ?? new(); + feedbackDelegateMock ??= new(); + adminTagDelegateMock ??= new(); + userProfileDelegateMock ??= new(); return new UserFeedbackService( new Mock>().Object,