public async Task TestInitDistroy() { LoggerResult loggerResult; var dispatcher = await WindowManagerHelper.CreateUIThread(); using (WindowManagerHelper.InitWindowManager(dispatcher, out loggerResult)) { } WindowManagerHelper.ShutdownUIThread(dispatcher); }
public async Task TestBlockingWindow(params Step[] steps) { TestWindow mainWindow = null; TestWindow modalWindow = null; TestWindow blockingWindow = null; LoggerResult loggerResult; var dispatcher = await WindowManagerHelper.CreateUIThread(); using (WindowManagerHelper.InitWindowManager(dispatcher, out loggerResult)) { foreach (var step in steps) { TestWindow window; var windowsEvent = new TaskCompletionSource <int>(); Task windowsManagerTask; Task dispatcherTask; switch (step) { case Step.ShowMain: Assert.Null(mainWindow); windowsManagerTask = WindowManagerHelper.NextWindowShown; window = dispatcher.Invoke(() => new TestWindow("MainWindow")); window.Shown += (sender, e) => { mainWindow = window; windowsEvent.SetResult(0); }; dispatcherTask = dispatcher.InvokeAsync(() => WindowManager.ShowMainWindow(window)).Task; break; case Step.ShowModal: Assert.Null(modalWindow); windowsManagerTask = WindowManagerHelper.NextWindowShown; window = dispatcher.Invoke(() => new TestWindow("ModalWindow")); window.Shown += (sender, e) => { modalWindow = window; windowsEvent.SetResult(0); }; dispatcherTask = dispatcher.InvokeAsync(() => window.ShowDialog()).Task; break; case Step.ShowBlocking: Assert.Null(blockingWindow); windowsManagerTask = WindowManagerHelper.NextWindowShown; window = dispatcher.Invoke(() => new TestWindow("BlockingWindow")); window.Shown += (sender, e) => { blockingWindow = window; windowsEvent.SetResult(0); }; dispatcherTask = dispatcher.InvokeAsync(() => WindowManager.ShowBlockingWindow(window)).Task; break; case Step.HideMain: Assert.NotNull(mainWindow); windowsManagerTask = WindowManagerHelper.NextWindowHidden; window = mainWindow; window.Closed += (sender, e) => { mainWindow = null; blockingWindow = null; windowsEvent.SetResult(0); }; dispatcherTask = dispatcher.InvokeAsync(() => window.Close()).Task; break; case Step.HideModal: Assert.NotNull(modalWindow); windowsManagerTask = WindowManagerHelper.NextWindowHidden; window = modalWindow; window.Closed += (sender, e) => { modalWindow = null; windowsEvent.SetResult(0); }; dispatcherTask = dispatcher.InvokeAsync(() => window.Close()).Task; break; case Step.HideBlocking: Assert.NotNull(blockingWindow); windowsManagerTask = WindowManagerHelper.NextWindowHidden; window = blockingWindow; window.Closed += (sender, e) => { blockingWindow = null; windowsEvent.SetResult(0); }; dispatcherTask = dispatcher.InvokeAsync(() => window.Close()).Task; break; default: throw new ArgumentOutOfRangeException(); } dispatcherTask.Forget(); await windowsEvent.Task; await windowsManagerTask; // Wait one more "frame" to be sure everything has been run. await dispatcher.InvokeAsync(() => { }, DispatcherPriority.Background); dispatcher.Invoke(() => AssertStep(step, mainWindow, modalWindow, blockingWindow)); } } WindowManagerHelper.ShutdownUIThread(dispatcher); }