namespace Febe.Tests.Windows.Support; /// /// A temporary folder under (TEMP: on Alberto's PC a work folder outside drive C:), /// removed at the end of the test. WebView2 may hold a file of its profile for a moment after it closed: removal is /// retried and a leftover folder is not an error. /// internal sealed class TestFolder : IDisposable { public TestFolder(string prefix) { Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "febe-prove-windows", prefix + "-" + Guid.NewGuid().ToString("N")[..10]); Directory.CreateDirectory(Path); } public string Path { get; } public string Combine(params string[] parts) => System.IO.Path.Combine([Path, .. parts]); public void Dispose() { for (var attempt = 0; attempt < 10; attempt++) { try { if (Directory.Exists(Path)) { Directory.Delete(Path, recursive: true); } return; } catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) { Thread.Sleep(300); } } } }