- Include root in valid directories

- AppSetting bug fix

- Updated testes with base test class and editor configuration changes

- Created new server and wafer counter tasks json files and pipelines to match
This commit is contained in:
2025-07-29 16:56:09 -07:00
parent 6f52566fc2
commit a427c5648a
49 changed files with 1680 additions and 822 deletions

View File

@ -8,14 +8,14 @@ using System.Net;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestAppSettingsController
public class UnitTestAppSettingsController : BaseTestClass
{
#pragma warning disable CS8618
private static ILogger? _Logger;
private static string _ControllerName;
private static string? _TestContextTestName;
public TestContext TestContext { get; set; }
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
#pragma warning restore
@ -23,7 +23,6 @@ public class UnitTestAppSettingsController
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContextTestName = testContext.TestName;
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
@ -37,23 +36,31 @@ public class UnitTestAppSettingsController
catch (Exception) { }
}
[TestCleanup]
public void TestCleanup()
{
if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
IncrementFailedTests();
}
[TestMethod]
public void TestControllerName()
{
_Logger?.LogInformation("Starting Web Application");
Assert.AreEqual(IAppSettingsController<object>.GetRouteName(), _ControllerName);
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
[TestMethod]
public void TestConnectionString()
{
_Logger?.LogInformation("Starting Web Application");
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
IAppSettingsRepository<Server.Models.Binder.AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<Server.Models.Binder.AppSettings>>();
appSettingsRepository?.VerifyConnectionStrings();
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
IAppSettingsRepository<AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<AppSettings>>();
_ = Assert.ThrowsException<NotSupportedException>(() => appSettingsRepository?.VerifyConnectionStrings());
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
@ -64,7 +71,7 @@ public class UnitTestAppSettingsController
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
AppSettings? appSettings = serviceProvider?.GetRequiredService<AppSettings>();
Assert.IsNotNull(appSettings);
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
@ -73,10 +80,10 @@ public class UnitTestAppSettingsController
{
_Logger?.LogInformation("Starting Web Application");
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
IAppSettingsRepository<Server.Models.Binder.AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<Server.Models.Binder.AppSettings>>();
Server.Models.Binder.AppSettings? appSettings = appSettingsRepository?.GetAppSettings();
Assert.IsTrue(appSettings is not null);
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
IAppSettingsRepository<AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<AppSettings>>();
AppSettings? appSettings = appSettingsRepository?.GetAppSettings();
Assert.IsNotNull(appSettings);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
@ -85,16 +92,17 @@ public class UnitTestAppSettingsController
{
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
_Logger?.LogInformation("Starting Web Application");
Assert.IsTrue(httpClient is not null);
Assert.IsNotNull(httpClient);
string actionName = nameof(IAppSettingsController<object>.Action.App);
HttpResponseMessage? httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}");
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
string json = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.IsNotNull(httpResponseMessage.Content.Headers.ContentType);
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType.ToString());
string? json = await httpResponseMessage.Content.ReadAsStringAsync();
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetAppSettings)}.json"), json);
Assert.IsNotNull(json);
Assert.IsTrue(json != "[]");
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
Assert.AreNotEqual("[]", json);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
@ -103,10 +111,10 @@ public class UnitTestAppSettingsController
{
_Logger?.LogInformation("Starting Web Application");
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
IAppSettingsRepository<Server.Models.Binder.AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<Server.Models.Binder.AppSettings>>();
IAppSettingsRepository<AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<AppSettings>>();
string? result = appSettingsRepository?.GetBuildNumberAndGitCommitSeven();
Assert.IsTrue(result is not null);
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
Assert.IsNotNull(result);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
@ -115,15 +123,16 @@ public class UnitTestAppSettingsController
{
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
_Logger?.LogInformation("Starting Web Application");
Assert.IsTrue(httpClient is not null);
Assert.IsNotNull(httpClient);
string actionName = nameof(IAppSettingsController<object>.Action.DevOps);
HttpResponseMessage? httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}");
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
Assert.AreEqual("text/plain; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
string json = await httpResponseMessage.Content.ReadAsStringAsync();
Assert.IsNotNull(httpResponseMessage.Content.Headers.ContentType);
Assert.AreEqual("text/plain; charset=utf-8", httpResponseMessage.Content.Headers.ContentType.ToString());
string? json = await httpResponseMessage.Content.ReadAsStringAsync();
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetBuildNumberAndGitCommitSeven)}.json"), json);
Assert.IsNotNull(json);
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}