- 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:
@ -7,14 +7,14 @@ using OI.Metrology.Shared.ViewModels;
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestServiceShopOrderController
|
||||
public class UnitTestServiceShopOrderController : 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
|
||||
@ -22,19 +22,32 @@ public class UnitTestServiceShopOrderController
|
||||
[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>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.ServiceShopOrderController)[..^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(IServiceShopOrderController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
|
||||
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -42,9 +55,9 @@ public class UnitTestServiceShopOrderController
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
ServiceShopOrder[] serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null);
|
||||
ServiceShopOrder[]? serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null);
|
||||
Assert.IsNotNull(serviceShopOrders);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
|
||||
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -54,13 +67,13 @@ public class UnitTestServiceShopOrderController
|
||||
ServiceShopOrder[]? serviceShopOrders;
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IServiceShopOrderRepository? serviceShopOrderRepository = serviceProvider?.GetRequiredService<IServiceShopOrderRepository>();
|
||||
Assert.IsTrue(serviceShopOrderRepository is not null);
|
||||
Assert.IsNotNull(serviceShopOrderRepository);
|
||||
serviceShopOrders = await serviceShopOrderRepository.GetAllServiceShopOrders();
|
||||
Assert.IsTrue(serviceShopOrders is not null);
|
||||
Assert.IsNotNull(serviceShopOrders);
|
||||
serviceShopOrders = await serviceShopOrderRepository.GetServiceShopOrders("23188d3d-9b75-ed11-ab8b-0050568f2fc3");
|
||||
Assert.IsTrue(serviceShopOrders is not null && serviceShopOrders.Length != 0);
|
||||
Assert.IsNotNull(serviceShopOrders[0].ToString());
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
|
||||
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -68,14 +81,14 @@ public class UnitTestServiceShopOrderController
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
Assert.IsNotNull(httpClient);
|
||||
string actionName = nameof(IServiceShopOrderController<object>.Action.All);
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/{actionName}");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetAllServiceShopOrders)}.json"), json);
|
||||
ServiceShopOrder[]? serviceShopOrders = System.Text.Json.JsonSerializer.Deserialize<ServiceShopOrder[]>(json);
|
||||
Assert.IsNotNull(serviceShopOrders);
|
||||
Assert.IsTrue(serviceShopOrders.Length != 0);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContextTestName);
|
||||
Assert.AreNotEqual(0, serviceShopOrders.Length);
|
||||
_Logger?.LogInformation("{TestName} completed", TestContext.TestName);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user