/// <summary> /// Create a new test-suite. /// </summary> /// <param name="testOutput"> /// Output for the current test. /// </param> protected TestBase(ITestOutputHelper testOutput) { if (testOutput == null) { throw new ArgumentNullException(nameof(testOutput)); } // We *must* have a synchronisation context for the test, or we'll see random deadlocks. SynchronizationContext.SetSynchronizationContext( new SynchronizationContext() ); TestOutput = testOutput; // Redirect component logging to Serilog. LoggerFactory = new LoggerFactory(); Disposal.Add(LoggerFactory); // LoggerFactory.AddDebug(LogLevel); // ReSharper disable once VirtualMemberCallInConstructor LoggerFactory.AddTestOutput(TestOutput, LogLevel); // Ugly hack to get access to the current test. CurrentTest = (ITest) TestOutput.GetType() .GetField("test", BindingFlags.NonPublic | BindingFlags.Instance) ! .GetValue(TestOutput) !; Assert.True(CurrentTest != null, "Cannot retrieve current test from ITestOutputHelper."); Log = LoggerFactory.CreateLogger("CurrentTest"); Disposal.Add(Log.BeginScope("TestDisplayName='{TestName}'", CurrentTest !.DisplayName)); }