|
|
@@ -4,6 +4,7 @@
|
|
|
// </copyright>
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
+using System.Collections.Generic;
|
|
|
using Avalonia.Platform;
|
|
|
using Avalonia.UnitTests;
|
|
|
using Moq;
|
|
|
@@ -114,5 +115,81 @@ namespace Avalonia.Controls.UnitTests
|
|
|
Assert.False(window.IsVisible);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Show_Should_Add_Window_To_OpenWindows()
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+ ClearOpenWindows();
|
|
|
+ var window = new Window();
|
|
|
+
|
|
|
+ window.Show();
|
|
|
+
|
|
|
+ Assert.Equal(new[] { window }, Window.OpenWindows);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Window_Should_Be_Added_To_OpenWindows_Only_Once()
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+ ClearOpenWindows();
|
|
|
+ var window = new Window();
|
|
|
+
|
|
|
+ window.Show();
|
|
|
+ window.Show();
|
|
|
+ window.IsVisible = true;
|
|
|
+
|
|
|
+ Assert.Equal(new[] { window }, Window.OpenWindows);
|
|
|
+
|
|
|
+ window.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Close_Should_Remove_Window_From_OpenWindows()
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+ ClearOpenWindows();
|
|
|
+ var window = new Window();
|
|
|
+
|
|
|
+ window.Show();
|
|
|
+ window.Close();
|
|
|
+
|
|
|
+ Assert.Empty(Window.OpenWindows);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Impl_Closing_Should_Remove_Window_From_OpenWindows()
|
|
|
+ {
|
|
|
+ var windowImpl = new Mock<IWindowImpl>();
|
|
|
+ windowImpl.SetupProperty(x => x.Closed);
|
|
|
+ windowImpl.Setup(x => x.Scaling).Returns(1);
|
|
|
+
|
|
|
+ var services = TestServices.StyledWindow.With(
|
|
|
+ windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object));
|
|
|
+
|
|
|
+ using (UnitTestApplication.Start(services))
|
|
|
+ {
|
|
|
+ ClearOpenWindows();
|
|
|
+ var window = new Window();
|
|
|
+
|
|
|
+ window.Show();
|
|
|
+ windowImpl.Object.Closed();
|
|
|
+
|
|
|
+ Assert.Empty(Window.OpenWindows);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ClearOpenWindows()
|
|
|
+ {
|
|
|
+ // HACK: We really need a decent way to have "statics" that can be scoped to
|
|
|
+ // AvaloniaLocator scopes.
|
|
|
+ ((IList<Window>)Window.OpenWindows).Clear();
|
|
|
+ }
|
|
|
}
|
|
|
}
|