* Initial check-in of default op improvements.  Need to write tests.

* Clean-up logic and prefer default operations.

* Add tests for default operation preference.

* Add description to memory assetion error.
For Chris

* Add AssertNoActivity.

* Remove timeout from schema.

* Fix bug in testscript.
This commit is contained in:
Chris McConnell 2020-10-14 12:00:47 -07:00 коммит произвёл GitHub
Родитель 2e852e299b
Коммит 3f4a07d2ce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
11 изменённых файлов: 352 добавлений и 219 удалений

Просмотреть файл

@ -36,6 +36,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing
yield return new DeclarativeType<AssertReply>(AssertReply.Kind);
yield return new DeclarativeType<AssertReplyOneOf>(AssertReplyOneOf.Kind);
yield return new DeclarativeType<AssertReplyActivity>(AssertReplyActivity.Kind);
yield return new DeclarativeType<AssertNoActivity>(AssertNoActivity.Kind);
yield return new DeclarativeType<MemoryAssertions>(MemoryAssertions.Kind);
yield return new DeclarativeType<HttpRequestSequenceMock>(HttpRequestSequenceMock.Kind);
yield return new DeclarativeType<UserTokenBasicMock>(UserTokenBasicMock.Kind);

Просмотреть файл

@ -0,0 +1,14 @@
{
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
"$role": "implements(Microsoft.Test.ITestAction)",
"title": "Assert Reply Activity",
"description": "Asserts that there is no activity.",
"type": "object",
"properties": {
"description": {
"type": "string",
"title": "Description",
"description": "The description of the assertion"
}
}
}

Просмотреть файл

@ -0,0 +1,67 @@
// Licensed under the MIT License.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveExpressions;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
{
/// <summary>
/// Basic assertion TestAction, which validates assertions against a reply activity.
/// </summary>
[DebuggerDisplay("AssertNoActivity:{GetConditionDescription()}")]
public class AssertNoActivity : TestAction
{
/// <summary>
/// Kind for json serialization.
/// </summary>
[JsonProperty("$kind")]
public const string Kind = "Microsoft.Test.AssertNoActivity";
/// <summary>
/// Initializes a new instance of the <see cref="AssertNoActivity"/> class.
/// </summary>
/// <param name="path">optional path.</param>
/// <param name="line">optional line.</param>
[JsonConstructor]
public AssertNoActivity([CallerFilePath] string path = "", [CallerLineNumber] int line = 0)
{
RegisterSourcePath(path, line);
}
/// <summary>
/// Gets or sets the description of this assertion.
/// </summary>
/// <value>Description of what this assertion is.</value>
[JsonProperty("description")]
public string Description { get; set; }
/// <summary>
/// Gets the text to assert for an activity.
/// </summary>
/// <returns>String.</returns>
public virtual string GetConditionDescription()
{
return Description ?? "No activity";
}
/// <inheritdoc/>
public override Task ExecuteAsync(TestAdapter adapter, BotCallbackHandler callback, Inspector inspector = null)
{
if (adapter.ActiveQueue.Count > 0)
{
throw new Exception($"{GetConditionDescription()}");
}
return Task.CompletedTask;
}
}
}

Просмотреть файл

@ -8,7 +8,6 @@ using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using AdaptiveExpressions;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Schema;
using Newtonsoft.Json;
namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
@ -62,7 +61,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing.TestActions
var (val, error) = Expression.Parse(assertion).TryEvaluate<bool>(dc.State);
if (error != null || !val)
{
throw new Exception($"{assertion} failed");
throw new Exception($"{Description} {assertion} failed");
}
}
}).ConfigureAwait(false);

Просмотреть файл

@ -54,7 +54,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing
{
foreach (var assignment in Assignments)
{
dc.State.SetValue(assignment.Property.Value, assignment.Value.Value);
dc.State.SetValue(assignment.Property.GetValue(dc.State), assignment.Value.GetValue(dc.State));
}
}).ConfigureAwait(false);
Trace.TraceInformation($"[Turn Ended => SetProperties completed]");

Просмотреть файл

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Bot.Builder.Adapters;
@ -26,6 +27,11 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing
/// <seealso cref="TestAdapter"/>
public class TestScript
{
/// <summary>
/// Test script ended event.
/// </summary>
public const string TestScriptEnded = "TestScriptEnded";
/// <summary>
/// Sets the Kind for this class.
/// </summary>
@ -173,16 +179,10 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing
async (turnContext, cancellationToken) => await di.InspectAsync(turnContext, inspector).ConfigureAwait(false)).ConfigureAwait(false);
}
if (callback != null)
DialogManager dm;
if (callback == null)
{
foreach (var testAction in Script)
{
await testAction.ExecuteAsync(adapter, callback, Inspect).ConfigureAwait(false);
}
}
else
{
var dm = new DialogManager(Dialog)
dm = new DialogManager(Dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();
@ -191,10 +191,12 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Testing
dm.UseLanguagePolicy(languagePolicy);
}
foreach (var testAction in Script)
{
await testAction.ExecuteAsync(adapter, dm.OnTurnAsync, Inspect).ConfigureAwait(false);
}
callback = dm.OnTurnAsync;
}
foreach (var testAction in Script)
{
await testAction.ExecuteAsync(adapter, callback, Inspect).ConfigureAwait(false);
}
}

Просмотреть файл

@ -35,7 +35,7 @@ namespace Microsoft.Bot.Builder.Dialogs.Adaptive
}
var list = new List<string>();
var entities = schema["$entities"]?.Value<JArray>();
var entities = schema["$entities"]?.Value<JArray>() ?? schema["items"]?["$entities"].Value<JArray>();
if (entities != null)
{
foreach (var entity in entities)

Просмотреть файл

@ -51,6 +51,11 @@
{
"$kind": "Microsoft.SendActivity",
"activity": "Set bread to rye"
},
{
"$kind": "Microsoft.SetProperty",
"property": "$Bread",
"value": "@BreadEntity"
}
]
}
@ -80,20 +85,21 @@
],
"description": "Ensure retries is initialized"
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "no entities"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Bread?"
},
{
"$kind": "Microsoft.Test.MemoryAssertions",
"assertions": [
"$retries == 1"
]
}, {
{
"$kind": "Microsoft.Test.UserSays",
"text": "no entities"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "Bread?"
},
{
"$kind": "Microsoft.Test.MemoryAssertions",
"assertions": [
"$retries == 1"
]
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "rye"
},
@ -106,6 +112,9 @@
"assertions": [
"!$retries"
]
},
{
"$kind": "Microsoft.Test.AssertNoActivity",
}
]
}

Просмотреть файл

@ -93,11 +93,11 @@
"whiteOnions",
"redOnions"
],
"maxItems": 3
"maxItems": 3,
"$entities": [
"ToppingsEntity"
]
},
"$entities": [
"ToppingsEntity"
]
},
"Sauces": {
"type": "array",

Просмотреть файл

@ -313,6 +313,9 @@
{
"$ref": "#/definitions/Microsoft.Test.AssertCondition"
},
{
"$ref": "#/definitions/Microsoft.Test.AssertNoActivity"
},
{
"$ref": "#/definitions/Microsoft.Test.AssertReply"
},
@ -8300,6 +8303,41 @@
}
}
},
"Microsoft.Test.AssertNoActivity": {
"$role": "implements(Microsoft.Test.ITestAction)",
"title": "Assert Reply Activity",
"description": "Asserts that there is no activity.",
"type": "object",
"required": [
"$kind"
],
"additionalProperties": false,
"patternProperties": {
"^\\$": {
"title": "Tooling property",
"description": "Open ended property for tooling."
}
},
"properties": {
"description": {
"type": "string",
"title": "Description",
"description": "The description of the assertion"
},
"$kind": {
"title": "Kind of dialog object",
"description": "Defines the valid properties for the component you are configuring (from a dialog .schema file)",
"type": "string",
"pattern": "^[a-zA-Z][a-zA-Z0-9.]*$",
"const": "Microsoft.Test.AssertNoActivity"
},
"$designer": {
"title": "Designer information",
"type": "object",
"description": "Extra information for the Bot Framework Composer."
}
}
},
"Microsoft.Test.AssertReply": {
"$role": "implements(Microsoft.Test.ITestAction)",
"title": "Assert Reply",
@ -8763,6 +8801,9 @@
"title": "Reference to Microsoft.Test.ITestAction",
"description": "Reference to Microsoft.Test.ITestAction .dialog file."
},
{
"$ref": "#/definitions/Microsoft.Test.AssertNoActivity"
},
{
"$ref": "#/definitions/Microsoft.Test.AssertReply"
},

Просмотреть файл

@ -23,6 +23,20 @@
}
}
},
"Microsoft.AttachmentInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for a file or an attachment",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Attachment Input"
}
},
"Microsoft.BeginDialog": {
"form": {
"helpLink": "https://aka.ms/bfc-understanding-dialogs",
@ -70,12 +84,54 @@
"subtitle": "Cancel All Dialogs"
}
},
"Microsoft.ChoiceInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt with multi-choice",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Choice Input"
}
},
"Microsoft.ConfirmInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for confirmation",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Confirm Input"
}
},
"Microsoft.ContinueLoop": {
"form": {
"label": "Continue loop",
"subtitle": "Continue loop"
}
},
"Microsoft.DateTimeInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for a date or a time",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Date Time Input"
}
},
"Microsoft.DebugBreak": {
"form": {
"label": "Debug Break"
@ -257,169 +313,6 @@
"subtitle": "Log Action"
}
},
"Microsoft.RepeatDialog": {
"form": {
"helpLink": "https://aka.ms/bfc-understanding-dialogs",
"label": "Repeat this dialog",
"order": [
"options",
"*"
],
"subtitle": "Repeat Dialog"
}
},
"Microsoft.ReplaceDialog": {
"form": {
"helpLink": "https://aka.ms/bfc-understanding-dialogs",
"label": "Replace this dialog",
"order": [
"dialog",
"options",
"*"
],
"subtitle": "Replace Dialog"
}
},
"Microsoft.SendActivity": {
"form": {
"helpLink": "https://aka.ms/bfc-send-activity",
"label": "Send a response",
"order": [
"activity",
"*"
],
"subtitle": "Send Activity"
}
},
"Microsoft.SetProperties": {
"form": {
"helpLink": "https://aka.ms/bfc-using-memory",
"label": "Set properties",
"properties": {
"assignments": {
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
}
}
},
"subtitle": "Set Properties"
}
},
"Microsoft.SetProperty": {
"form": {
"helpLink": "https://aka.ms/bfc-using-memory",
"label": "Set a property",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Set Property"
}
},
"Microsoft.SignOutUser": {
"form": {
"label": "Sign out user",
"subtitle": "Signout User"
}
},
"Microsoft.SwitchCondition": {
"form": {
"helpLink": "https://aka.ms/bfc-controlling-conversation-flow",
"hidden": [
"default"
],
"label": "Branch: Switch (multiple options)",
"properties": {
"cases": {
"hidden": [
"actions"
]
},
"condition": {
"intellisenseScopes": [
"user-variables"
]
}
},
"subtitle": "Switch Condition"
}
},
"Microsoft.ThrowException": {
"form": {
"label": "Throw an exception",
"subtitle": "Throw an exception"
}
},
"Microsoft.TraceActivity": {
"form": {
"helpLink": "https://aka.ms/bfc-debugging-bots",
"label": "Emit a trace event",
"subtitle": "Trace Activity"
}
},
"Microsoft.AttachmentInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for a file or an attachment",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Attachment Input"
}
},
"Microsoft.ChoiceInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt with multi-choice",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Choice Input"
}
},
"Microsoft.ConfirmInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for confirmation",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Confirm Input"
}
},
"Microsoft.DateTimeInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for a date or a time",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Date Time Input"
}
},
"Microsoft.NumberInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
@ -445,27 +338,6 @@
"subtitle": "OAuth Input"
}
},
"Microsoft.TextInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for text",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Text Input"
}
},
"Microsoft.RegexRecognizer": {
"form": {
"hidden": [
"entities"
]
}
},
"Microsoft.OnActivity": {
"form": {
"hidden": [
@ -729,5 +601,133 @@
],
"subtitle": "Unknown intent recognized"
}
},
"Microsoft.RegexRecognizer": {
"form": {
"hidden": [
"entities"
]
}
},
"Microsoft.RepeatDialog": {
"form": {
"helpLink": "https://aka.ms/bfc-understanding-dialogs",
"label": "Repeat this dialog",
"order": [
"options",
"*"
],
"subtitle": "Repeat Dialog"
}
},
"Microsoft.ReplaceDialog": {
"form": {
"helpLink": "https://aka.ms/bfc-understanding-dialogs",
"label": "Replace this dialog",
"order": [
"dialog",
"options",
"*"
],
"subtitle": "Replace Dialog"
}
},
"Microsoft.SendActivity": {
"form": {
"helpLink": "https://aka.ms/bfc-send-activity",
"label": "Send a response",
"order": [
"activity",
"*"
],
"subtitle": "Send Activity"
}
},
"Microsoft.SetProperties": {
"form": {
"helpLink": "https://aka.ms/bfc-using-memory",
"label": "Set properties",
"properties": {
"assignments": {
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
}
}
},
"subtitle": "Set Properties"
}
},
"Microsoft.SetProperty": {
"form": {
"helpLink": "https://aka.ms/bfc-using-memory",
"label": "Set a property",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Set Property"
}
},
"Microsoft.SignOutUser": {
"form": {
"label": "Sign out user",
"subtitle": "Signout User"
}
},
"Microsoft.SwitchCondition": {
"form": {
"helpLink": "https://aka.ms/bfc-controlling-conversation-flow",
"hidden": [
"default"
],
"label": "Branch: Switch (multiple options)",
"properties": {
"cases": {
"hidden": [
"actions"
]
},
"condition": {
"intellisenseScopes": [
"user-variables"
]
}
},
"subtitle": "Switch Condition"
}
},
"Microsoft.TextInput": {
"form": {
"helpLink": "https://aka.ms/bfc-ask-for-user-input",
"label": "Prompt for text",
"properties": {
"property": {
"intellisenseScopes": [
"variable-scopes"
]
}
},
"subtitle": "Text Input"
}
},
"Microsoft.ThrowException": {
"form": {
"label": "Throw an exception",
"subtitle": "Throw an exception"
}
},
"Microsoft.TraceActivity": {
"form": {
"helpLink": "https://aka.ms/bfc-debugging-bots",
"label": "Emit a trace event",
"subtitle": "Trace Activity"
}
}
}