Skip to content

Commit

Permalink
[#6430] Adaptive ForEachElement does not exit when child action Cance…
Browse files Browse the repository at this point in the history
…lAllDialogs is called (#6452)

* Consider canceled status to end the dialog

* Add unit test
  • Loading branch information
ceciliaavila authored Aug 29, 2022
1 parent c58e322 commit c572be3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ private DialogContext CreateChildContext(DialogContext dc, DialogState childDial

private bool ShouldEndDialog(DialogTurnResult turnResult, out DialogTurnResult finalTurnResult)
{
DialogTurnStatus[] endedDialog = { DialogTurnStatus.Complete, DialogTurnStatus.Cancelled };
finalTurnResult = null;

// Insure BreakLoop ends the dialog
Expand All @@ -279,12 +280,12 @@ private bool ShouldEndDialog(DialogTurnResult turnResult, out DialogTurnResult f
// the result will be nested.
while (finalTurnResult.Result != null
&& finalTurnResult.Result is DialogTurnResult dtr
&& dtr.ParentEnded && dtr.Status == DialogTurnStatus.Complete)
&& dtr.ParentEnded && endedDialog.Contains(dtr.Status))
{
finalTurnResult = dtr;
}

return finalTurnResult.ParentEnded && finalTurnResult.Status == DialogTurnStatus.Complete;
return finalTurnResult.ParentEnded && endedDialog.Contains(finalTurnResult.Status);
}

private void UpdateActionScopeState(DialogContext dc, DialogState state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ public async Task Action_Foreach_Nested()
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task Action_Foreach_Nested_WithCancel()
{
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task Action_Foreach_Object()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "root",
"triggers": [
{
"$kind": "Microsoft.OnBeginDialog",
"actions": [
{
"$kind": "Microsoft.SetProperty",
"property": "dialog.todo",
"value": "=['1', '2', '3']"
},
{
"$kind": "Microsoft.Foreach",
"itemsProperty": "dialog.todo",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "I'm the Parent loop - index is: ${dialog.foreach.index}"
},
{
"$kind": "Microsoft.Foreach",
"itemsProperty": "dialog.todo",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "I'm the child loop and I will cancel all dialogs"
},
{
"$kind": "Microsoft.CancelAllDialogs"
},
{
"$kind": "Microsoft.SendActivity",
"activity": "This shouldn't be sent"
}
]
},
{
"$kind": "Microsoft.SendActivity",
"activity": "This shouldn't be sent either"
}
]
}
]
}
],
"autoEndDialog": true,
"defaultResultProperty": "dialog.result"
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hi"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "I'm the Parent loop - index is: 0"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "I'm the child loop and I will cancel all dialogs"
}
]
}

0 comments on commit c572be3

Please sign in to comment.