Creation
This commit is contained in:
1
Tests/.vscode/format-report.json
vendored
Normal file
1
Tests/.vscode/format-report.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[]
|
8
Tests/.vscode/settings.json
vendored
Normal file
8
Tests/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"coverage-gutters.coverageBaseDir": "../.vscode/TestResults/*",
|
||||
"cSpell.words": [
|
||||
"Contollers",
|
||||
"Serilog",
|
||||
"Setpoint"
|
||||
],
|
||||
}
|
42
Tests/Expose-MyIT.Tests.csproj
Normal file
42
Tests/Expose-MyIT.Tests.csproj
Normal file
@ -0,0 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<VSTestLogger>trx</VSTestLogger>
|
||||
<VSTestCollect>XPlat Code Coverage</VSTestCollect>
|
||||
<VSTestResultsDirectory>../.vscode/TestResults</VSTestResultsDirectory>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Shared\Expose-MyIT.Shared.csproj" />
|
||||
<ProjectReference Include="..\Server\Expose-MyIT.Server.csproj" />
|
||||
<ProjectReference Include="..\Shared\Expose-MyIT.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\Server\appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\Server\appsettings.Staging.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\Server\appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\Server\Data\Mike\ssa.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="..\Server\Data\Mike\service-shop.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
66
Tests/UnitTestAppSettingsController.cs
Normal file
66
Tests/UnitTestAppSettingsController.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace Expose.MyIT.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestAppSettingsController
|
||||
{
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string? _ControllerName;
|
||||
private static TestContext? _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestAppSettingsController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
_ControllerName = nameof(Server.Controllers.AppSettingsController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_Logger.Information("Starting Web Application");
|
||||
Assert.AreEqual(Shared.Models.Stateless.Methods.IAppSettingsController.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Get_ShouldReturn()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
Server.Models.AppSettings appSettings = serviceProvider.GetRequiredService<Server.Models.AppSettings>();
|
||||
Assert.IsNotNull(appSettings);
|
||||
if (appSettings.IsDevelopment)
|
||||
{
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}/");
|
||||
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
|
||||
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
|
||||
string result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
Assert.IsTrue(result.Contains(appSettings.Company));
|
||||
httpClient.Dispose();
|
||||
}
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
}
|
59
Tests/UnitTestClientSettingsController.cs
Normal file
59
Tests/UnitTestClientSettingsController.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace Expose.MyIT.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestClientSettingsController
|
||||
{
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string? _ControllerName;
|
||||
private static TestContext? _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestClientSettingsController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
_ControllerName = nameof(Server.Controllers.ClientSettingsController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_Logger.Information("Starting Web Application");
|
||||
Assert.AreEqual(Shared.Models.Stateless.Methods.IClientSettingsController.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Get_ShouldReturn()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}");
|
||||
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
|
||||
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
|
||||
string result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
Assert.IsNotNull(result);
|
||||
httpClient.Dispose();
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
}
|
96
Tests/UnitTestServiceShopOrderController.cs
Normal file
96
Tests/UnitTestServiceShopOrderController.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Expose.MyIT.Shared.Models.Methods;
|
||||
using Expose.MyIT.Shared.Models.Stateless.Methods;
|
||||
using Expose.MyIT.Shared.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace Expose.MyIT.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestServiceShopOrderController : IServiceShopOrder
|
||||
{
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string? _ControllerName;
|
||||
private static TestContext? _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestServiceShopOrderController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
_ControllerName = nameof(Server.Controllers.ServiceShopOrderController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_Logger.Information("Starting Web Application");
|
||||
Assert.AreEqual(IServiceShopOrderController.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestStatic_GetServiceShopOrders()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
IServiceShopOrder serviceShopOrder = this;
|
||||
ServiceShopOrder[] serviceShopOrders = serviceShopOrder.TestStatic_GetServiceShopOrders(null);
|
||||
Assert.IsNotNull(serviceShopOrders);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllServiceShopOrders_ShouldReturn()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_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 GetAllServiceShopOrders_API_ShouldReturn()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
string actionName = nameof(Server.Controllers.ServiceShopOrderController.GetAllServiceShopOrders)[3..];
|
||||
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();
|
||||
Assert.IsNotNull(result);
|
||||
httpClient.Dispose();
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
}
|
96
Tests/UnitTestSsaOrderController.cs
Normal file
96
Tests/UnitTestSsaOrderController.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Expose.MyIT.Shared.Models.Methods;
|
||||
using Expose.MyIT.Shared.Models.Stateless.Methods;
|
||||
using Expose.MyIT.Shared.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace Expose.MyIT.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestSsaOrderController : ISsaOrder
|
||||
{
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string? _ControllerName;
|
||||
private static TestContext? _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestSsaOrderController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
_ControllerName = nameof(Server.Controllers.SsaOrderController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_Logger.Information("Starting Web Application");
|
||||
Assert.AreEqual(ISsaOrderController.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestStatic_GetSsaOrders()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
ISsaOrder ssaOrder = this;
|
||||
SsaOrder[] ssaOrders = ssaOrder.TestStatic_GetSsaOrders(null);
|
||||
Assert.IsNotNull(ssaOrders);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllSsaOrders_ShouldReturn()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_Logger.Information("Starting Web Application");
|
||||
SsaOrder[] ssaOrders;
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
ISsaOrderRepository SsaOrderRepository = serviceProvider.GetRequiredService<ISsaOrderRepository>();
|
||||
ssaOrders = await SsaOrderRepository.GetAllSsaOrders();
|
||||
Assert.IsTrue(ssaOrders is not null);
|
||||
ssaOrders = await SsaOrderRepository.GetSsaOrders("f0998fc8-c724-ed11-a98b-0050568f497f");
|
||||
Assert.IsTrue(ssaOrders is not null && ssaOrders.Any());
|
||||
Assert.IsNotNull(ssaOrders[0].ToString());
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllSsaOrders_API_ShouldReturn()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
string actionName = nameof(Server.Controllers.SsaOrderController.GetAllSsaOrders)[3..];
|
||||
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();
|
||||
Assert.IsNotNull(result);
|
||||
httpClient.Dispose();
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
}
|
59
Tests/UnitTestWeatherForecastController.cs
Normal file
59
Tests/UnitTestWeatherForecastController.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Serilog;
|
||||
using System.Net;
|
||||
|
||||
namespace Expose.MyIT.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestWeatherForecastController
|
||||
{
|
||||
|
||||
private static ILogger? _Logger;
|
||||
private static string? _ControllerName;
|
||||
private static TestContext? _TestContext;
|
||||
private static WebApplicationFactory<Server.Program>? _WebApplicationFactory;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitAsync(TestContext testContext)
|
||||
{
|
||||
_TestContext = testContext;
|
||||
_Logger = Log.ForContext<UnitTestWeatherForecastController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
_ControllerName = nameof(Server.Controllers.WeatherForecastController)[..^10];
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
_Logger.Information("Starting Web Application");
|
||||
Assert.AreEqual(Shared.Models.Stateless.Methods.IWeatherForecastController.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetReactors_ShouldReturnAllWeatherForecast()
|
||||
{
|
||||
if (_Logger is null)
|
||||
throw new NullReferenceException(nameof(_Logger));
|
||||
if (_ControllerName is null)
|
||||
throw new NullReferenceException(nameof(_ControllerName));
|
||||
if (_WebApplicationFactory is null)
|
||||
throw new NullReferenceException(nameof(_WebApplicationFactory));
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpResponseMessage httpResponseMessage = await httpClient.GetAsync($"api/{_ControllerName}");
|
||||
Assert.AreEqual(HttpStatusCode.OK, httpResponseMessage.StatusCode);
|
||||
Assert.AreEqual("application/json; charset=utf-8", httpResponseMessage.Content.Headers.ContentType?.ToString());
|
||||
string result = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
Assert.IsNotNull(result);
|
||||
httpClient.Dispose();
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
}
|
||||
|
||||
}
|
1
Tests/Usings.cs
Normal file
1
Tests/Usings.cs
Normal file
@ -0,0 +1 @@
|
||||
global using Microsoft.VisualStudio.TestTools.UnitTesting;
|
Reference in New Issue
Block a user