Added test for APIs
This commit is contained in:
parent
a0c3e66dc1
commit
b428464a02
@ -10,8 +10,7 @@ public record AppSettings(string BuildNumber,
|
|||||||
bool IsDevelopment,
|
bool IsDevelopment,
|
||||||
bool IsStaging,
|
bool IsStaging,
|
||||||
string MonAResource,
|
string MonAResource,
|
||||||
string MonASite,
|
string MonASite)
|
||||||
string URLs)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -17,7 +17,6 @@ public class AppSettings
|
|||||||
[Display(Name = "Is Staging"), Required] public bool? IsStaging { get; set; }
|
[Display(Name = "Is Staging"), Required] public bool? IsStaging { get; set; }
|
||||||
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
||||||
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
||||||
[Display(Name = "URLs"), Required] public string URLs { get; set; }
|
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
@ -50,8 +49,6 @@ public class AppSettings
|
|||||||
throw new NullReferenceException(nameof(MonAResource));
|
throw new NullReferenceException(nameof(MonAResource));
|
||||||
if (appSettings.MonASite is null)
|
if (appSettings.MonASite is null)
|
||||||
throw new NullReferenceException(nameof(MonASite));
|
throw new NullReferenceException(nameof(MonASite));
|
||||||
if (appSettings.URLs is null)
|
|
||||||
throw new NullReferenceException(nameof(URLs));
|
|
||||||
result = new(
|
result = new(
|
||||||
appSettings.BuildNumber,
|
appSettings.BuildNumber,
|
||||||
appSettings.Company,
|
appSettings.Company,
|
||||||
@ -61,8 +58,7 @@ public class AppSettings
|
|||||||
appSettings.IsDevelopment.Value,
|
appSettings.IsDevelopment.Value,
|
||||||
appSettings.IsStaging.Value,
|
appSettings.IsStaging.Value,
|
||||||
appSettings.MonAResource,
|
appSettings.MonAResource,
|
||||||
appSettings.MonASite,
|
appSettings.MonASite);
|
||||||
appSettings.URLs);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@ using ReportingServices.API.Models;
|
|||||||
using ReportingServices.Shared.Repositories;
|
using ReportingServices.Shared.Repositories;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
internal class Program
|
namespace ReportingServices.API;
|
||||||
|
|
||||||
|
public class Program
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -10,7 +12,7 @@ internal class Program
|
|||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
_ = builder.Configuration.AddUserSecrets<Program>();
|
_ = builder.Configuration.AddUserSecrets<Program>();
|
||||||
AppSettings appSettings = ReportingServices.API.Models.Binder.AppSettings.Get(builder.Configuration);
|
AppSettings appSettings = Models.Binder.AppSettings.Get(builder.Configuration);
|
||||||
Environment.SetEnvironmentVariable("workingDirectory", appSettings.LoggingDirectory);
|
Environment.SetEnvironmentVariable("workingDirectory", appSettings.LoggingDirectory);
|
||||||
_ = loggerConfiguration.ReadFrom.Configuration(builder.Configuration);
|
_ = loggerConfiguration.ReadFrom.Configuration(builder.Configuration);
|
||||||
_ = builder.Host.UseSerilog();
|
_ = builder.Host.UseSerilog();
|
||||||
|
@ -1,10 +1,125 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
using ReportingServices.Shared.HelperClasses;
|
using ReportingServices.Shared.HelperClasses;
|
||||||
|
using ReportingServices.Shared.Models.PlanningReport;
|
||||||
|
using ReportingServices.Shared.Models.ProductionReport;
|
||||||
|
using Serilog;
|
||||||
|
using System.Net.Http.Json;
|
||||||
|
|
||||||
namespace ReportingServices.Test;
|
namespace ReportingServices.Test;
|
||||||
|
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class APIHelperTester
|
public class APIHelperTester
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#pragma warning disable CS8618
|
||||||
|
|
||||||
|
private static ILogger _Logger;
|
||||||
|
private static string _ControllerName;
|
||||||
|
private static TestContext _TestContext;
|
||||||
|
private static WebApplicationFactory<API.Program> _WebApplicationFactory;
|
||||||
|
|
||||||
|
#pragma warning restore
|
||||||
|
|
||||||
|
[ClassInitialize]
|
||||||
|
public static void ClassInitAsync(TestContext testContext)
|
||||||
|
{
|
||||||
|
_TestContext = testContext;
|
||||||
|
_Logger = Log.ForContext<APIHelperTester>();
|
||||||
|
_WebApplicationFactory = new WebApplicationFactory<API.Program>();
|
||||||
|
_ControllerName = nameof(API.Controllers.ScrapeDBController)[..^10];
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task ReactorOuts()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
DateTime endDate = DateTime.Now;
|
||||||
|
DateTime startDate = endDate.AddHours(-24);
|
||||||
|
YieldInformation? result = await httpClient.GetFromJsonAsync<YieldInformation>($"api/{_ControllerName}/ReactorOuts/?startDate={startDate}&endDate={endDate}");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task PSNWO()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
DateTime endDate = DateTime.Now;
|
||||||
|
DateTime startDate = endDate.AddHours(-3);
|
||||||
|
List<ReactorPSNWORuns>? result = await httpClient.GetFromJsonAsync<List<ReactorPSNWORuns>>($"api/{_ControllerName}/PSNWO/?startDate={startDate}&endDate={endDate}");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task PartChanges()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
DateTime endDate = DateTime.Now;
|
||||||
|
DateTime startDate = endDate.AddHours(-3);
|
||||||
|
int? result = await httpClient.GetFromJsonAsync<int>($"api/{_ControllerName}/PartChanges/?startDate={startDate}&endDate={endDate}");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Targets()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
QuarterlyTargets? result = await httpClient.GetFromJsonAsync<QuarterlyTargets>($"api/{_ControllerName}/Targets");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task Reactors()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
List<Reactor>? result = await httpClient.GetFromJsonAsync<List<Reactor>>($"api/{_ControllerName}/Reactors");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task RDS()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
DateTime date = DateTime.Now;
|
||||||
|
List<RDS>? result = await httpClient.GetFromJsonAsync<List<RDS>>($"api/{_ControllerName}/RDS/?date={date}");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task ReactorEvents()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
string reactorNumber = "37";
|
||||||
|
DateTime endDate = DateTime.Now;
|
||||||
|
DateTime startDate = endDate.AddHours(-3);
|
||||||
|
List<ReactorEvent>? result = await httpClient.GetFromJsonAsync<List<ReactorEvent>>($"api/{_ControllerName}/ReactorEvents/?startDate={startDate}&endDate={endDate}&reactorNumber={reactorNumber}");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public async Task ToolEvents()
|
||||||
|
{
|
||||||
|
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||||
|
_Logger.Information("Starting Web Application");
|
||||||
|
string toolID = "37";
|
||||||
|
ToolEvent? result = await httpClient.GetFromJsonAsync<ToolEvent>($"api/{_ControllerName}/ToolEvents/?toolID={toolID}");
|
||||||
|
Assert.IsNotNull(result);
|
||||||
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void CheckShortDateWithPassedInDate()
|
public void CheckShortDateWithPassedInDate()
|
||||||
{
|
{
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
||||||
|
@ -12,8 +12,7 @@ public record AppSettings(string BaseAPIAddress,
|
|||||||
bool IsStaging,
|
bool IsStaging,
|
||||||
string MonAResource,
|
string MonAResource,
|
||||||
string MonASite,
|
string MonASite,
|
||||||
string ToolStateOwnerFilePath,
|
string ToolStateOwnerFilePath)
|
||||||
string URLs)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -19,7 +19,6 @@ public class AppSettings
|
|||||||
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
[Display(Name = "MonA Resource"), Required] public string MonAResource { get; set; }
|
||||||
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
[Display(Name = "MonA Site"), Required] public string MonASite { get; set; }
|
||||||
[Display(Name = "Tool State Owner File Path"), Required] public string ToolStateOwnerFilePath { get; set; }
|
[Display(Name = "Tool State Owner File Path"), Required] public string ToolStateOwnerFilePath { get; set; }
|
||||||
[Display(Name = "URLs"), Required] public string URLs { get; set; }
|
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
@ -54,8 +53,6 @@ public class AppSettings
|
|||||||
throw new NullReferenceException(nameof(MonAResource));
|
throw new NullReferenceException(nameof(MonAResource));
|
||||||
if (appSettings.MonASite is null)
|
if (appSettings.MonASite is null)
|
||||||
throw new NullReferenceException(nameof(MonASite));
|
throw new NullReferenceException(nameof(MonASite));
|
||||||
if (appSettings.URLs is null)
|
|
||||||
throw new NullReferenceException(nameof(URLs));
|
|
||||||
if (appSettings.ToolStateOwnerFilePath is null)
|
if (appSettings.ToolStateOwnerFilePath is null)
|
||||||
throw new NullReferenceException(nameof(ToolStateOwnerFilePath));
|
throw new NullReferenceException(nameof(ToolStateOwnerFilePath));
|
||||||
result = new(
|
result = new(
|
||||||
@ -69,8 +66,7 @@ public class AppSettings
|
|||||||
appSettings.IsStaging.Value,
|
appSettings.IsStaging.Value,
|
||||||
appSettings.MonAResource,
|
appSettings.MonAResource,
|
||||||
appSettings.MonASite,
|
appSettings.MonASite,
|
||||||
appSettings.ToolStateOwnerFilePath,
|
appSettings.ToolStateOwnerFilePath);
|
||||||
appSettings.URLs);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
using ReportingServices.UI.Models;
|
using ReportingServices.UI.Models;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
internal class Program
|
namespace ReportingServices.UI;
|
||||||
|
|
||||||
|
public class Program
|
||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -9,7 +11,7 @@ internal class Program
|
|||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
_ = builder.Configuration.AddUserSecrets<Program>();
|
_ = builder.Configuration.AddUserSecrets<Program>();
|
||||||
AppSettings appSettings = ReportingServices.UI.Models.Binder.AppSettings.Get(builder.Configuration);
|
AppSettings appSettings = Models.Binder.AppSettings.Get(builder.Configuration);
|
||||||
Environment.SetEnvironmentVariable("workingDirectory", "D:\\tmp\\logging\\MesaReportingServices\\UI");
|
Environment.SetEnvironmentVariable("workingDirectory", "D:\\tmp\\logging\\MesaReportingServices\\UI");
|
||||||
_ = loggerConfiguration.ReadFrom.Configuration(builder.Configuration);
|
_ = loggerConfiguration.ReadFrom.Configuration(builder.Configuration);
|
||||||
_ = builder.Host.UseSerilog();
|
_ = builder.Host.UseSerilog();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user