using Microsoft.AspNetCore.Mvc.Testing; using Serilog; namespace Expose.MyIT.Tests; [TestClass] public class UnitTestWeatherForecastController { #pragma warning disable CS8618 private static ILogger _Logger; private static string _ControllerName; private static TestContext _TestContext; private static WebApplicationFactory _WebApplicationFactory; #pragma warning restore [ClassInitialize] public static void ClassInitAsync(TestContext testContext) { _TestContext = testContext; _Logger = Log.ForContext(); _WebApplicationFactory = new WebApplicationFactory(); _ControllerName = nameof(Server.Controllers.WeatherForecastController)[..^10]; } [TestMethod] public void TestControllerName() { _Logger.Information("Starting Web Application"); Assert.AreEqual(Shared.Models.Stateless.IWeatherForecastController.GetRouteName(), _ControllerName); _Logger.Information($"{_TestContext?.TestName} completed"); } [TestMethod] public async Task GetReactors_ShouldReturnAllWeatherForecast() { HttpClient httpClient = _WebApplicationFactory.CreateClient(); _Logger.Information("Starting Web Application"); string result = await httpClient.GetStringAsync($"api/{_ControllerName}"); Assert.IsNotNull(result); _Logger.Information($"{_TestContext?.TestName} completed"); } }