using Barcode.Host.Shared.Models; using Barcode.Host.Shared.Models.Stateless; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.DependencyInjection; using Serilog; namespace Barcode.Host.Tests; [TestClass] public class UnitTestPostService { #pragma warning disable CS8618 private static ILogger _Logger; 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(); } private static void NonThrowTryCatch() { try { throw new Exception(); } catch (Exception) { } } #if DEBUG [Ignore] #endif [TestMethod] public void GetPostTo() { _Logger.Information("Starting Web Application"); HttpClient httpClient = _WebApplicationFactory.CreateClient(); IServiceProvider serviceProvider = _WebApplicationFactory.Services.CreateScope().ServiceProvider; Server.Models.AppSettings appSettings = serviceProvider.GetRequiredService(); IPostService postService = serviceProvider.GetRequiredService(); Notification notification = new(KeyPressEvent: null, "Test", null); _ = postService.Post(appSettings.PostTo, httpClient, notification); _Logger.Information($"{_TestContext?.TestName} completed"); NonThrowTryCatch(); } }