From 74cf71eeaa3a6f29e2c088fe058610ce185d165f Mon Sep 17 00:00:00 2001 From: Mat Date: Sat, 8 Jun 2019 16:17:06 +0200 Subject: [PATCH] Removed external test dependency (#131) Removed capture test being dependent on some Notepad window. Test was only successfull if this window existed. Code from [here](https://github.com/dapplo/Dapplo.Windows/blob/450fae4b4a139b2bf6063bbbc6c40772355d4c0d/src/Dapplo.Windows.Tests/WindowsEnumeratorTests.cs#L85) --- src/Greenshot.Tests/CaptureTests.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Greenshot.Tests/CaptureTests.cs b/src/Greenshot.Tests/CaptureTests.cs index d6412f7ef..de894a783 100644 --- a/src/Greenshot.Tests/CaptureTests.cs +++ b/src/Greenshot.Tests/CaptureTests.cs @@ -20,6 +20,7 @@ using System.Drawing.Imaging; using System.IO; using System.Linq; +using System.Reactive.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Media.Imaging; @@ -117,7 +118,19 @@ namespace Greenshot.Tests { ICoreConfiguration config = new CoreConfigurationImpl(); - var windowToCapture = InteropWindowQuery.GetTopLevelWindows().First(window => window.GetCaption().Contains("Notepad")); + var textValue = System.Guid.NewGuid().ToString(); + var form = new Form + { + Text = textValue, + TopLevel = true + }; + form.Show(); + // Important, otherwise Windows doesn't have time to display the window! + Application.DoEvents(); + + await Task.Delay(400); + var windowToCapture = await WindowsEnumerator.EnumerateWindowsAsync().Where(info => info.GetCaption().Contains(textValue)).FirstOrDefaultAsync(); + var bounds = windowToCapture.GetInfo().Bounds; var captureFlow = new CaptureFlow {