From 7459eeec28e66b39fb4127066600ad9bee6a3a90 Mon Sep 17 00:00:00 2001 From: Marcel Wagner Date: Sun, 5 Dec 2021 21:50:33 +0100 Subject: [PATCH] Add window cleanup on test run finish --- UnitTests/UnitTests.Notifications.WinUI/App.xaml.cs | 13 +++++++++++++ UnitTests/UnitTests.WinUI/App.xaml.cs | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/UnitTests/UnitTests.Notifications.WinUI/App.xaml.cs b/UnitTests/UnitTests.Notifications.WinUI/App.xaml.cs index 52962479dca..f7a999d2b1b 100644 --- a/UnitTests/UnitTests.Notifications.WinUI/App.xaml.cs +++ b/UnitTests/UnitTests.Notifications.WinUI/App.xaml.cs @@ -4,6 +4,7 @@ using System; using Microsoft.UI.Xaml; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; namespace UnitTests.Notifications.WinUI @@ -49,5 +50,17 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e) // replace back with e.Arguments when https://github.com/microsoft/microsoft-ui-xaml/issues/3368 is fixed Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(Environment.CommandLine); } + + [AssemblyCleanup] + public static void CleanupWindow() + { + if (_window != null) + { + _window.DispatcherQueue.TryEnqueue(() => + { + _window.Close(); + }); + } + } } } \ No newline at end of file diff --git a/UnitTests/UnitTests.WinUI/App.xaml.cs b/UnitTests/UnitTests.WinUI/App.xaml.cs index eaeb771488d..8c74247ab6d 100644 --- a/UnitTests/UnitTests.WinUI/App.xaml.cs +++ b/UnitTests/UnitTests.WinUI/App.xaml.cs @@ -6,6 +6,7 @@ using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; using Microsoft.VisualStudio.TestTools.UnitTesting.Logging; using UnitTests.WinUI; @@ -90,5 +91,17 @@ protected override void OnLaunched(LaunchActivatedEventArgs e) // replace back with e.Arguments when https://github.com/microsoft/microsoft-ui-xaml/issues/3368 is fixed Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(Environment.CommandLine); } + + [AssemblyCleanup] + public static void CleanupWindow() + { + if(_window != null) + { + DispatcherQueue.TryEnqueue(() => + { + _window.Close(); + }); + } + } } } \ No newline at end of file