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

51 lines
1.7 KiB
C#

using System;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.Utilities;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Fab2ApprovalTests.Utilities;
[TestClass]
public class EmailUtilitiesTests {
#pragma warning disable CS8618
private static ILogger? _Logger;
private static TestContext _TestContext;
private static WebApplicationFactory<Fab2ApprovalMKLink.Program> _WebApplicationFactory;
#pragma warning restore
[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) { }
}
#if Release
[Ignore]
#endif
[TestMethod]
public void EmailUtilitiesIsAttachedOnly() {
_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)
EmailUtilities.SendNotification("mike.phares@infineon.com", [], "Test: Subject", "Body");
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
NonThrowTryCatch();
}
}