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 { #pragma warning disable CS8618 private static ILogger? _Logger; private static string _ControllerName; private static TestContext _TestContext; private static WebApplicationFactory? _WebApplicationFactory; #pragma warning restore [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { _TestContext = testContext; _WebApplicationFactory = new WebApplicationFactory(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; _Logger = serviceProvider.GetRequiredService>(); _ControllerName = nameof(Server.ApiControllers.WaferCounterController)[..^10]; } private static void NonThrowTryCatch() { try { throw new Exception(); } catch (Exception) { } } [TestMethod] public void TestControllerName() { _Logger?.LogInformation("Starting Web Application"); Assert.AreEqual(IWaferCounterController.GetRouteName(), _ControllerName); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } [TestMethod] public void GetSlotMap() { _Logger?.LogInformation("Starting Web Application"); string? result; IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService(); result = waferCounterRepository?.GetSlotMap("T00", "P0000000"); Assert.AreEqual("0000000000000000000000000", result); result = waferCounterRepository?.GetSlotMap("T25", "P1FFFFFF"); Assert.AreEqual("1111111111111111111111111", result); result = waferCounterRepository?.GetSlotMap("T12", "P0AAAAAA"); Assert.AreEqual("0101010101010101010101010", result); result = waferCounterRepository?.GetSlotMap("T13", "P1555555"); Assert.AreEqual("1010101010101010101010101", result); result = waferCounterRepository?.GetSlotMap("T20", "P0EFFFF8"); Assert.AreEqual("0111011111111111111111000", result); result = waferCounterRepository?.GetSlotMap("T20", "P07FFFF8"); Assert.AreEqual("0011111111111111111111000", result); result = waferCounterRepository?.GetSlotMap("T20", "P17FFFF0"); Assert.AreEqual("1011111111111111111110000", result); result = waferCounterRepository?.GetSlotMap("T03", "P1002002"); Assert.AreEqual("1000000000010000000000010", result); result = waferCounterRepository?.GetSlotMap("T02", "P1000002"); Assert.AreEqual("1000000000000000000000010", result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } [Ignore] [TestMethod] public void GetLastQuantityAndSlotMap() { WaferCounter? result; _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService(); result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "6INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-East", "8INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-West", "6INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("EPP-West", "8INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("FQA", "6INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("FQA", "8INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("MU", "6INCH"); Assert.IsNotNull(result); result = waferCounterRepository?.GetLastQuantityAndSlotMap("MU", "8INCH"); Assert.IsNotNull(result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } [Ignore] [TestMethod] public async Task GetLastQuantityAndSlotMapApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); Assert.IsTrue(httpClient is not null); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/8INCH/last-quantity-and-slot-map/?area=EPP-East"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetLastQuantityAndSlotMap)}.json"), json); Assert.IsNotNull(json); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } [Ignore] [TestMethod] public void GetLastQuantityAndSlotMapWithText() { _Logger?.LogInformation("Starting Web Application"); IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider; IWaferCounterRepository? waferCounterRepository = serviceProvider?.GetRequiredService(); WaferCounter? result = waferCounterRepository?.GetLastQuantityAndSlotMapWithText("EPP-East", "8INCH", "123456"); Assert.IsNotNull(result); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } [Ignore] [TestMethod] public async Task GetLastQuantityAndSlotMapWithTextApi() { HttpClient? httpClient = _WebApplicationFactory?.CreateClient(); _Logger?.LogInformation("Starting Web Application"); Assert.IsTrue(httpClient is not null); string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/8INCH/last-quantity-and-slot-map-with-text/?area=EPP-East&text=123456"); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetLastQuantityAndSlotMapWithText)}.json"), json); Assert.IsNotNull(json); _Logger?.LogInformation("{TestName} completed", _TestContext?.TestName); NonThrowTryCatch(); } }