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

67 lines
2.5 KiB
C#

using System;
using System.Net.Http;
using System.Threading.Tasks;
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 AccountDMOTests {
#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) { }
}
private static void AccountDMO(AppSettings appSettings, HttpClient httpClient) {
#pragma warning disable IDE0059, CS8625
UserAccountDMO userAccountDMO = new();
LoginModel loginModel = userAccountDMO.GetUserByID(appSettings.UserId);
Task<LoginResult> loginResultTask = Fab2ApprovalSystem.DMO.AccountDMO.LoginAsync(httpClient, loginModel: loginModel);
loginResultTask.Wait();
Task<LoginResult> loginResultTaskB = Fab2ApprovalSystem.DMO.AccountDMO.ExternalAuthSetupAsync(httpClient, authAttempt: null);
loginResultTaskB.Wait();
if (loginModel is null) { }
#pragma warning restore IDE0059, CS8625
}
#if Release
[Ignore]
#endif
[TestMethod]
public void AccountDMOIsAttachedOnly() {
_Logger?.LogInformation("Starting Web Application");
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
AppSettings? appSettings = serviceProvider?.GetRequiredService<AppSettings>();
Assert.IsTrue(appSettings is not null);
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
Assert.IsTrue(httpClient is not null);
httpClient.BaseAddress = new Uri(appSettings.ApiBaseUrl);
if (System.Diagnostics.Debugger.IsAttached)
AccountDMO(appSettings, httpClient);
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
NonThrowTryCatch();
}
}