Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
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 @@ -36,6 +36,7 @@ public virtual IEnumerable<DeclarativeType> GetDeclarativeTypes(ResourceExplorer
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
Expand Down Expand Up @@ -62,7 +61,7 @@ await inspector((dc) =>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ await inspector((dc) =>
{
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]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>
Expand Down Expand Up @@ -173,16 +179,10 @@ await adapter.ProcessActivityAsync(
async (turnContext, cancellationToken) => await di.InspectAsync(turnContext, inspector).ConfigureAwait(false)).ConfigureAwait(false);
}

if (callback != null)
{
foreach (var testAction in Script)
{
await testAction.ExecuteAsync(adapter, callback, Inspect).ConfigureAwait(false);
}
}
else
DialogManager dm;
if (callback == null)
{
var dm = new DialogManager(Dialog)
dm = new DialogManager(Dialog)
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

Expand All @@ -191,10 +191,12 @@ await adapter.ProcessActivityAsync(
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PropertySchema(string path, JObject schema, List<PropertySchema> children
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
{
"$kind": "Microsoft.SendActivity",
"activity": "Set bread to rye"
},
{
"$kind": "Microsoft.SetProperty",
"property": "$Bread",
"value": "@BreadEntity"
}
]
}
Expand Down Expand Up @@ -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"
},
Expand All @@ -106,6 +112,9 @@
"assertions": [
"!$retries"
]
},
{
"$kind": "Microsoft.Test.AssertNoActivity",
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@
"whiteOnions",
"redOnions"
],
"maxItems": 3
"maxItems": 3,
"$entities": [
"ToppingsEntity"
]
},
"$entities": [
"ToppingsEntity"
]
},
"Sauces": {
"type": "array",
Expand Down
41 changes: 41 additions & 0 deletions tests/tests.schema
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@
{
"$ref": "#/definitions/Microsoft.Test.AssertCondition"
},
{
"$ref": "#/definitions/Microsoft.Test.AssertNoActivity"
},
{
"$ref": "#/definitions/Microsoft.Test.AssertReply"
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
Loading