mirror of https://github.com/AMT-Cheif/Stylet.git
Add overridable CanClose() method to Screen - meaning they don't have to use Tasks
This commit is contained in:
parent
e29e3bf061
commit
77c6d347a5
|
@ -220,10 +220,20 @@ namespace Stylet
|
|||
/// <summary>
|
||||
/// Called when a conductor wants to know whether this screen can close.
|
||||
/// </summary>
|
||||
/// <remarks>Internally, this calls CanClose, and wraps the response in a Task</remarks>
|
||||
/// <returns>A task returning true (can close) or false (can't close)</returns>
|
||||
public virtual Task<bool> CanCloseAsync()
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
return Task.FromResult(this.CanClose());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Synchronous alternative to CanClose
|
||||
/// </summary>
|
||||
/// <returns>True if this screen can close, or false otherwise</returns>
|
||||
protected virtual bool CanClose()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -55,6 +55,12 @@ namespace StyletUnitTests
|
|||
{
|
||||
this.OnViewLoadedCalled = true;
|
||||
}
|
||||
|
||||
public bool? CanCloseResult = null;
|
||||
protected override bool CanClose()
|
||||
{
|
||||
return this.CanCloseResult == null ? base.CanClose() : this.CanCloseResult.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private MyScreen screen;
|
||||
|
@ -248,13 +254,22 @@ namespace StyletUnitTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void CanCloseAsyncReturnsCompletedTrueTask()
|
||||
public void CanCloseAsyncReturnsTrueByDefault()
|
||||
{
|
||||
var task = this.screen.CanCloseAsync();
|
||||
Assert.IsTrue(task.IsCompleted);
|
||||
Assert.IsTrue(task.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanCloseAsyncReturnsResultOfCanClose()
|
||||
{
|
||||
this.screen.CanCloseResult = false;
|
||||
var task = this.screen.CanCloseAsync();
|
||||
Assert.IsTrue(task.IsCompleted);
|
||||
Assert.IsFalse(task.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TryCloseThrowsIfParentIsNotIChildDelegate()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue