public void TestMainThreadDetection() { int mainThread = Thread.CurrentThread.ManagedThreadId; var cmdlet = new PowerBICmdletMock(); var logger = new PowerBILoggerMock() { Cmdlet = cmdlet }; Assert.AreEqual(mainThread, cmdlet.MainThreadId); Assert.IsTrue(logger.GetIsMainThread); // Using Thread instead of Task to avoid ThreadPool executing on main thread var backgroundThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; logger.WriteVerbose("Test"); }); backgroundThread.Start(); Trace.WriteLine($"Managed Thread ID: {backgroundThread.ManagedThreadId}"); backgroundThread.Join(); Assert.AreEqual(0, logger.VerboseMessages.Count); logger.FlushMessages(); Assert.AreEqual(1, logger.VerboseMessages.Count); Assert.AreEqual("Test", logger.VerboseMessages.Single()); }
public void TestDetectingIsPowerBICmdlet() { var logger = new PowerBILoggerMock() { Cmdlet = new NonPowerBICmdlet() }; Assert.IsNull(logger.GetPowerBICmdlet); }