refactor(net): converge live session state reset
This commit is contained in:
parent
78a9223b65
commit
4f31a5085f
35 changed files with 1460 additions and 83 deletions
|
|
@ -187,6 +187,74 @@ public sealed class RetailDialogFactoryTests
|
|||
Assert.Null(root.Modal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset_CompletesEveryDialogAndKeepsContextSequenceMonotonic()
|
||||
{
|
||||
var root = new UiRoot { Width = 800f, Height = 600f };
|
||||
var layouts = new List<ImportedLayout>();
|
||||
var factory = CreateFactory(root, layouts);
|
||||
int callbacks = 0;
|
||||
int notices = 0;
|
||||
factory.DialogClosed += (_, _) => notices++;
|
||||
|
||||
uint first = factory.MakeConfirmation("active", _ => callbacks++);
|
||||
factory.MakeConfirmation("pending", _ => callbacks++);
|
||||
factory.Reset();
|
||||
|
||||
Assert.Equal(1u, first);
|
||||
Assert.Equal(2, callbacks);
|
||||
Assert.Equal(2, notices);
|
||||
Assert.False(factory.IsOpen);
|
||||
Assert.Equal(0, factory.PendingCount);
|
||||
Assert.Null(root.Modal);
|
||||
Assert.Empty(root.Children);
|
||||
Assert.Equal(3u, factory.MakeConfirmation("new session"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset_AttemptsEveryDialogWhenOneCallbackThrows()
|
||||
{
|
||||
var root = new UiRoot { Width = 800f, Height = 600f };
|
||||
var layouts = new List<ImportedLayout>();
|
||||
var factory = CreateFactory(root, layouts);
|
||||
int completed = 0;
|
||||
|
||||
factory.MakeConfirmation("active", _ => throw new InvalidOperationException("boom"));
|
||||
factory.MakeConfirmation("pending", _ => completed++);
|
||||
|
||||
AggregateException error = Assert.Throws<AggregateException>(factory.Reset);
|
||||
|
||||
Assert.Contains("boom", error.ToString());
|
||||
Assert.Equal(1, completed);
|
||||
Assert.False(factory.IsOpen);
|
||||
Assert.Equal(0, factory.PendingCount);
|
||||
Assert.Null(root.Modal);
|
||||
Assert.Empty(root.Children);
|
||||
factory.Reset();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reset_DrainsDialogCreatedReentrantlyByCompletionCallback()
|
||||
{
|
||||
var root = new UiRoot { Width = 800f, Height = 600f };
|
||||
var layouts = new List<ImportedLayout>();
|
||||
var factory = CreateFactory(root, layouts);
|
||||
int completed = 0;
|
||||
factory.MakeConfirmation("first", _ =>
|
||||
{
|
||||
completed++;
|
||||
factory.MakeConfirmation("reentrant", _ => completed++);
|
||||
});
|
||||
|
||||
factory.Reset();
|
||||
|
||||
Assert.Equal(2, completed);
|
||||
Assert.False(factory.IsOpen);
|
||||
Assert.Equal(0, factory.PendingCount);
|
||||
Assert.Null(root.Modal);
|
||||
Assert.Empty(root.Children);
|
||||
}
|
||||
|
||||
private static RetailDialogFactory CreateFactory(
|
||||
UiRoot root,
|
||||
List<ImportedLayout> layouts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue