TargetFramework update,

reference updates and added tests for Viewer
This commit is contained in:
2023-01-06 21:17:30 -07:00
parent 791724fdd4
commit f0c2140f93
82 changed files with 10187 additions and 1052 deletions

View File

@ -58,7 +58,9 @@ public class AppSettings
public static Models.AppSettings Get(IConfigurationRoot configurationRoot)
{
Models.AppSettings result;
AppSettings appSettings = configurationRoot.Get<AppSettings>();
AppSettings? appSettings = configurationRoot.Get<AppSettings>();
if (appSettings is null)
throw new NullReferenceException(nameof(appSettings));
result = Get(appSettings);
return result;
}

View File

@ -5,7 +5,7 @@
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<VSTestLogger>trx</VSTestLogger>
@ -27,29 +27,29 @@
<DefineConstants>Linux</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<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.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\Archive\Archive.csproj" />
<ProjectReference Include="..\Shared\OI.Metrology.Shared.csproj" />
<ProjectReference Include="..\Viewer\OI.Metrology.Viewer.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="..\Archive\appsettings.json">
<None Include="..\Viewer\appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\Archive\appsettings.Development.json">
<None Include="..\Viewer\appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="..\.Data\RdsMaxRepo.json">

View File

@ -0,0 +1,99 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using OI.Metrology.Shared.DataModels;
using OI.Metrology.Shared.Models.Stateless;
using Serilog;
using System.Net.Http.Json;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitAwaitingDispoController
{
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Viewer.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_Logger = Log.ForContext<UnitAwaitingDispoController>();
_WebApplicationFactory = new WebApplicationFactory<Viewer.Program>();
_ControllerName = nameof(Viewer.ApiControllers.ToolTypesController)[..^10];
}
[TestMethod]
public void TestControllerName()
{
_Logger.Information("Starting Web Application");
Assert.AreEqual(IToolTypesController<string>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void Index()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
IEnumerable<AwaitingDispo> awaitingDispos = metrologyRepository.GetAwaitingDispo();
Assert.IsTrue(awaitingDispos is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task IndexApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.PostAsync($"api/{_ControllerName}", null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void MarkAsReviewed()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
_ = metrologyRepository.UpdateReviewDate(toolTypeId: 0, headerId: 0, clearDate: false);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task MarkAsReviewedApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/markasreviewed");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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: 0, headerId: 0, clearDate: true);
Assert.IsTrue(dateCleared <= 1);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task MarkAsAwaitingApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.PostAsync($"api/{_ControllerName}/markasawaiting", null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
}

View File

@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Mvc.Testing;
using OI.Metrology.Shared.Models.Stateless;
using Serilog;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitInboundController
{
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Viewer.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_Logger = Log.ForContext<UnitInboundController>();
_WebApplicationFactory = new WebApplicationFactory<Viewer.Program>();
_ControllerName = nameof(Viewer.ApiControllers.ToolTypesController)[..^10];
}
[TestMethod]
public void TestControllerName()
{
_Logger.Information("Starting Web Application");
Assert.AreEqual(IToolTypesController<string>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task DataApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.PostAsync($"api/{_ControllerName}/a", null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task AttachFileApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.PostAsync($"api/{_ControllerName}/a/attachment", null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
}

View File

@ -0,0 +1,102 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using OI.Metrology.Shared.Models.Stateless;
using Serilog;
using System.Net;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestAppSettingsController
{
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Viewer.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_Logger = Log.ForContext<UnitTestAppSettingsController>();
_WebApplicationFactory = new WebApplicationFactory<Viewer.Program>();
_ControllerName = nameof(Viewer.ApiControllers.AppSettingsController)[..^10];
}
[TestMethod]
public void TestControllerName()
{
_Logger.Information("Starting Web Application");
Assert.AreEqual(IAppSettingsController<object>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void AppSettings()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
Viewer.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Viewer.Models.AppSettings>();
Assert.IsNotNull(appSettings);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetAppSettings()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IAppSettingsRepository appSettingsRepository = serviceProvider.GetRequiredService<IAppSettingsRepository>();
List<string> collection = appSettingsRepository.GetAppSettings();
Assert.IsTrue(collection is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAppSettingsApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IAppSettingsController<object>.Action.App);
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 result = await httpResponseMessage.Content.ReadAsStringAsync();
httpClient.Dispose();
Assert.IsNotNull(result);
Assert.IsTrue(result != "[]");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetBuildNumberAndGitCommitSeven()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IAppSettingsRepository appSettingsRepository = serviceProvider.GetRequiredService<IAppSettingsRepository>();
string result = appSettingsRepository.GetBuildNumberAndGitCommitSeven();
Assert.IsTrue(result is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetBuildNumberAndGitCommitSevenApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IAppSettingsController<object>.Action.DevOps);
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 result = await httpResponseMessage.Content.ReadAsStringAsync();
httpClient.Dispose();
Assert.IsNotNull(result);
_Logger.Information($"{_TestContext?.TestName} completed");
}
}

View File

@ -1,87 +1,87 @@
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OI.Metrology.Archive.Repositories;
using OI.Metrology.Shared.Models;
using OI.Metrology.Shared.Repositories;
using OI.Metrology.Tests.Models;
using Serilog;
using System.Reflection;
using System.Text.Json;
// using Microsoft.Extensions.Caching.Memory;
// using Microsoft.Extensions.Configuration;
// using Microsoft.Extensions.DependencyInjection;
// using OI.Metrology.Archive.Repositories;
// using OI.Metrology.Shared.Models;
// using OI.Metrology.Shared.Repositories;
// using OI.Metrology.Tests.Models;
// using Serilog;
// using System.Reflection;
// using System.Text.Json;
namespace OI.Metrology.Tests;
// namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestArchive
{
// [TestClass]
// public class UnitTestArchive
// {
private readonly ILogger _Logger;
private readonly AppSettings _AppSettings;
private readonly string _WorkingDirectory;
private readonly IMemoryCache? _MemoryCache;
private readonly IConfigurationRoot _ConfigurationRoot;
// private readonly ILogger _Logger;
// private readonly AppSettings _AppSettings;
// private readonly string _WorkingDirectory;
// private readonly IMemoryCache? _MemoryCache;
// private readonly IConfigurationRoot _ConfigurationRoot;
public UnitTestArchive()
{
ILogger logger;
AppSettings appSettings;
string workingDirectory;
IConfigurationRoot configurationRoot;
LoggerConfiguration loggerConfiguration = new();
Assembly assembly = Assembly.GetExecutingAssembly();
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile("appsettings.Development.json");
configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
Log.Logger = loggerConfiguration.CreateLogger();
logger = Log.ForContext<UnitTestArchive>();
logger.Information("Complete");
ServiceCollection services = new();
ServiceProvider serviceProvider = services.BuildServiceProvider();
_ = services.AddMemoryCache();
_MemoryCache = serviceProvider.GetService<IMemoryCache>();
_Logger = logger;
_AppSettings = appSettings;
_WorkingDirectory = workingDirectory;
_ConfigurationRoot = configurationRoot;
}
// public UnitTestArchive()
// {
// ILogger logger;
// AppSettings appSettings;
// string workingDirectory;
// IConfigurationRoot configurationRoot;
// LoggerConfiguration loggerConfiguration = new();
// Assembly assembly = Assembly.GetExecutingAssembly();
// IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
// .AddEnvironmentVariables()
// .AddJsonFile("appsettings.Development.json");
// configurationRoot = configurationBuilder.Build();
// appSettings = Models.Binder.AppSettings.Get(configurationRoot);
// workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
// Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
// _ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
// Log.Logger = loggerConfiguration.CreateLogger();
// logger = Log.ForContext<UnitTestArchive>();
// logger.Information("Complete");
// ServiceCollection services = new();
// ServiceProvider serviceProvider = services.BuildServiceProvider();
// _ = services.AddMemoryCache();
// _MemoryCache = serviceProvider.GetService<IMemoryCache>();
// _Logger = logger;
// _AppSettings = appSettings;
// _WorkingDirectory = workingDirectory;
// _ConfigurationRoot = configurationRoot;
// }
[TestMethod]
public void TestMethodNull()
{
Assert.IsFalse(_Logger is null);
Assert.IsFalse(_AppSettings is null);
Assert.IsFalse(_WorkingDirectory is null);
Assert.IsFalse(_ConfigurationRoot is null);
}
// [TestMethod]
// public void TestMethodNull()
// {
// Assert.IsFalse(_Logger is null);
// Assert.IsFalse(_AppSettings is null);
// Assert.IsFalse(_WorkingDirectory is null);
// Assert.IsFalse(_ConfigurationRoot is null);
// }
[TestMethod]
public void TestMethodArchive()
{
Assert.IsFalse(_Logger is null);
Assert.IsFalse(_AppSettings is null);
Assert.IsFalse(_WorkingDirectory is null);
Assert.IsFalse(_ConfigurationRoot is null);
}
// [TestMethod]
// public void TestMethodArchive()
// {
// Assert.IsFalse(_Logger is null);
// Assert.IsFalse(_AppSettings is null);
// Assert.IsFalse(_WorkingDirectory is null);
// Assert.IsFalse(_ConfigurationRoot is null);
// }
[TestMethod]
public void TestMethodArchiveJson()
{
string json;
string jsonFile = Path.Combine(AppContext.BaseDirectory, "RdsMaxRepo.json");
Assert.IsTrue(File.Exists(jsonFile));
json = JsonSerializer.Serialize(_AppSettings);
IRdsMaxRepo rdsMaxRepo = new RdsMaxRepo(json, _MemoryCache);
json = File.ReadAllText(jsonFile);
Shared.DataModels.RDS.Max[]? collection = JsonSerializer.Deserialize<Shared.DataModels.RDS.Max[]>(json);
if (collection is null)
throw new NullReferenceException(nameof(collection));
List<string[]> data = rdsMaxRepo.Convert(collection);
Assert.IsTrue(data.Any());
}
// [TestMethod]
// public void TestMethodArchiveJson()
// {
// string json;
// string jsonFile = Path.Combine(AppContext.BaseDirectory, "RdsMaxRepo.json");
// Assert.IsTrue(File.Exists(jsonFile));
// json = JsonSerializer.Serialize(_AppSettings);
// IRdsMaxRepo rdsMaxRepo = new RdsMaxRepo(json, _MemoryCache);
// json = File.ReadAllText(jsonFile);
// Shared.DataModels.RDS.Max[]? collection = JsonSerializer.Deserialize<Shared.DataModels.RDS.Max[]>(json);
// if (collection is null)
// throw new NullReferenceException(nameof(collection));
// List<string[]> data = rdsMaxRepo.Convert(collection);
// Assert.IsTrue(data.Any());
// }
}
// }

View File

@ -0,0 +1,92 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using OI.Metrology.Shared.Models.Stateless;
using Serilog;
using System.Net;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestClientSettingsController
{
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Viewer.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_Logger = Log.ForContext<UnitTestClientSettingsController>();
_WebApplicationFactory = new WebApplicationFactory<Viewer.Program>();
_ControllerName = nameof(Viewer.ApiControllers.ClientSettingsController)[..^10];
}
[TestMethod]
public void TestControllerName()
{
_Logger.Information("Starting Web Application");
Assert.AreEqual(IClientSettingsController<object>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetClientSettings()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IClientSettingsRepository clientSettingsRepository = serviceProvider.GetRequiredService<IClientSettingsRepository>();
List<string> clientSettings = clientSettingsRepository.GetClientSettings(null);
Assert.IsTrue(clientSettings is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetClientSettingsApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IClientSettingsController<object>.Action.Client);
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 result = await httpResponseMessage.Content.ReadAsStringAsync();
httpClient.Dispose();
Assert.IsNotNull(result);
Assert.IsTrue(result != "[]");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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);
Assert.IsTrue(ipAddress is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetIpAddressApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IClientSettingsController<object>.Action.IP);
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 result = await httpResponseMessage.Content.ReadAsStringAsync();
httpClient.Dispose();
Assert.IsNotNull(result);
_Logger.Information($"{_TestContext?.TestName} completed");
}
}

View File

@ -1,52 +0,0 @@
using Microsoft.Extensions.Configuration;
using OI.Metrology.Shared.Models;
using OI.Metrology.Tests.Models;
using Serilog;
using System.Reflection;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestExample
{
private readonly ILogger _Logger;
private readonly AppSettings _AppSettings;
private readonly string _WorkingDirectory;
private readonly IConfigurationRoot _ConfigurationRoot;
public UnitTestExample()
{
ILogger logger;
AppSettings appSettings;
string workingDirectory;
IConfigurationRoot configurationRoot;
LoggerConfiguration loggerConfiguration = new();
Assembly assembly = Assembly.GetExecutingAssembly();
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile("appsettings.Development.json");
configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
Log.Logger = loggerConfiguration.CreateLogger();
logger = Log.ForContext<UnitTestExample>();
logger.Information("Complete");
_Logger = logger;
_AppSettings = appSettings;
_WorkingDirectory = workingDirectory;
_ConfigurationRoot = configurationRoot;
}
[TestMethod]
public void TestMethodNull()
{
Assert.IsFalse(_Logger is null);
Assert.IsFalse(_AppSettings is null);
Assert.IsFalse(_WorkingDirectory is null);
Assert.IsFalse(_ConfigurationRoot is null);
}
}

View File

@ -1,109 +1,109 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System.Net;
// using Microsoft.AspNetCore.Mvc.Testing;
// using Microsoft.Extensions.DependencyInjection;
// using Serilog;
// using System.Net;
namespace OI.Metrology.Tests;
// namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestReactorController
{
// [TestClass]
// public class UnitTestReactorController
// {
private static TestContext? _TestContext;
private static WebApplicationFactory<Archive.Program>? _WebApplicationFactory;
// private static TestContext? _TestContext;
// private static WebApplicationFactory<Archive.Program>? _WebApplicationFactory;
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_WebApplicationFactory = new WebApplicationFactory<Archive.Program>();
}
// [ClassInitialize]
// public static void ClassInitAsync(TestContext testContext)
// {
// _TestContext = testContext;
// _WebApplicationFactory = new WebApplicationFactory<Archive.Program>();
// }
[TestMethod]
public async Task GetReactors_ShouldReturnAllReactorsAsync()
{
HttpResponseMessage httpResponseMessage;
if (_WebApplicationFactory is null)
throw new NullReferenceException(nameof(_WebApplicationFactory));
HttpClient httpClient = _WebApplicationFactory.CreateClient();
ILogger log = Log.ForContext<UnitTestReactorController>();
log.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
Archive.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Archive.Models.AppSettings>();
httpResponseMessage = await httpClient.GetAsync($"api/{nameof(Archive.ApiContollers.ReactorsController)[..^10]}/true");
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
httpResponseMessage = await httpClient.GetAsync($"api/{nameof(Archive.ApiContollers.ReactorsController)[..^10]}/false");
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
// string result = await httpResponseMessage.Content.ReadAsStringAsync();
// Assert.AreEqual("\"Sample Name 1\"", result);
httpClient.Dispose();
log.Information($"{_TestContext?.TestName} completed");
}
// [TestMethod]
// public async Task GetReactors_ShouldReturnAllReactorsAsync()
// {
// HttpResponseMessage httpResponseMessage;
// if (_WebApplicationFactory is null)
// throw new NullReferenceException(nameof(_WebApplicationFactory));
// HttpClient httpClient = _WebApplicationFactory.CreateClient();
// ILogger log = Log.ForContext<UnitTestReactorController>();
// log.Information("Starting Web Application");
// IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
// Archive.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Archive.Models.AppSettings>();
// httpResponseMessage = await httpClient.GetAsync($"api/{nameof(Archive.ApiControllers.ReactorsController)[..^10]}/true");
// Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
// Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
// httpResponseMessage = await httpClient.GetAsync($"api/{nameof(Archive.ApiControllers.ReactorsController)[..^10]}/false");
// Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
// // string result = await httpResponseMessage.Content.ReadAsStringAsync();
// // Assert.AreEqual("\"Sample Name 1\"", result);
// httpClient.Dispose();
// log.Information($"{_TestContext?.TestName} completed");
// }
// [TestMethod]
// public void GetAllProducts_ShouldReturnAllProducts()
// {
// var testProducts = GetTestProducts();
// var controller = new OI.Metrology.Archive.ApiContollers.ReactorsController(testProducts);
// // [TestMethod]
// // public void GetAllProducts_ShouldReturnAllProducts()
// // {
// // var testProducts = GetTestProducts();
// // var controller = new OI.Metrology.Archive.ApiControllers.ReactorsController(testProducts);
// var result = controller.GetAllProducts() as List<Product>;
// Assert.AreEqual(testProducts.Count, result.Count);
// }
// // var result = controller.GetAllProducts() as List<Product>;
// // Assert.AreEqual(testProducts.Count, result.Count);
// // }
// [TestMethod]
// public async Task GetAllProductsAsync_ShouldReturnAllProducts()
// {
// var testProducts = GetTestProducts();
// var controller = new OI.Metrology.Archive.ApiContollers.ReactorsController(testProducts);
// // [TestMethod]
// // public async Task GetAllProductsAsync_ShouldReturnAllProducts()
// // {
// // var testProducts = GetTestProducts();
// // var controller = new OI.Metrology.Archive.ApiControllers.ReactorsController(testProducts);
// var result = await controller.GetAllProductsAsync() as List<Product>;
// Assert.AreEqual(testProducts.Count, result.Count);
// }
// // var result = await controller.GetAllProductsAsync() as List<Product>;
// // Assert.AreEqual(testProducts.Count, result.Count);
// // }
// [TestMethod]
// public void GetProduct_ShouldReturnCorrectProduct()
// {
// var testProducts = GetTestProducts();
// var controller = new OI.Metrology.Archive.ApiContollers.ReactorsController(testProducts);
// // [TestMethod]
// // public void GetProduct_ShouldReturnCorrectProduct()
// // {
// // var testProducts = GetTestProducts();
// // var controller = new OI.Metrology.Archive.ApiControllers.ReactorsController(testProducts);
// var result = controller.GetProduct(4) as OkNegotiatedContentResult<Product>;
// Assert.IsNotNull(result);
// Assert.AreEqual(testProducts[3].Name, result.Content.Name);
// }
// // var result = controller.GetProduct(4) as OkNegotiatedContentResult<Product>;
// // Assert.IsNotNull(result);
// // Assert.AreEqual(testProducts[3].Name, result.Content.Name);
// // }
// [TestMethod]
// public async Task GetProductAsync_ShouldReturnCorrectProduct()
// {
// var testProducts = GetTestProducts();
// var controller = new OI.Metrology.Archive.ApiContollers.ReactorsController(testProducts);
// // [TestMethod]
// // public async Task GetProductAsync_ShouldReturnCorrectProduct()
// // {
// // var testProducts = GetTestProducts();
// // var controller = new OI.Metrology.Archive.ApiControllers.ReactorsController(testProducts);
// var result = await controller.GetProductAsync(4) as OkNegotiatedContentResult<Product>;
// Assert.IsNotNull(result);
// Assert.AreEqual(testProducts[3].Name, result.Content.Name);
// }
// // var result = await controller.GetProductAsync(4) as OkNegotiatedContentResult<Product>;
// // Assert.IsNotNull(result);
// // Assert.AreEqual(testProducts[3].Name, result.Content.Name);
// // }
// [TestMethod]
// public void GetProduct_ShouldNotFindProduct()
// {
// var controller = new OI.Metrology.Archive.ApiContollers.ReactorsController(GetTestProducts());
// // [TestMethod]
// // public void GetProduct_ShouldNotFindProduct()
// // {
// // var controller = new OI.Metrology.Archive.ApiControllers.ReactorsController(GetTestProducts());
// var result = controller.GetProduct(999);
// Assert.IsInstanceOfType(result, typeof(NotFoundResult));
// }
// // var result = controller.GetProduct(999);
// // Assert.IsInstanceOfType(result, typeof(NotFoundResult));
// // }
// private List<Product> GetTestProducts()
// {
// var testProducts = new List<Product>();
// testProducts.Add(new Product { Id = 1, Name = "Demo1", Price = 1 });
// testProducts.Add(new Product { Id = 2, Name = "Demo2", Price = 3.75M });
// testProducts.Add(new Product { Id = 3, Name = "Demo3", Price = 16.99M });
// testProducts.Add(new Product { Id = 4, Name = "Demo4", Price = 11.00M });
// // private List<Product> GetTestProducts()
// // {
// // var testProducts = new List<Product>();
// // testProducts.Add(new Product { Id = 1, Name = "Demo1", Price = 1 });
// // testProducts.Add(new Product { Id = 2, Name = "Demo2", Price = 3.75M });
// // testProducts.Add(new Product { Id = 3, Name = "Demo3", Price = 16.99M });
// // testProducts.Add(new Product { Id = 4, Name = "Demo4", Price = 11.00M });
// return testProducts;
// }
// // return testProducts;
// // }
[ClassCleanup]
public static void ClassCleanup() => _WebApplicationFactory?.Dispose();
// [ClassCleanup]
// public static void ClassCleanup() => _WebApplicationFactory?.Dispose();
}
// }

View File

@ -0,0 +1,77 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.ViewModels;
using Serilog;
using System.Net.Http.Json;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestServiceShopOrderController
{
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Viewer.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_Logger = Log.ForContext<UnitTestServiceShopOrderController>();
_WebApplicationFactory = new WebApplicationFactory<Viewer.Program>();
_ControllerName = nameof(Viewer.ApiControllers.ServiceShopOrderController)[..^10];
}
[TestMethod]
public void TestControllerName()
{
_Logger.Information("Starting Web Application");
Assert.AreEqual(IServiceShopOrderController<string>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetServiceShopOrders()
{
if (_Logger is null)
throw new NullReferenceException(nameof(_Logger));
ServiceShopOrder[] serviceShopOrders = IServiceShopOrder.GetServiceShopOrders(null);
Assert.IsNotNull(serviceShopOrders);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAllServiceShopOrders()
{
_Logger.Information("Starting Web Application");
ServiceShopOrder[] serviceShopOrders;
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IServiceShopOrderRepository serviceShopOrderRepository = serviceProvider.GetRequiredService<IServiceShopOrderRepository>();
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.IsNotNull(serviceShopOrders[0].ToString());
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAllServiceShopOrdersApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
string actionName = nameof(IServiceShopOrderController<object>.Action.All);
ServiceShopOrder[]? serviceShopOrders = await httpClient.GetFromJsonAsync<ServiceShopOrder[]>($"api/{_ControllerName}/{actionName}");
Assert.IsNotNull(serviceShopOrders);
Assert.IsTrue(serviceShopOrders.Any());
_Logger.Information($"{_TestContext?.TestName} completed");
}
}

View File

@ -0,0 +1,210 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using OI.Metrology.Shared.Models.Stateless;
using OI.Metrology.Shared.Services;
using Serilog;
using System.Net.Http.Json;
namespace OI.Metrology.Tests;
[TestClass]
public class UnitTestToolTypesController
{
#pragma warning disable CS8618
private static ILogger _Logger;
private static string _ControllerName;
private static TestContext _TestContext;
private static WebApplicationFactory<Viewer.Program> _WebApplicationFactory;
#pragma warning restore
[ClassInitialize]
public static void ClassInitAsync(TestContext testContext)
{
_TestContext = testContext;
_Logger = Log.ForContext<UnitTestToolTypesController>();
_WebApplicationFactory = new WebApplicationFactory<Viewer.Program>();
_ControllerName = nameof(Viewer.ApiControllers.ToolTypesController)[..^10];
}
[TestMethod]
public void TestControllerName()
{
_Logger.Information("Starting Web Application");
Assert.AreEqual(IToolTypesController<string>.GetRouteName(), _ControllerName);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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>();
object @object = toolTypesRepository.Index(metrologyRepository);
Assert.IsTrue(@object is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task IndexApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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>();
object @object = toolTypesRepository.GetToolTypeMetadata(metrologyRepository, id: 0, sortby: string.Empty);
Assert.IsTrue(@object is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetToolTypeMetadataApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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>();
string json = toolTypesRepository.GetHeaders(metrologyRepository, id: 0, datebegin: null, dateend: null, page: null, pagesize: null, headerid: null);
Assert.IsTrue(json is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetHeadersApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0/headers");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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>();
string json = toolTypesRepository.GetHeaderTitles(metrologyRepository, id: 0, page: null, pagesize: null);
Assert.IsTrue(json is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetHeaderTitlesApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0/headertitles");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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>();
string json = toolTypesRepository.GetHeaderFields(metrologyRepository, id: 0, headerid: 0);
Assert.IsTrue(json is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetHeaderFieldsApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0/headers/0/fields");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[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>();
string json = toolTypesRepository.GetData(metrologyRepository, id: 0, headerid: 0);
Assert.IsTrue(json is not null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetDataApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0/headers/data");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void GetAttachment()
{
_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>();
(string? message, string? _, Stream? _) = toolTypesRepository.GetAttachment(metrologyRepository, attachmentsService, toolTypeId: 0, string.Empty, string.Empty, string.Empty);
Assert.IsTrue(message is null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task GetAttachmentApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0/0/files/0/a.txt");
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public void OIExport()
{
_Logger.Information("Starting Web Application");
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
IMetrologyRepository metrologyRepository = serviceProvider.GetRequiredService<IMetrologyRepository>();
IToolTypesRepository toolTypesRepository = serviceProvider.GetRequiredService<IToolTypesRepository>();
Viewer.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Viewer.Models.AppSettings>();
Exception? exception = toolTypesRepository.OIExport(metrologyRepository, appSettings.OIExportPath, toolTypeId: 0, headerid: 0);
Assert.IsTrue(exception is null);
_Logger.Information($"{_TestContext?.TestName} completed");
}
[TestMethod]
public async Task OIExportApi()
{
HttpClient httpClient = _WebApplicationFactory.CreateClient();
_Logger.Information("Starting Web Application");
_ = await httpClient.GetFromJsonAsync<object>($"api/{_ControllerName}/0/headers/0/oiexport");
_Logger.Information($"{_TestContext?.TestName} completed");
}
}