Align .editorconfig files Move Controller logic to DMO classes GlobalVars.AppSettings = Models.AppSettings.GetFromConfigurationManager(); Question EditorConfig Project level editorconfig Format White Spaces AppSetting when EnvironmentVariable not set Corrective Actions Tests Schedule Actions Tests DMO Tests Controller Tests Get ready to use VSCode IDE
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
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();
|
|
}
|
|
|
|
} |