using Adaptation._Tests.Shared; using Adaptation.FileHandlers.MoveAllFiles; using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Diagnostics; using System.Net.Http; using System.Reflection; using System.Text.Json; namespace Adaptation._Tests.Static; [TestClass] public class API : LoggingUnitTesting, IDisposable { #pragma warning disable CA2254 #pragma warning disable IDE0060 internal static API LoggingUnitTesting { get; private set; } public API() : base(testContext: null, declaringType: null) { if (LoggingUnitTesting is null) throw new Exception(); } public API(TestContext testContext) : base(testContext, new StackFrame().GetMethod().DeclaringType) { } [ClassInitialize] public static void ClassInitialize(TestContext testContext) => LoggingUnitTesting ??= new API(testContext); [ClassCleanup()] public static void ClassCleanup() { LoggingUnitTesting?.Logger?.LogInformation("Cleanup"); LoggingUnitTesting?.Dispose(); } private static void NonThrowTryCatch() { try { throw new Exception(); } catch (Exception) { } } #if (!true) [Ignore] #endif [TestMethod] public void TestApiA() { MethodBase methodBase = new StackFrame().GetMethod(); #nullable enable HttpClient httpClient = new(); // string rds = "504162"; string rds = "601132"; string url = $"{FileRead.OpenInsightApplicationProgrammingInterface}/materials/rds/{rds}"; string httpClientResult = httpClient.GetStringAsync(url).Result; FileHandlers.MoveAllFiles.OpenInsight.Root? root = JsonSerializer.Deserialize(httpClientResult); httpClient.Dispose(); Assert.IsNotNull(root?.Rds.ProdSpec.PrsStages); List? collection; Dictionary> qaMetTests = new(); foreach (FileHandlers.MoveAllFiles.OpenInsight.PrsStage prsStage in root.Rds.ProdSpec.PrsStages) { if (prsStage.QaMetTests is null) continue; foreach (FileHandlers.MoveAllFiles.OpenInsight.QaMetTest qaMetTest in prsStage.QaMetTests) { if (qaMetTest.ToolClass != "FTIR") continue; if (!qaMetTests.TryGetValue(prsStage.Stage, out collection)) { qaMetTests.Add(prsStage.Stage, new()); if (!qaMetTests.TryGetValue(prsStage.Stage, out collection)) throw new Exception(); } collection.Add(qaMetTest); } } Assert.IsTrue(qaMetTests.Count > 0); string json = JsonSerializer.Serialize(qaMetTests, new JsonSerializerOptions { WriteIndented = true }); Assert.IsTrue(!string.IsNullOrEmpty(json)); System.IO.File.WriteAllText("D:/.json", json); LoggingUnitTesting.Logger.LogInformation(string.Concat(methodBase?.Name, " - Exit")); NonThrowTryCatch(); #nullable restore } }