using System; using System.Linq; using Fab2ApprovalSystem.DMO; using Fab2ApprovalSystem.Models; using Fab2ApprovalSystem.ViewModels; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Fab2ApprovalTests.DMO; [TestClass] public class CorrectiveActionDMOTests { #pragma warning disable CS8618 private static ILogger? _Logger; private static TestContext _TestContext; private static WebApplicationFactory _WebApplicationFactory; #pragma warning restore public static void SetGlobalVars(ILogger? logger, AppSettings appSettings) { logger?.LogDebug("Starting to set Fab2ApprovalSystem.Misc.GlobalVars"); Fab2ApprovalSystem.Misc.GlobalVars.AppSettings = appSettings; Fab2ApprovalSystem.Misc.GlobalVars.AttachmentUrl = appSettings.AttachmentUrl is null ? string.Empty : appSettings.AttachmentUrl; Fab2ApprovalSystem.Misc.GlobalVars.CA_BlankFormsLocation = appSettings.CABlankFormsLocation; Fab2ApprovalSystem.Misc.GlobalVars.DBConnection = appSettings.DBConnection; Fab2ApprovalSystem.Misc.GlobalVars.DB_CONNECTION_STRING = appSettings.DBConnectionString; Fab2ApprovalSystem.Misc.GlobalVars.hostURL = appSettings.HostURL; Fab2ApprovalSystem.Misc.GlobalVars.IS_INFINEON_DOMAIN = appSettings.IsInfineonDomain; Fab2ApprovalSystem.Misc.GlobalVars.MesaTemplateFiles = appSettings.MesaTemplateFiles; Fab2ApprovalSystem.Misc.GlobalVars.NDriveURL = appSettings.NDriveURL; Fab2ApprovalSystem.Misc.GlobalVars.SENDER_EMAIL = appSettings.SenderEmail; Fab2ApprovalSystem.Misc.GlobalVars.USER_ID = appSettings.UserId; Fab2ApprovalSystem.Misc.GlobalVars.USER_ISADMIN = appSettings.UserIsAdmin; Fab2ApprovalSystem.Misc.GlobalVars.WSR_URL = appSettings.WSR_URL; logger?.LogDebug("Finished setting Fab2ApprovalSystem.Misc.GlobalVars"); } [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { _TestContext = testContext; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); } private static void NonThrowTryCatch() { try { throw new Exception(); } catch (Exception) { } } private static void CorrectiveActionDMO(ILogger? logger, AppSettings appSettings) { #pragma warning disable IDE0059 SetGlobalVars(logger, appSettings); CorrectiveActionDMO correctiveActionDMO = new(); // void ApproveSection(int issueID, appSettings.UserId, string DSection); // void DeleteCAAttachment(int attachmentID); // void DeleteD3ContainmentActionItem(int d3ContainmentActionID); // void DeleteD5D6CorrectivetAction(int d5d6CAID); // void DeleteD7PreventiveActionItem(int D7PAID); int[] ints = correctiveActionDMO.Get8DQA().ToArray(); CAUserList[] cAUserLists = correctiveActionDMO.GetAllUserList().ToArray(); // string GetCAAttachmentFileName(string fileGUID); // IEnumerable GetCAAttachmentsList(int caNo, string section); CAD3D5D7Due[] cAD3D5D7Dues = correctiveActionDMO.GetCAD3D5D7Due().ToArray(); // IEnumerable GetCAFindingsItemAttachments(int caFindingsID); // CorrectiveAction GetCAItem(int caNo, appSettings.UserId); // CorrectiveAction GetCAItemReadOnly(int caNo, appSettings.UserId); // IEnumerable GetCASectionApprovalLog(int caNo); CASource[] cASources = correctiveActionDMO.GetCASourceList().ToArray(); // IEnumerable GetD3ContainmentActions(int caNo); RiskAssessmentArea[] riskAssessmentAreas = correctiveActionDMO.GetD3RiskAssessmentAreas().ToArray(); // D5D6CorrectivetAction GetD5D5CAItem(int d5d6CAID); // IEnumerable GetD5D6CorrectivetActions(int caNo); D5D6Improvement[] d5D6Improvements = correctiveActionDMO.GetD5D6Improvement().ToArray(); // IEnumerable GetD5D6ItemAttachments(int d5d6CAID); // IEnumerable GetD7ItemAttachments(int d7PAID); // D7PreventiveAction GetD7PAItem(int d7PAID); // IEnumerable GetD7PreventiveActions(int caNo); IssuesViewModel[] issuesViewModels = correctiveActionDMO.GetECNList().ToArray(); Module[] modules = correctiveActionDMO.GetModuleList().ToArray(); // List GetRejectionAssigneeEmailList(int caNo); CAUserList[] cAUserListsB = correctiveActionDMO.GetUserList().ToArray(); // CorrectiveAction InsertCA(CorrectiveAction ca); // void InsertCAAttachment(CA_Attachment attach); // void InsertD3ContainmentAction(D3ContainmentAction model); // void InsertD5D6CorrectivetAction(D5D6CorrectivetAction model); // void InsertD7PreventiveAction(D7PreventiveAction model); // bool IsAIAssignee(appSettings.UserId, int caId); // bool IsLastSectionApprover(int caNo, string dSection); // bool IsUserSectionApprover(int issueId, appSettings.UserId); // void RejectSection(int issueID, appSettings.UserId, string DSection, string comments); // void ReleaseLockOnDocument(appSettings.UserId, int issueID); // DateTime SetCAComplete(int issueID); // DateTime SetCAD3DueDate(int issueID); // DateTime SetCAD5D7DueDate(int issueID); // void SetD3D5D7NotificationDate(int caNo, string section); // int StartApproval(int issueID, appSettings.UserId, int worlflowNumber); // void StartSectionApproval(int issueID, appSettings.UserId, string DSection); // void UpdateCorrectiveAction(CorrectiveAction model); // void UpdateD3ContainmentAction(D3ContainmentAction model); // void UpdateD5D6CorrectivetAction(D5D6CorrectivetAction model); // void UpdateD7PreventiveAction(D7PreventiveAction model); if (correctiveActionDMO is null) { } #pragma warning restore IDE0059 } #if Release [Ignore] #endif [TestMethod] public void CorrectiveActionDMOIsAttachedOnly() { _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; AppSettings? appSettings = serviceProvider?.GetRequiredService(); Assert.IsTrue(appSettings is not null); if (System.Diagnostics.Debugger.IsAttached) CorrectiveActionDMO(_Logger, appSettings); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } }