Tests passed using Mock
This commit is contained in:
.editorconfig.gitignore
.kanbn
.vscode
Archive
Server
.vscode
ApiControllers
Data
Tests
AppSettings-GetAppSettings.jsonAppSettings-GetBuildNumberAndGitCommitSeven.jsonExport-GetExport.txtExport-GetLogistics.jsonInfinityQS-GetData.jsonInfinityQS-GetHeader.jsonInfinityQSV2-GetCommandText.sqlInfinityQSV2-GetData.jsonInfinityQSV2-GetHeader.jsonInfinityQSV3-GetCommandText.sqlInfinityQSV3-GetData.jsonInfinityQSV3-GetDescriptors.jsonInfinityQSV3-GetHeader.jsonInfinityQSV3-GetProductDataAverageSumOfDefectsProcessMeanProcessSigma.jsonOpenInsightV1-GetTencorRun.jsonToolTypes-GetData.jsonToolTypes-GetHeaderTitles.jsonToolTypes-GetHeaders.jsonToolTypes-GetToolTypeMetadata.jsonToolTypes-Index.jsonWorkMaterial-GetCassette.json
Models
OI.Metrology.Server.csprojProgram.csRepositories
AppSettingsRepository.csClientSettingsRepository.csExportRepository.csInboundRepository.csInfinityQSV3Repository.csMetrologyRepository.csOpenInsightV1Repository.csPinRepository.csServiceShopOrderRepository.csToolTypesRepository.csWorkMaterialRepository.cs
Services
appsettings.Development.jsonappsettings.jsonwwwroot
js
Shared
Tests
OI.Metrology.Tests.csprojUnitAwaitingDispoController.csUnitInboundController.csUnitTestAppSettingsController.csUnitTestClientSettingsController.csUnitTestExportController.csUnitTestISpreadingResistanceProfileController.csUnitTestInfinityQSController.csUnitTestInfinityQSV2Controller.csUnitTestInfinityQSV3Controller.csUnitTestOpenInsightV1Controller.csUnitTestPinController.csUnitTestReactorController.csUnitTestServiceShopOrderController.csUnitTestToolTypesController.csUnitTestWorkMaterialController.cs
View
azure-pipelines-server-development.ymlazure-pipelines-server.yml@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.ViewModels;
|
||||
using Serilog;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -12,10 +12,10 @@ public class UnitTestServiceShopOrderController
|
||||
|
||||
#pragma warning disable CS8618
|
||||
|
||||
private static ILogger _Logger;
|
||||
private static ILogger? _Logger;
|
||||
private static string _ControllerName;
|
||||
private static TestContext _TestContext;
|
||||
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
#pragma warning restore
|
||||
|
||||
@ -23,17 +23,18 @@ public class UnitTestServiceShopOrderController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestServiceShopOrderController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.ServiceShopOrderController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IServiceShopOrderController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -43,36 +44,38 @@ public class UnitTestServiceShopOrderController
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
ServiceShopOrder[] serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null);
|
||||
Assert.IsNotNull(serviceShopOrders);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllServiceShopOrders()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
ServiceShopOrder[] serviceShopOrders;
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IServiceShopOrderRepository serviceShopOrderRepository = serviceProvider.GetRequiredService<IServiceShopOrderRepository>();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
ServiceShopOrder[]? serviceShopOrders;
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IServiceShopOrderRepository? serviceShopOrderRepository = serviceProvider?.GetRequiredService<IServiceShopOrderRepository>();
|
||||
Assert.IsTrue(serviceShopOrderRepository is not null);
|
||||
serviceShopOrders = await serviceShopOrderRepository.GetAllServiceShopOrders();
|
||||
Assert.IsTrue(serviceShopOrders is not null);
|
||||
serviceShopOrders = await serviceShopOrderRepository.GetServiceShopOrders("23188d3d-9b75-ed11-ab8b-0050568f2fc3");
|
||||
Assert.IsTrue(serviceShopOrders is not null && serviceShopOrders.Any());
|
||||
Assert.IsTrue(serviceShopOrders is not null && serviceShopOrders.Length != 0);
|
||||
Assert.IsNotNull(serviceShopOrders[0].ToString());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllServiceShopOrdersApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
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.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsTrue(serviceShopOrders.Length != 0);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user