Added test for APIs

This commit is contained in:
Daniel Wathen
2023-01-17 15:51:47 -07:00
parent a0c3e66dc1
commit b428464a02
8 changed files with 128 additions and 18 deletions

View File

@ -1,10 +1,125 @@
using Microsoft.AspNetCore.Mvc.Testing;
using ReportingServices.Shared.HelperClasses;
using ReportingServices.Shared.Models.PlanningReport;
using ReportingServices.Shared.Models.ProductionReport;
using Serilog;
using System.Net.Http.Json;
namespace ReportingServices.Test;
[TestClass]
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]
public void CheckShortDateWithPassedInDate()
{