Tests passed using Mock
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user