Files
oi-metrology/Tests/UnitTestWaferCounterController.cs
phares@iscn5cg20977xq a427c5648a - 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
2025-07-29 16:56:09 -07:00

80 lines
2.8 KiB
C#

using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models.Stateless;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestWaferCounterController : BaseTestClass
{
#pragma warning disable CS8618
private static ILogger? _Logger;
private static string _ControllerName;
public TestContext TestContext { get; set; }
private static WebApplicationFactory<Wafer.Counter.Program>? _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_WebApplicationFactory = new WebApplicationFactory<Wafer.Counter.Program>();
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
_Logger = serviceProvider.GetRequiredService<ILogger<Wafer.Counter.Program>>();
_ControllerName = nameof(Wafer.Counter.ApiControllers.WaferCounterController)[..^10];
}
private static void NonThrowTryCatch()
{
try
{ throw new Exception(); }
catch (Exception) { }
}
[TestCleanup]
public void TestCleanup()
{
if (TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)
IncrementFailedTests();
}
[TestMethod]
public void TestControllerName()
{
_Logger?.LogInformation("Starting Web Application");
Assert.AreEqual(IWaferCounterController<string>.GetRouteName(), _ControllerName);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
[Ignore]
[TestMethod]
public void GetLastQuantityAndSlotMap()
{
_Logger?.LogInformation("Starting Web Application");
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService<IWaferCounterRepository>();
WaferCounter? result = waferCounterRepository?.GetLastQuantityAndSlotMap(area: "FQA", waferSize: "8INCH", text: "Test");
Assert.IsNotNull(result);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
[Ignore]
[TestMethod]
public async Task LastQuantityAndSlotMapApi()
{
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
_Logger?.LogInformation("Starting Web Application");
Assert.IsNotNull(httpClient);
string? response = await httpClient.GetStringAsync($"api/v1/{_ControllerName}/FQA/last-quantity-and-slot-map/?waferSize=8INCH&text=Test");
Assert.IsNotNull(response);
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
NonThrowTryCatch();
}
}