67 lines
2.3 KiB
C#
67 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using OI.Metrology.Shared.Models.Stateless;
|
|
using Serilog;
|
|
|
|
namespace OI.Metrology.Tests;
|
|
|
|
[TestClass]
|
|
public class UnitTestISpreadingResistanceProfileController
|
|
{
|
|
|
|
#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
|
|
|
|
[ClassInitialize]
|
|
public static void ClassInitAsync(TestContext testContext)
|
|
{
|
|
_TestContext = testContext;
|
|
_Logger = Log.ForContext<UnitTestISpreadingResistanceProfileController>();
|
|
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
|
_ControllerName = nameof(Server.ApiControllers.InfinityQSController)[..^10];
|
|
}
|
|
|
|
private static void NonThrowTryCatch()
|
|
{
|
|
try
|
|
{ throw new Exception(); }
|
|
catch (Exception) { }
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestControllerName()
|
|
{
|
|
_Logger.Information("Starting Web Application");
|
|
Assert.AreEqual(IInfinityQSController<string>.GetRouteName(), _ControllerName);
|
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
|
NonThrowTryCatch();
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetSpreadingResistanceProfileServiceImageBytes()
|
|
{
|
|
_Logger.Information("Starting Web Application");
|
|
string directory = "D:/wwwRoot";
|
|
if (!Directory.Exists(directory))
|
|
_ = Directory.CreateDirectory(directory);
|
|
string file = Path.Combine(directory, "data.json");
|
|
if (File.Exists(file))
|
|
{
|
|
string json = File.ReadAllText(file);
|
|
IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider;
|
|
ISpreadingResistanceProfileService spreadingResistanceProfileService = serviceProvider.GetRequiredService<ISpreadingResistanceProfileService>();
|
|
byte[] bytes = spreadingResistanceProfileService.GetImageBytes(json);
|
|
Assert.IsTrue(bytes.Any());
|
|
File.WriteAllBytes(Path.Combine(directory, "srp.png"), bytes);
|
|
}
|
|
_Logger.Information($"{_TestContext?.TestName} completed");
|
|
NonThrowTryCatch();
|
|
}
|
|
|
|
} |