using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using Allure.Net.Commons; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestResult = Allure.Net.Commons.TestResult; namespace skyscraper8.Tests; [TestClass] public class Feyllure { public TestContext TestContext { get; set; } protected static readonly AllureLifecycle Allure = AllureLifecycle.Instance; private bool assemblyWasInited; private void AssemblyInit(TestContext context) { // Ensure allure-results exists var resultsDir = Allure.ResultsDirectory; Directory.CreateDirectory(resultsDir); var envFile = Path.Combine(resultsDir, "environment.properties"); using (var writer = new StreamWriter(envFile)) { writer.WriteLine($"SkyscraperRelease={VersionInfo.GetPublicReleaseNumber()}"); writer.WriteLine($"SkyscraperCodeVersion={VersionInfo.GetCurrentAssemblyDisplayVersion()}"); writer.WriteLine($"OS={RuntimeInformation.OSDescription}"); writer.WriteLine($".NET={Environment.Version}"); writer.WriteLine($"Machine={Environment.MachineName}"); writer.WriteLine($"User={Environment.UserName}"); writer.WriteLine($"Framework={System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}"); writer.WriteLine($"BuildDate={DateTime.UtcNow:yyyy-MM-dd HH:mm:ss}"); } var executorFile = Path.Combine(resultsDir, "executor.json"); var executorInfo = new { name = Environment.MachineName, buildName = "My build name", buildUrl = "http://127.0.0.2", }; var executorJson = Newtonsoft.Json.JsonConvert.SerializeObject(executorInfo); File.WriteAllText(executorFile, executorJson); } [TestInitialize] public void Setup() { if (!assemblyWasInited){ AssemblyInit(TestContext); assemblyWasInited = true; } var testName = TestContext.TestName; var fqClass = TestContext.FullyQualifiedTestClassName; // Extract namespace and class name var lastDot = fqClass.LastIndexOf('.'); var ns = lastDot > 0 ? fqClass.Substring(0, lastDot) : ""; var cls = lastDot > 0 ? fqClass.Substring(lastDot + 1) : fqClass; TestResult testResult = new TestResult(); testResult.uuid = Guid.NewGuid().ToString(); testResult.name = testName; testResult.fullName = String.Format("{0}.{1}", TestContext.FullyQualifiedTestClassName, testName); testResult.labels = new List