Browse Source

Make Window.OpenWindows readonly

And hack around the fact that it's static in unit tests.
pull/996/head
Steven Kirk 9 years ago
parent
commit
5a819c1c87
  1. 4
      src/Avalonia.Controls/Window.cs
  2. 14
      tests/Avalonia.Controls.UnitTests/WindowTests.cs

4
src/Avalonia.Controls/Window.cs

@ -47,12 +47,12 @@ namespace Avalonia.Controls
/// </summary>
public class Window : WindowBase, IStyleable, IFocusScope, ILayoutRoot, INameScope
{
private static IList<Window> s_windows = new List<Window>();
private static List<Window> s_windows = new List<Window>();
/// <summary>
/// Retrieves an enumeration of all Windows in the currently running application.
/// </summary>
public static IList<Window> OpenWindows => s_windows;
public static IReadOnlyList<Window> OpenWindows => s_windows;
/// <summary>
/// Defines the <see cref="SizeToContent"/> property.

14
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -4,6 +4,7 @@
// </copyright>
// -----------------------------------------------------------------------
using System.Collections.Generic;
using Avalonia.Platform;
using Avalonia.UnitTests;
using Moq;
@ -120,13 +121,12 @@ namespace Avalonia.Controls.UnitTests
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
ClearOpenWindows();
var window = new Window();
window.Show();
Assert.Equal(new[] { window }, Window.OpenWindows);
window.Close();
}
}
@ -135,6 +135,7 @@ namespace Avalonia.Controls.UnitTests
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
ClearOpenWindows();
var window = new Window();
window.Show();
@ -152,6 +153,7 @@ namespace Avalonia.Controls.UnitTests
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
ClearOpenWindows();
var window = new Window();
window.Show();
@ -173,6 +175,7 @@ namespace Avalonia.Controls.UnitTests
using (UnitTestApplication.Start(services))
{
ClearOpenWindows();
var window = new Window();
window.Show();
@ -181,5 +184,12 @@ namespace Avalonia.Controls.UnitTests
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();
}
}
}

Loading…
Cancel
Save