using System; using Fab2ApprovalSystem.DMO; using Fab2ApprovalSystem.Models; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Fab2ApprovalTests.DMO; [TestClass] public class WorkflowDMOTests { #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 WorkflowDMO(ILogger? logger, AppSettings appSettings, int issueID, string comments, int documentType) { #pragma warning disable IDE0059 bool isLastStep; SetGlobalVars(logger, appSettings); ECN_DMO ecnDMO = new(); ECN ecn = ecnDMO.GetECN(issueID); WorkflowDMO workflowDMO = new(); // string AddAdditionalApproval(int issueID, string userIDs, byte step, int documentType); // string AddEECNApproval(int ecnNumber, byte step, int documentType, string engUserIDs, string opUserIDs); bool check = workflowDMO.Approve(appSettings, issueID, ecn.CurrentStep, comments, out isLastStep, appSettings.UserId, documentType, ecn.WorkFlowNumber); // string DelegateDocumentApproval(int issueID, int delegateFromUser, int delegateToUser); // string GetApproversForCancelled_ExpiredTECNDocs(int ecnNumber); // string GetSubRoleItems(int issueID, int docType); // string GetSubRolesForPartsRequestNextStep(int prNumber); // WorkflowSteps GetWorkflowStep(int docTypeID, int wfNumber, int stepNumber); // string ReAssignApproval(int issueID, int assignedFromUser, int assignedToUser, byte step, int docType); // bool Recall(int issueID, byte step, string comments, appSettings.UserId, int docType); // bool Reject(int issueID, byte step, string comments, appSettings.UserId, int docType); // void RejectTECNExtension(int ecnNumber, byte step, string comments, appSettings.UserId, int docType); if (workflowDMO is null) { } #pragma warning restore IDE0059 } #if Release [Ignore] #endif [TestMethod] [DataRow(82700, "comment", 3)] public void WorkflowDMOIsAttachedOnly(int issueID, string comments, int documentType) { _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) WorkflowDMO(_Logger, appSettings, issueID, comments, documentType); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } }