remove appsettings
This commit is contained in:
@ -2,7 +2,7 @@ using Barcode.Host.Shared.DataModels;
|
||||
using Barcode.Host.Shared.Models.Stateless;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Barcode.Host.Tests;
|
||||
|
||||
@ -10,21 +10,18 @@ namespace Barcode.Host.Tests;
|
||||
public class UnitTestLastScanController
|
||||
{
|
||||
|
||||
#pragma warning disable CS8618
|
||||
|
||||
private static ILogger _Logger;
|
||||
private static string _ControllerName;
|
||||
private static TestContext _TestContext;
|
||||
private static WebApplicationFactory<Server.Program> _WebApplicationFactory;
|
||||
|
||||
#pragma warning restore
|
||||
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<UnitTestLastScanController>();
|
||||
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
_Logger = serviceProvider.GetRequiredService<ILogger<Server.Program>>();
|
||||
_ControllerName = nameof(Server.ApiControllers.LastScanController)[..^10];
|
||||
}
|
||||
|
||||
@ -38,9 +35,9 @@ public class UnitTestLastScanController
|
||||
[TestMethod]
|
||||
public void TestControllerName()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.AreEqual(ILastScanController<string>.GetRouteName(), _ControllerName);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{testName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -50,12 +47,13 @@ public class UnitTestLastScanController
|
||||
[TestMethod]
|
||||
public void GetScan()
|
||||
{
|
||||
_Logger.Information("Starting Web Application");
|
||||
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
||||
ILastScanService lastScanService = serviceProvider.GetRequiredService<ILastScanService>();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||
ILastScanService? lastScanService = serviceProvider?.GetRequiredService<ILastScanService>();
|
||||
Assert.IsNotNull(lastScanService);
|
||||
Result<string> result = lastScanService.GetScan();
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{testName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -65,13 +63,14 @@ public class UnitTestLastScanController
|
||||
[TestMethod]
|
||||
public async Task GetScanApi()
|
||||
{
|
||||
HttpClient httpClient = _WebApplicationFactory.CreateClient();
|
||||
_Logger.Information("Starting Web Application");
|
||||
HttpClient? httpClient = _WebApplicationFactory?.CreateClient();
|
||||
_Logger?.LogInformation("Starting Web Application");
|
||||
Assert.IsNotNull(httpClient);
|
||||
string? json = await httpClient.GetStringAsync($"api/{_ControllerName}/O171927.1.37/");
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, $"{_ControllerName}-{nameof(GetScan)}.json"), json);
|
||||
Result<string>? result = System.Text.Json.JsonSerializer.Deserialize<Result<string>>(json);
|
||||
Assert.IsNotNull(result?.Results);
|
||||
_Logger.Information($"{_TestContext?.TestName} completed");
|
||||
_Logger?.LogInformation("{testName} completed", _TestContext?.TestName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user