Browse Source

Added test and fixed implementation.

pull/459/head
Jeremy Koritzinsky 10 years ago
parent
commit
eea178500a
  1. 4
      src/Perspex.Controls/TopLevel.cs
  2. 21
      tests/Perspex.Controls.UnitTests/TopLevelTests.cs
  3. 4
      tests/Perspex.UnitTests/UnitTestApplication.cs

4
src/Perspex.Controls/TopLevel.cs

@ -114,7 +114,7 @@ namespace Perspex.Controls
.Select(
x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty<Cursor>())
.Switch().Subscribe(cursor => PlatformImpl.SetCursor(cursor?.PlatformCursor));
_applicationLifecycle.OnExit += HandleApplicationExiting;
_applicationLifecycle.OnExit += OnApplicationExiting;
}
/// <summary>
@ -355,7 +355,7 @@ namespace Perspex.Controls
private void OnApplicationExiting(object sender, EventArgs args)
{
HandleApplicationExiting();
}
/// <summary>

21
tests/Perspex.Controls.UnitTests/TopLevelTests.cs

@ -282,12 +282,33 @@ namespace Perspex.Controls.UnitTests
});
}
[Fact]
public void Exiting_Application_Notifies_Top_Level()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var impl = new Mock<ITopLevelImpl>();
impl.SetupAllProperties();
var target = new TestTopLevel(impl.Object);
UnitTestApplication.Current.Exit();
Assert.True(target.IsClosed);
}
}
private class TestTopLevel : TopLevel
{
public bool IsClosed { get; private set; }
public TestTopLevel(ITopLevelImpl impl)
: base(impl)
{
}
protected override void HandleApplicationExiting()
{
base.HandleApplicationExiting();
IsClosed = true;
}
}
}
}

4
tests/Perspex.UnitTests/UnitTestApplication.cs

@ -6,6 +6,7 @@ using Perspex.Input;
using Perspex.Layout;
using Perspex.Platform;
using Perspex.Styling;
using Perspex.Controls;
namespace Perspex.UnitTests
{
@ -41,7 +42,8 @@ namespace Perspex.UnitTests
.Bind<IPlatformThreadingInterface>().ToConstant(Services.ThreadingInterface)
.Bind<IStandardCursorFactory>().ToConstant(Services.StandardCursorFactory)
.Bind<IStyler>().ToConstant(Services.Styler)
.Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform);
.Bind<IWindowingPlatform>().ToConstant(Services.WindowingPlatform)
.Bind<IApplicationLifecycle>().ToConstant(this);
}
}
}

Loading…
Cancel
Save