46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
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<Server.Program> _WebApplicationFactory;
|
|
|
|
#pragma warning restore
|
|
|
|
[ClassInitialize]
|
|
public static void ClassInitAsync(TestContext testContext)
|
|
{
|
|
_TestContext = testContext;
|
|
_Logger = Log.ForContext<UnitTestWeatherForecastController>();
|
|
_WebApplicationFactory = new WebApplicationFactory<Server.Program>();
|
|
_ControllerName = nameof(Server.Controllers.WeatherForecastController)[..^10];
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestControllerName()
|
|
{
|
|
_Logger.Information("Starting Web Application");
|
|
Assert.AreEqual(Shared.Models.Stateless.IWeatherForecastController<object>.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");
|
|
}
|
|
|
|
} |