mesa-fab-approval/Fab2ApprovalTests/DMO/CorrectiveActionDMOTests.cs
Mike Phares b99b721458 Moved System.IO references from DMO classes to Static Helpers
Removed nugetSource from pipeline
Removed more comments
Created Static Classes for most DMO / Controller Classes
Push ConfigurationManager.AppSettings to controller
Align Tests with other Projects
2024-12-11 09:29:01 -07:00

126 lines
6.7 KiB
C#

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<Fab2ApprovalMKLink.Program> _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<Fab2ApprovalMKLink.Program>();
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
_Logger = serviceProvider.GetRequiredService<ILogger<Fab2ApprovalMKLink.Program>>();
}
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(appSettings);
// void ApproveSection(int issueID, int 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<CA_Attachment> GetCAAttachmentsList(int caNo, string section);
CAD3D5D7Due[] cAD3D5D7Dues = correctiveActionDMO.GetCAD3D5D7Due().ToArray();
// IEnumerable<CA_Attachment> GetCAFindingsItemAttachments(int caFindingsID);
// CorrectiveAction GetCAItem(int caNo, int userID);
// CorrectiveAction GetCAItemReadOnly(int caNo, int userID);
// IEnumerable<CASectionApproval> GetCASectionApprovalLog(int caNo);
CASource[] cASources = correctiveActionDMO.GetCASourceList().ToArray();
// IEnumerable<D3ContainmentAction> GetD3ContainmentActions(int caNo);
RiskAssessmentArea[] riskAssessmentAreas = correctiveActionDMO.GetD3RiskAssessmentAreas().ToArray();
// D5D6CorrectivetAction GetD5D5CAItem(int d5d6CAID);
// IEnumerable<D5D6CorrectivetAction> GetD5D6CorrectivetActions(int caNo);
D5D6Improvement[] d5D6Improvements = correctiveActionDMO.GetD5D6Improvement().ToArray();
// IEnumerable<CA_Attachment> GetD5D6ItemAttachments(int d5d6CAID);
// IEnumerable<CA_Attachment> GetD7ItemAttachments(int d7PAID);
// D7PreventiveAction GetD7PAItem(int d7PAID);
// IEnumerable<D7PreventiveAction> GetD7PreventiveActions(int caNo);
IssuesViewModel[] issuesViewModels = correctiveActionDMO.GetECNList().ToArray();
Module[] modules = correctiveActionDMO.GetModuleList().ToArray();
// List<string> 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(int userId, int caId);
// bool IsLastSectionApprover(int caNo, string dSection);
// bool IsUserSectionApprover(int issueId, int userId);
// void RejectSection(int issueID, int userID, string DSection, string comments);
// void ReleaseLockOnDocument(int 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, int userID, int worlflowNumber);
// void StartSectionApproval(int issueID, int 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<AppSettings>();
Assert.IsTrue(appSettings is not null);
if (System.Diagnostics.Debugger.IsAttached)
CorrectiveActionDMO(_Logger, appSettings);
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
NonThrowTryCatch();
}
}