Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DefaultValueResponce can't access DialogContext.State #4691

Merged
merged 5 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public abstract class InputDialog : Dialog
var (value, error) = this.DefaultValue.TryGetValue(dc.State);
if (this.DefaultValueResponse != null)
{
var response = await this.DefaultValueResponse.BindAsync(dc, cancellationToken).ConfigureAwait(false);
var response = await this.DefaultValueResponse.BindAsync(dc, cancellationToken: cancellationToken).ConfigureAwait(false);
cosmicshuai marked this conversation as resolved.
Show resolved Hide resolved

var properties = new Dictionary<string, string>()
{
Expand All @@ -285,7 +285,7 @@ public abstract class InputDialog : Dialog
}
}

return await dc.EndDialogAsync().ConfigureAwait(false);
return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public class OAuthInput : InputDialog
var (value, _) = this.DefaultValue.TryGetValue(dc.State);
if (this.DefaultValueResponse != null)
{
var response = await this.DefaultValueResponse.BindAsync(dc, cancellationToken).ConfigureAwait(false);
var response = await this.DefaultValueResponse.BindAsync(dc, cancellationToken: cancellationToken).ConfigureAwait(false);
var properties = new Dictionary<string, string>()
{
{ "template", JsonConvert.SerializeObject(this.DefaultValueResponse) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public ActivityTemplate(string template)
/// <returns>Instance of <see cref="Activity"/>.</returns>
public virtual async Task<Activity> BindAsync(DialogContext dialogContext, object data = null, CancellationToken cancellationToken = default)
{
if (dialogContext == null)
{
throw new ArgumentNullException(nameof(dialogContext));
}

if (data is CancellationToken)
{
throw new ArgumentException($"{nameof(data)} cannot be a cancellation token");
}

if (!string.IsNullOrEmpty(this.Template))
{
var languageGenerator = dialogContext.Services.Get<LanguageGenerator>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public TextTemplate(string template)
/// <returns>Instance of string.</returns>
public virtual async Task<string> BindAsync(DialogContext dialogContext, object data = null, CancellationToken cancellationToken = default)
{
if (dialogContext == null)
{
throw new ArgumentNullException(nameof(dialogContext));
}

if (data is CancellationToken)
{
throw new ArgumentException($"{nameof(data)} cannot be a cancellation token");
}

if (string.IsNullOrEmpty(this.Template))
{
throw new InvalidOperationException($"The {nameof(this.Template)} property can't be empty.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ public async Task Action_NumberInputWithVAlueExpression()
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

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

[Fact]
public async Task Action_RepeatDialog()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Tests\ActionTests\Action_NumberInputWithDefaultResponse.test.dialog">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Tests\AskTests\Action_AskRetriesDeleteProperties.test.dialog">
<SubType>Component</SubType>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"id": "planningTest",
"triggers": [
{
"$kind": "Microsoft.OnBeginDialog",
"actions": [
{
"$kind": "Microsoft.NumberInput",
"defaultLocale": "en-us",
"disabled": false,
"maxTurnCount": 2,
"alwaysPrompt": true,
"allowInterruptions": false,
"prompt": "Give me your favorite number (1-10)",
"unrecognizedPrompt": "Sorry, ${turn.activity.text} did not include a valid number.",
"invalidPrompt": "Sorry, ${this.value} does not work. Can you give me a different number that is between 1-10?",
"defaultValueResponse": "Sorry, we have tried for ${class.MaxTurnCount} number of times and I'm still not getting it. For now, I'm setting ${class.property} to ${class.DefaultValue}",
"property": "user.favoriteNumber",
"outputFormat": "=string(this.value)",
"validations": [
"=int(this.value) >=1",
"=int(this.value) <= 10"
],
"defaultValue": 9
}
]
}
],
"defaultResultProperty": "dialog.result"
},
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hi"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Give me your favorite number (1-10)"
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "1000"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Sorry, 1000 does not work. Can you give me a different number that is between 1-10?"
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "25"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Sorry, we have tried for 2 number of times and I'm still not getting it. For now, I'm setting user.favoriteNumber to 9"
}
]
}