Tests passed using Mock
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
@ -32,11 +31,11 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="Serilog" Version="3.0.1" />
|
||||
@ -46,12 +45,6 @@
|
||||
<ProjectReference Include="..\Server\OI.Metrology.Server.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\Server\appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\Server\appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\.Data\RdsMaxRepo.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
@ -13,10 +13,10 @@ public class UnitAwaitingDispoController
|
||||
|
||||
#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
|
||||
|
||||
@ -24,83 +24,87 @@ public class UnitAwaitingDispoController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitAwaitingDispoController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.AwaitingDispoController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IAwaitingDispoController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void Index()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IEnumerable<AwaitingDisposition> awaitingDispositions = metrologyRepository.GetAwaitingDisposition();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IEnumerable<AwaitingDisposition>? awaitingDispositions = metrologyRepository?.GetAwaitingDisposition();
|
||||
Assert.IsTrue(awaitingDispositions is not null);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public async Task IndexApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(IMetrologyRepository.GetAwaitingDisposition)}Api.json"), json);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void MarkAsReviewed()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
_ = metrologyRepository.UpdateReviewDate(toolTypeId: 1, headerId: 1, clearDate: false);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
_ = metrologyRepository?.UpdateReviewDate(toolTypeId: 1, headerId: 1, clearDate: false);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public async Task MarkAsReviewedApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/markasreviewed");
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void MarkAsAwaiting()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
int dateCleared = metrologyRepository.UpdateReviewDate(toolTypeId: 1, headerId: 1, clearDate: true);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
int? dateCleared = metrologyRepository?.UpdateReviewDate(toolTypeId: 1, headerId: 1, clearDate: true);
|
||||
Assert.IsTrue(dateCleared <= 1);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public async Task MarkAsAwaitingApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
_ = await httpClient.PostAsync($"api/{_ControllerName}/markasawaiting", null);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
using System.Text;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
@ -12,10 +13,10 @@ public class UnitInboundController
|
||||
|
||||
#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,8 +24,9 @@ public class UnitInboundController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitInboundController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.InboundController)[..^10];
|
||||
}
|
||||
|
||||
@ -38,9 +40,9 @@ public class UnitInboundController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IInboundController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -54,10 +56,11 @@ public class UnitInboundController
|
||||
[TestMethod]
|
||||
public async Task DataApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
_ = await httpClient.PostAsync($"api/{_ControllerName}/BioRad", GetStringContent());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -65,10 +68,11 @@ public class UnitInboundController
|
||||
[TestMethod]
|
||||
public async Task AttachFileApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
_ = await httpClient.PostAsync($"api/{_ControllerName}/BioRad/attachment", GetStringContent());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Server.Models;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
@ -13,10 +13,10 @@ public class UnitTestAppSettingsController
|
||||
|
||||
#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
|
||||
|
||||
@ -24,8 +24,9 @@ public class UnitTestAppSettingsController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestAppSettingsController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.AppSettingsController)[..^10];
|
||||
}
|
||||
|
||||
@ -39,88 +40,90 @@ public class UnitTestAppSettingsController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IAppSettingsController<object>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestConnectionString()
|
||||
{
|
||||
_Logger.Information("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.Information($"{_TestContext?.TestName} completed");
|
||||
_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", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppSettings()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
AppSettings appSettings = serviceProvider.GetRequiredService<AppSettings>();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
AppSettings? appSettings = serviceProvider?.GetRequiredService<AppSettings>();
|
||||
Assert.IsNotNull(appSettings);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetAppSettings()
|
||||
{
|
||||
_Logger.Information("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();
|
||||
_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.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAppSettingsApi()
|
||||
{
|
||||
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(IAppSettingsController<object>.Action.App);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}");
|
||||
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();
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetAppSettings)}.json"), json);
|
||||
Assert.IsNotNull(json);
|
||||
Assert.IsTrue(json != "[]");
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetBuildNumberAndGitCommitSeven()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IAppSettingsRepository<Server.Models.Binder.AppSettings> appSettingsRepository = serviceProvider.GetRequiredService<IAppSettingsRepository<Server.Models.Binder.AppSettings>>();
|
||||
string result = appSettingsRepository.GetBuildNumberAndGitCommitSeven();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IAppSettingsRepository<Server.Models.Binder.AppSettings>? appSettingsRepository = serviceProvider?.GetRequiredService<IAppSettingsRepository<Server.Models.Binder.AppSettings>>();
|
||||
string? result = appSettingsRepository?.GetBuildNumberAndGitCommitSeven();
|
||||
Assert.IsTrue(result is not null);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetBuildNumberAndGitCommitSevenApi()
|
||||
{
|
||||
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(IAppSettingsController<object>.Action.DevOps);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}");
|
||||
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();
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetBuildNumberAndGitCommitSeven)}.json"), json);
|
||||
Assert.IsNotNull(json);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
@ -12,10 +12,10 @@ public class UnitTestClientSettingsController
|
||||
|
||||
#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,38 +23,40 @@ public class UnitTestClientSettingsController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestClientSettingsController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.ClientSettingsController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IClientSettingsController<object>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetClientSettings()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IClientSettingsRepository clientSettingsRepository = serviceProvider.GetRequiredService<IClientSettingsRepository>();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IClientSettingsRepository? clientSettingsRepository = serviceProvider?.GetRequiredService<IClientSettingsRepository>();
|
||||
#if DEBUG
|
||||
List<string> clientSettings = clientSettingsRepository.GetClientSettings(null);
|
||||
List<string>? clientSettings = clientSettingsRepository?.GetClientSettings(null);
|
||||
Assert.IsTrue(clientSettings is not null);
|
||||
#endif
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetClientSettingsApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
#if DEBUG
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
string actionName = nameof(IClientSettingsController<object>.Action.Client);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}");
|
||||
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
|
||||
@ -64,25 +66,26 @@ public class UnitTestClientSettingsController
|
||||
Assert.IsNotNull(json);
|
||||
Assert.IsTrue(json != "[]");
|
||||
#endif
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetIpAddress()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IClientSettingsRepository clientSettingsRepository = serviceProvider.GetRequiredService<IClientSettingsRepository>();
|
||||
string? ipAddress = clientSettingsRepository.GetIpAddress(null);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IClientSettingsRepository? clientSettingsRepository = serviceProvider?.GetRequiredService<IClientSettingsRepository>();
|
||||
string? ipAddress = clientSettingsRepository?.GetIpAddress(null);
|
||||
Assert.IsTrue(ipAddress is not null);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetIpAddressApi()
|
||||
{
|
||||
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(IClientSettingsController<object>.Action.IP);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/{actionName}");
|
||||
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
|
||||
@ -90,7 +93,7 @@ public class UnitTestClientSettingsController
|
||||
string json = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetIpAddress)}.json"), json);
|
||||
Assert.IsNotNull(json);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
using System.Text;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
@ -13,10 +13,10 @@ public class UnitTestExportController
|
||||
|
||||
#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
|
||||
|
||||
@ -24,8 +24,9 @@ public class UnitTestExportController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestExportController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.ExportController)[..^10];
|
||||
}
|
||||
|
||||
@ -39,9 +40,9 @@ public class UnitTestExportController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IExportController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -54,142 +55,150 @@ public class UnitTestExportController
|
||||
[TestMethod]
|
||||
public void GetExport()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository exportRepository = serviceProvider.GetRequiredService<IExportRepository>();
|
||||
string result = exportRepository.GetExport(GetHeaderCommon());
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository? exportRepository = serviceProvider?.GetRequiredService<IExportRepository>();
|
||||
string? result = exportRepository?.GetExport(GetHeaderCommon());
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetExportApi()
|
||||
{
|
||||
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? result = await httpClient.GetStringAsync($"api/{_ControllerName}/export");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetExport)}.txt"), result);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostExportApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/export", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetHeaders()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository exportRepository = serviceProvider.GetRequiredService<IExportRepository>();
|
||||
Result<HeaderCommon[]> result = exportRepository.GetHeaders(GetHeaderCommon());
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository? exportRepository = serviceProvider?.GetRequiredService<IExportRepository>();
|
||||
Result<HeaderCommon[]>? result = exportRepository?.GetHeaders(GetHeaderCommon());
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetHeadersApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/headers");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaders)}.json"), json);
|
||||
Result<HeaderCommon[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostHeadersApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/headers", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetLogistics()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository exportRepository = serviceProvider.GetRequiredService<IExportRepository>();
|
||||
Result<HeaderCommon[]> result = exportRepository.GetLogistics(GetHeaderCommon());
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository? exportRepository = serviceProvider?.GetRequiredService<IExportRepository>();
|
||||
Result<HeaderCommon[]>? result = exportRepository?.GetLogistics(GetHeaderCommon());
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetLogisticsApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/logistics");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetLogistics)}.json"), json);
|
||||
Result<HeaderCommon[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostLogisticsApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/logistics", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetProcessDataStandardFormat()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository exportRepository = serviceProvider.GetRequiredService<IExportRepository>();
|
||||
string result = exportRepository.GetProcessDataStandardFormat(GetHeaderCommon());
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IExportRepository? exportRepository = serviceProvider?.GetRequiredService<IExportRepository>();
|
||||
string? result = exportRepository?.GetProcessDataStandardFormat(GetHeaderCommon());
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetProcessDataStandardFormatApi()
|
||||
{
|
||||
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? result = await httpClient.GetStringAsync($"api/{_ControllerName}/processDataStandardFormat");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetProcessDataStandardFormat)}.pdsf"), result);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task PostProcessDataStandardFormatApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"api/{_ControllerName}/processDataStandardFormat", GetStringContent());
|
||||
Assert.IsTrue(httpResponseMessage.StatusCode == System.Net.HttpStatusCode.OK);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -11,10 +11,10 @@ public class UnitTestISpreadingResistanceProfileController
|
||||
|
||||
#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
|
||||
|
||||
@ -22,9 +22,10 @@ public class UnitTestISpreadingResistanceProfileController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestISpreadingResistanceProfileController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
_ControllerName = nameof(Server.ApiControllers.InfinityQSController)[..^10];
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.SpreadingResistanceProfileController)[..^10];
|
||||
}
|
||||
|
||||
private static void NonThrowTryCatch()
|
||||
@ -37,16 +38,16 @@ public class UnitTestISpreadingResistanceProfileController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
Assert.AreEqual(IInfinityQSController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(ISpreadingResistanceProfileController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetSpreadingResistanceProfileServiceImageBytes()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
string directory = "D:/wwwRoot";
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
@ -54,13 +55,14 @@ public class UnitTestISpreadingResistanceProfileController
|
||||
if (File.Exists(file))
|
||||
{
|
||||
string json = File.ReadAllText(file);
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
ISpreadingResistanceProfileService spreadingResistanceProfileService = serviceProvider.GetRequiredService<ISpreadingResistanceProfileService>();
|
||||
byte[] bytes = spreadingResistanceProfileService.GetImageBytes(json);
|
||||
Assert.IsTrue(bytes.Any());
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
ISpreadingResistanceProfileService? spreadingResistanceProfileService = serviceProvider?.GetRequiredService<ISpreadingResistanceProfileService>();
|
||||
byte[]? bytes = spreadingResistanceProfileService?.GetImageBytes(json);
|
||||
Assert.IsTrue(bytes is not null);
|
||||
Assert.IsTrue(bytes.Length != 0);
|
||||
File.WriteAllBytes(Path.Combine(directory, "srp.png"), bytes);
|
||||
}
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class UnitTestInfinityQSController
|
||||
IInfinityQSRepository infinityQSRepository = serviceProvider.GetRequiredService<IInfinityQSRepository>();
|
||||
Result<InfinityQSBase[]> result = infinityQSRepository.GetData("1677273357");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result?.Results.Any());
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
Assert.IsNotNull(result?.Results[0].PR_NAME);
|
||||
Assert.IsNotNull(result?.Results[0].SE_SGTM);
|
||||
Assert.IsNotNull(result?.Results[0].SE_TSNO);
|
||||
@ -123,7 +123,7 @@ public class UnitTestInfinityQSController
|
||||
IInfinityQSRepository infinityQSRepository = serviceProvider.GetRequiredService<IInfinityQSRepository>();
|
||||
Result<InfinityQSDescriptor[]> result = infinityQSRepository.GetDescriptors("1677273357");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result?.Results.Any());
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
Assert.IsNotNull(result?.Results[0].SD_SGRP);
|
||||
Assert.IsNotNull(result?.Results[0].SD_TSNO);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -12,10 +12,10 @@ public class UnitTestInfinityQSV2Controller
|
||||
|
||||
#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,8 +23,9 @@ public class UnitTestInfinityQSV2Controller
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestInfinityQSV2Controller>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.InfinityQSV2Controller)[..^10];
|
||||
}
|
||||
|
||||
@ -38,21 +39,21 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IInfinityQSV2Controller<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetCommandText()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository infinityQSV2Repository = serviceProvider.GetRequiredService<IInfinityQSV2Repository>();
|
||||
string result = infinityQSV2Repository.GetCommandText("1677273357", "61", "CDE5", "5012", "575908", "");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService<IInfinityQSV2Repository>();
|
||||
string? result = infinityQSV2Repository?.GetCommandText("1677273357", "61", "CDE5", "5012", "575908", "");
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -62,12 +63,13 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public async Task GetCommandTextApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/commandText/?process=61&job=CDE5&part=5012&lot=575908&date_time=2023-02-24 15:15:00");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCommandText)}.sql"), json);
|
||||
Assert.IsNotNull(json);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -77,18 +79,18 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public void GetData()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository infinityQSV2Repository = serviceProvider.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSBaseV2[]> result = infinityQSV2Repository.GetData("1677273357");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSBaseV2[]>? result = infinityQSV2Repository?.GetData("1677273357");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result?.Results.Any());
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
Assert.IsNotNull(result?.Results[0].Process);
|
||||
Assert.IsNotNull(result?.Results[0].Variable);
|
||||
Assert.IsNotNull(result?.Results[0].SiteNumber);
|
||||
Assert.IsNotNull(result?.Results[0].VariableNumber);
|
||||
Assert.IsNotNull(result?.Results[0].SubGroupDateTime);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -98,14 +100,15 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public async Task GetDataApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357 575908_2023-02-24 14-18-05.txt/data");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/data");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json);
|
||||
Result<InfinityQSBaseV2[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSBaseV2[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -115,15 +118,15 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public void GetDescriptors()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository infinityQSV2Repository = serviceProvider.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSDescriptorV2[]> result = infinityQSV2Repository.GetDescriptors("1677273357");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSDescriptorV2[]>? result = infinityQSV2Repository?.GetDescriptors("1677273357");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result?.Results.Any());
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
Assert.IsNotNull(result?.Results[0].SubGroupId);
|
||||
Assert.IsNotNull(result?.Results[0].SiteNumber);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -133,14 +136,15 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public async Task GetDescriptorsApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357 575908_2023-02-24 14-18-05.txt/descriptors");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/descriptors");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetDescriptors)}.json"), json);
|
||||
Result<InfinityQSDescriptorV2[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSDescriptorV2[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -150,12 +154,12 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public void GetEvents()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository infinityQSV2Repository = serviceProvider.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSEventV2[]> result = infinityQSV2Repository.GetEvents("1677273357");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSEventV2[]>? result = infinityQSV2Repository?.GetEvents("1677273357");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -165,13 +169,14 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public async Task GetEventsApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/events");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetEvents)}.json"), json);
|
||||
Result<InfinityQSEvent[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSEvent[]>>(json);
|
||||
Result<InfinityQSEventV2[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSEventV2[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -181,12 +186,13 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public void GetHeader()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository infinityQSV2Repository = serviceProvider.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSBaseV2[]> result = infinityQSV2Repository.GetHeader("1677273357");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV2Repository? infinityQSV2Repository = serviceProvider?.GetRequiredService<IInfinityQSV2Repository>();
|
||||
Result<InfinityQSBaseV2[]>? result = infinityQSV2Repository?.GetHeader("1677273357");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsNotNull(result?.Results[0].Part);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -196,13 +202,15 @@ public class UnitTestInfinityQSV2Controller
|
||||
[TestMethod]
|
||||
public async Task GetHeaderApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1677273357/header");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeader)}.json"), json);
|
||||
Result<InfinityQSBaseV2[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSBaseV2[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsNotNull(result?.Results[0].Part);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
216
Tests/UnitTestInfinityQSV3Controller.cs
Normal file
216
Tests/UnitTestInfinityQSV3Controller.cs
Normal file
@ -0,0 +1,216 @@
|
||||
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 UnitTestInfinityQSV3Controller
|
||||
{
|
||||
|
||||
#pragma warning disable CS8618
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string _ControllerName;
|
||||
private static TestContext _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
#pragma warning restore
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.InfinityQSV3Controller)[..^10];
|
||||
}
|
||||
|
||||
private static void NonThrowTryCatch()
|
||||
{
|
||||
try
|
||||
{ throw new Exception(); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IInfinityQSV3Controller<string>.GetRouteName(), _ControllerName);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetCommandText()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService<IInfinityQSV3Repository>();
|
||||
string? result = infinityQSV3Repository?.GetCommandText("1698497987", "61", "CDE5", "5012", "575908", "");
|
||||
Assert.IsNotNull(result);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public async Task GetCommandTextApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/commandText/?process=61&job=CDE5&part=5012&lot=575908&date_time=2023-02-24 15:15:00");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCommandText)}.sql"), json);
|
||||
Assert.IsNotNull(json);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public void GetData()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService<IInfinityQSV3Repository>();
|
||||
Result<InfinityQSV3[]>? result = infinityQSV3Repository?.GetData("1698497987");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
Assert.IsNotNull(result?.Results[0].Process);
|
||||
Assert.IsNotNull(result?.Results[0].Variable);
|
||||
Assert.IsNotNull(result?.Results[0].SiteNumber);
|
||||
Assert.IsNotNull(result?.Results[0].VariableNumber);
|
||||
Assert.IsNotNull(result?.Results[0].SubGroupDateTime);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public async Task GetDataApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
//string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987 575908_2023-02-24 14-18-05.txt/data");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/data");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json);
|
||||
Result<InfinityQSV3[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSV3[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public void GetDescriptors()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService<IInfinityQSV3Repository>();
|
||||
Result<InfinityQSDescriptorV3[]>? result = infinityQSV3Repository?.GetDescriptors("1698497987");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
Assert.IsNotNull(result?.Results[0].SubGroupId);
|
||||
Assert.IsNotNull(result?.Results[0].SiteNumber);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public async Task GetDescriptorsApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
//string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987 575908_2023-02-24 14-18-05.txt/descriptors");
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/descriptors");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetDescriptors)}.json"), json);
|
||||
Result<InfinityQSDescriptorV3[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSDescriptorV3[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public void GetHeader()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService<IInfinityQSV3Repository>();
|
||||
Result<InfinityQSV3[]>? result = infinityQSV3Repository?.GetHeader("1698497987");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result?.Results[0].Part);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public async Task GetHeaderApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1698497987/header");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeader)}.json"), json);
|
||||
Result<InfinityQSV3[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<InfinityQSV3[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result?.Results[0].Part);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public void GetProductDataAverageSumOfDefectsProcessMeanProcessSigma()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IInfinityQSV3Repository? infinityQSV3Repository = serviceProvider?.GetRequiredService<IInfinityQSV3Repository>();
|
||||
string? result = infinityQSV3Repository?.GetProductDataAverageSumOfDefectsProcessMeanProcessSigma("41", "8IN_THIN ROTR");
|
||||
Assert.IsNotNull(result);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[Ignore]
|
||||
#endif
|
||||
[TestMethod]
|
||||
public async Task GetProductDataAverageSumOfDefectsProcessMeanProcessSigmaApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/41/product-data-average-sum-of-defects-process-mean-process-sigma?recipe=8IN_THIN ROTR");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetProductDataAverageSumOfDefectsProcessMeanProcessSigma)}.json"), result);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
}
|
71
Tests/UnitTestOpenInsightV1Controller.cs
Normal file
71
Tests/UnitTestOpenInsightV1Controller.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestOpenInsightV1Controller
|
||||
{
|
||||
|
||||
#pragma warning disable CS8618
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string _ControllerName;
|
||||
private static TestContext _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
#pragma warning restore
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.OpenInsightV1Controller)[..^10];
|
||||
}
|
||||
|
||||
private static void NonThrowTryCatch()
|
||||
{
|
||||
try
|
||||
{ throw new Exception(); }
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IOpenInsightV1Controller<string>.GetRouteName(), _ControllerName);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetTencorRun()
|
||||
{
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IOpenInsightV1Repository? openInsightRepository = serviceProvider?.GetRequiredService<IOpenInsightV1Repository>();
|
||||
string? result = openInsightRepository?.GetTencorRun("615071", "10/30/2023 06:48:34PM", "6IN_EPP ROTR");
|
||||
Assert.IsNotNull(result);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetTencorRunApi()
|
||||
{
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
string? result = await httpClient.GetStringAsync($"api/{_ControllerName}/615071/tencor-run?insert_date=10/30/2023 06:48:34PM&recipe=6IN_EPP ROTR");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetTencorRun)}.json"), result);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -12,10 +12,10 @@ public class UnitTestPinController
|
||||
|
||||
#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,41 +23,44 @@ public class UnitTestPinController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestPinController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.PinController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IPinController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetPinnedTable()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IPinRepository pinRepository = serviceProvider.GetRequiredService<IPinRepository>();
|
||||
Result<Pinned[]> result = pinRepository.GetPinnedTable(metrologyRepository, id: 1, cde_id: null, biorad_id: null, rds: null);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IPinRepository? pinRepository = serviceProvider?.GetRequiredService<IPinRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<Pinned[]>? result = pinRepository?.GetPinnedTable(metrologyRepository, id: 1, cde_id: null, biorad_id: null, rds: null);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetPinnedTableApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/-1/pinned");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetPinnedTable)}.json"), json);
|
||||
Result<Pinned[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<Pinned[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -12,10 +12,10 @@ public class UnitTestReactorController
|
||||
|
||||
#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,8 +23,9 @@ public class UnitTestReactorController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestReactorController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.ReactorsController)[..^10];
|
||||
}
|
||||
|
||||
@ -38,47 +39,48 @@ public class UnitTestReactorController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IReactorsController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetReactors()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IReactorsRepository reactorsRepository = serviceProvider.GetRequiredService<IReactorsRepository>();
|
||||
Result<int[]> result = reactorsRepository.EvenReactors();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IReactorsRepository? reactorsRepository = serviceProvider?.GetRequiredService<IReactorsRepository>();
|
||||
Result<int[]>? result = reactorsRepository?.EvenReactors();
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetReactorsApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/true/");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetReactors)}.json"), json);
|
||||
Result<int[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<int[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetKey()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IReactorsRepository reactorsRepository = serviceProvider.GetRequiredService<IReactorsRepository>();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IReactorsRepository? reactorsRepository = serviceProvider?.GetRequiredService<IReactorsRepository>();
|
||||
WorkMaterialOut workMaterialOut = new() { RunDataSheet = "123456", Username = "phares" };
|
||||
string? result = reactorsRepository.GetKey(workMaterialOut, save: false);
|
||||
string? result = reactorsRepository?.GetKey(workMaterialOut, save: false);
|
||||
Assert.IsNotNull(result);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using OI.Metrology.Shared.Services;
|
||||
using Serilog;
|
||||
using System.Data;
|
||||
using System.Net.Http.Json;
|
||||
|
||||
@ -15,10 +15,10 @@ public class UnitTestToolTypesController
|
||||
|
||||
#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
|
||||
|
||||
@ -26,8 +26,9 @@ public class UnitTestToolTypesController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestToolTypesController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.ToolTypesController)[..^10];
|
||||
}
|
||||
|
||||
@ -41,252 +42,274 @@ public class UnitTestToolTypesController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IToolTypesController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Index()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<ToolTypeNameId[]> result = toolTypesRepository.Index(metrologyRepository);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<ToolTypeNameId[]>? result = toolTypesRepository?.Index(metrologyRepository);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
Assert.IsTrue(result.Results.Length != 0);
|
||||
Assert.IsFalse(result.Results.All(l => l.ID == 0));
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task IndexApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(Index)}.json"), json);
|
||||
Result<ToolTypeNameId[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<ToolTypeNameId[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
Assert.IsTrue(result.Results.Length != 0);
|
||||
Assert.IsFalse(result.Results.All(l => l.ID == 0));
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetToolTypeMetadata()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<ToolTypeMetadataResult> result = toolTypesRepository.GetToolTypeMetadata(metrologyRepository, id: 1, sortby: string.Empty);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<ToolTypeMetadataResult>? result = toolTypesRepository?.GetToolTypeMetadata(metrologyRepository, id: 1, sortby: string.Empty);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Metadata);
|
||||
Assert.IsTrue(result.Results.Metadata.Any());
|
||||
Assert.IsTrue(result.Results.Metadata.Length != 0);
|
||||
Assert.IsFalse(result.Results.Metadata.All(l => l.ToolTypeID == 0));
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetToolTypeMetadataApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetToolTypeMetadata)}.json"), json);
|
||||
Result<ToolTypeMetadataResult>? result = System.Text.Json.JsonSerializer.Deserialize<Result<ToolTypeMetadataResult>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Metadata);
|
||||
Assert.IsTrue(result.Results.Metadata.Any());
|
||||
Assert.IsTrue(result.Results.Metadata.Length != 0);
|
||||
Assert.IsFalse(result.Results.Metadata.All(l => l.ToolTypeID == 0));
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetHeaders()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<DataTable> result = toolTypesRepository.GetHeaders(metrologyRepository, id: 1, datebegin: null, dateend: null, page: null, pagesize: null, headerid: null);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<DataTable>? result = toolTypesRepository?.GetHeaders(metrologyRepository, id: 1, datebegin: null, dateend: null, page: null, pagesize: null, headerid: null);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Rows.Count > 0);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetHeadersApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headers");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaders)}.json"), json);
|
||||
Result<DataTable>? result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<DataTable>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Rows.Count > 0);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetHeaderTitles()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<HeaderCommon[]> result = toolTypesRepository.GetHeaderTitles(metrologyRepository, id: -1, page: null, pagesize: null);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<HeaderCommon[]>? result = toolTypesRepository?.GetHeaderTitles(metrologyRepository, id: -1, page: null, pagesize: null);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsTrue(result?.Results.Length != 0);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetHeaderTitlesApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/-1/headertitles");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaderTitles)}.json"), json);
|
||||
Result<HeaderCommon[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<HeaderCommon[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsTrue(result.Results.Length != 0);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetHeaderFields()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<ColumnValue[]> result = toolTypesRepository.GetHeaderFields(metrologyRepository, id: 1, headerid: 1);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<ColumnValue[]>? result = toolTypesRepository?.GetHeaderFields(metrologyRepository, id: 1, headerid: 1);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsTrue(result.Results.Length != 0);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetHeaderFieldsApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headers/1/fields");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetHeaderFields)}.json"), json);
|
||||
Result<ColumnValue[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<ColumnValue[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsTrue(result.Results.Any());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
Assert.IsTrue(result.Results.Length != 0);
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GetData()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<DataTable> result = toolTypesRepository.GetData(metrologyRepository, id: 1, headerid: 1);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<DataTable>? result = toolTypesRepository?.GetData(metrologyRepository, id: 1, headerid: 1);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Rows.Count > 0);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetDataApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/headers/1/data");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetData)}.json"), json);
|
||||
Result<DataTable>? result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<DataTable>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Rows.Count > 0);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void GetExportData()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Result<DataTable> result = toolTypesRepository.GetExportData(metrologyRepository, toolTypeId: 1, datebegin: null, dateend: null);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Result<DataTable>? result = toolTypesRepository?.GetExportData(metrologyRepository, toolTypeId: 1, datebegin: null, dateend: null);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Rows.Count > 0);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public async Task GetExportDataApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/1/export");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetExportData)}.json"), json);
|
||||
Result<DataTable>? result = Newtonsoft.Json.JsonConvert.DeserializeObject<Result<DataTable>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
Assert.IsNotNull(result.Results.Rows.Count > 0);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void GetAttachment()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
int toolTypeId = 1;
|
||||
string tabletype = "data";
|
||||
string filename = "data.txt";
|
||||
string attachmentId = "ffdf5410-ca19-4097-bfa4-b398e236d07e";
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IAttachmentsService attachmentsService = serviceProvider.GetRequiredService<IAttachmentsService>();
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IAttachmentsService? attachmentsService = serviceProvider?.GetRequiredService<IAttachmentsService>();
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Assert.IsTrue(attachmentsService is not null);
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
Assert.IsTrue(toolTypesRepository is not null);
|
||||
(string? message, string? _, Stream? _) = toolTypesRepository.GetAttachment(metrologyRepository, attachmentsService, toolTypeId, tabletype, attachmentId, filename);
|
||||
Assert.IsTrue(message is null);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public async Task GetAttachmentApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/1/data/files/ffdf5410-ca19-4097-bfa4-b398e236d07e/data.txt");
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void OIExport()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IAttachmentsService attachmentsService = serviceProvider.GetRequiredService<IAttachmentsService>();
|
||||
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
|
||||
Server.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Server.Models.AppSettings>();
|
||||
string? message = toolTypesRepository.OIExport(metrologyRepository, attachmentsService, appSettings.AttachmentPath, appSettings.TableToPath, toolTypeId: 1, headerid: 1);
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IAttachmentsService? attachmentsService = serviceProvider?.GetRequiredService<IAttachmentsService>();
|
||||
IMetrologyRepository? metrologyRepository = serviceProvider?.GetRequiredService<IMetrologyRepository>();
|
||||
IToolTypesRepository? toolTypesRepository = serviceProvider?.GetRequiredService<IToolTypesRepository>();
|
||||
Server.Models.AppSettings? appSettings = serviceProvider?.GetRequiredService<Server.Models.AppSettings>();
|
||||
Assert.IsTrue(appSettings is not null);
|
||||
Assert.IsTrue(attachmentsService is not null);
|
||||
Assert.IsTrue(metrologyRepository is not null);
|
||||
string? message = toolTypesRepository?.OIExport(metrologyRepository, attachmentsService, appSettings.AttachmentPath, appSettings.TableToPath, toolTypeId: 1, headerid: 1);
|
||||
Assert.IsTrue(message is null);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public async Task OIExportApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/1/headers/1/oiexport");
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsTrue(httpClient is not null);
|
||||
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/1/headers/1/export");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OI.Metrology.Shared.DataModels;
|
||||
using OI.Metrology.Shared.Models.Stateless;
|
||||
using Serilog;
|
||||
|
||||
namespace OI.Metrology.Tests;
|
||||
|
||||
@ -12,10 +12,10 @@ public class UnitTestWorkMaterialController
|
||||
|
||||
#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,8 +23,9 @@ public class UnitTestWorkMaterialController
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestWorkMaterialController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.WorkMaterialController)[..^10];
|
||||
}
|
||||
|
||||
@ -38,9 +39,9 @@ public class UnitTestWorkMaterialController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(IWorkMaterialController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -50,12 +51,12 @@ public class UnitTestWorkMaterialController
|
||||
[TestMethod]
|
||||
public void GetCassette()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
IWorkMaterialRepository workMaterialRepository = serviceProvider.GetRequiredService<IWorkMaterialRepository>();
|
||||
Result<WorkMaterialV2[]> result = workMaterialRepository.GetCassette("O171927.1.37");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
IWorkMaterialRepository? workMaterialRepository = serviceProvider?.GetRequiredService<IWorkMaterialRepository>();
|
||||
Result<WorkMaterialV2[]>? result = workMaterialRepository?.GetCassette("O171927.1.37");
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -65,13 +66,14 @@ public class UnitTestWorkMaterialController
|
||||
[TestMethod]
|
||||
public async Task GetCassetteApi()
|
||||
{
|
||||
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? json = await httpClient.GetStringAsync($"api/{_ControllerName}/O171927.1.37/");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetCassette)}.json"), json);
|
||||
Result<WorkMaterialV2[]>? result = System.Text.Json.JsonSerializer.Deserialize<Result<WorkMaterialV2[]>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user