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 @@ -143,8 +143,9 @@ public TestAdapter DefaultTestAdapter(ResourceExplorer resourceExplorer, [Caller
/// <param name="testName">Name of the test.</param>
/// <param name="callback">The bot logic.</param>
/// <param name="adapter">optional test adapter.</param>
/// <param name="languagePolicy">The default language policy.</param>
/// <returns>Runs the exchange between the user and the bot.</returns>
public async Task ExecuteAsync(ResourceExplorer resourceExplorer, [CallerMemberName] string testName = null, BotCallbackHandler callback = null, TestAdapter adapter = null)
public async Task ExecuteAsync(ResourceExplorer resourceExplorer, [CallerMemberName] string testName = null, BotCallbackHandler callback = null, TestAdapter adapter = null, LanguagePolicy languagePolicy = null)
{
if (adapter == null)
{
Expand Down Expand Up @@ -185,6 +186,11 @@ await adapter.ProcessActivityAsync(
.UseResourceExplorer(resourceExplorer)
.UseLanguageGeneration();

if (languagePolicy != null)
{
dm.UseLanguagePolicy(languagePolicy);
}

foreach (var testAction in Script)
{
await testAction.ExecuteAsync(adapter, dm.OnTurnAsync, Inspect).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MultiLanguageRecognizer([CallerFilePath] string callerPath = "", [CallerL
/// </value>
[JsonProperty("languagePolicy")]
#pragma warning disable CA2227 // Collection properties should be read only (we can't change this without breaking binary compat)
public LanguagePolicy LanguagePolicy { get; set; } = new LanguagePolicy();
public LanguagePolicy LanguagePolicy { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
Expand All @@ -66,13 +66,17 @@ public MultiLanguageRecognizer([CallerFilePath] string callerPath = "", [CallerL
/// <returns>Analysis of utterance.</returns>
public override async Task<RecognizerResult> RecognizeAsync(DialogContext dialogContext, Activity activity, CancellationToken cancellationToken = default, Dictionary<string, string> telemetryProperties = null, Dictionary<string, double> telemetryMetrics = null)
{
var languagePolicy = LanguagePolicy ??
dialogContext.Services.Get<LanguagePolicy>() ??
new LanguagePolicy();

var policy = new List<string>();
if (activity.Locale != null && LanguagePolicy.TryGetValue(activity.Locale, out string[] targetpolicy))
if (activity.Locale != null && languagePolicy.TryGetValue(activity.Locale, out string[] targetpolicy))
{
policy.AddRange(targetpolicy);
}

if (LanguagePolicy.TryGetValue(string.Empty, out string[] defaultPolicy))
if (languagePolicy.TryGetValue(string.Empty, out string[] defaultPolicy))
{
// we now explictly add defaultPolicy instead of coding that into target's policy
policy.AddRange(defaultPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,12 @@ public async Task MultiLanguageRecognizerTest_DefaultFallback()
{
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer);
}

[Fact]
public async Task MultiLanguageRecognizerTest_LanguagePolicy()
{
var languagePolicy = new LanguagePolicy("en-gb");
await TestUtils.RunTestScript(_resourceExplorerFixture.ResourceExplorer, languagePolicy: languagePolicy);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public static IEnumerable<object[]> GetTestScripts(string relativeFolder)
return Directory.EnumerateFiles(testFolder, "*.test.dialog", SearchOption.AllDirectories).Select(s => new object[] { Path.GetFileName(s) }).ToArray();
}

public static async Task RunTestScript(ResourceExplorer resourceExplorer, string resourceId = null, IConfiguration configuration = null, [CallerMemberName] string testName = null)
public static async Task RunTestScript(ResourceExplorer resourceExplorer, string resourceId = null, IConfiguration configuration = null, [CallerMemberName] string testName = null, LanguagePolicy languagePolicy = null)
{
var script = resourceExplorer.LoadType<TestScript>(resourceId ?? $"{testName}.test.dialog");
script.Configuration = configuration ?? new ConfigurationBuilder().AddInMemoryCollection().Build();
script.Description = script.Description ?? resourceId;
await script.ExecuteAsync(testName: testName, resourceExplorer: resourceExplorer).ConfigureAwait(false);
await script.ExecuteAsync(testName: testName, resourceExplorer: resourceExplorer, languagePolicy: languagePolicy).ConfigureAwait(false);
}

public static string GetProjectPath()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"$schema": "../../../tests.schema",
"$kind": "Microsoft.Test.Script",
"dialog": {
"$kind": "Microsoft.AdaptiveDialog",
"recognizer": {
"$kind": "Microsoft.MultiLanguageRecognizer",
"recognizers": {
"en-us": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"pattern": "(?i)howdy"
},
{
"intent": "Goodbye",
"pattern": "(?i)bye"
}
]
},
"en-gb": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"pattern": "(?i)hiya"
},
{
"intent": "Goodbye",
"pattern": "(?i)cheerio"
}
]
},
"en": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"pattern": "(?i)hello"
},
{
"intent": "Goodbye",
"pattern": "(?i)goodbye"
}
]
},
"": {
"$kind": "Microsoft.RegexRecognizer",
"intents": [
{
"intent": "Greeting",
"pattern": "(?i)salve"
},
{
"intent": "Goodbye",
"pattern": "(?i)vale dicere"
}
]
}
}
},
"triggers": [
{
"$kind": "Microsoft.OnIntent",
"intent": "Greeting",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "greeting intent"
}
]
},
{
"$kind": "Microsoft.OnIntent",
"intent": "Goodbye",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "goodbye intent"
}
]
},
{
"$kind": "Microsoft.OnUnknownIntent",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "default rule"
}
]
}
],
"defaultResultProperty": "dialog.result"
},
"locale": "",
"script": [
{
"$kind": "Microsoft.Test.UserSays",
"text": "hiya"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "greeting intent"
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "howdy"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "default rule"
},
{
"$kind": "Microsoft.Test.UserSays",
"text": "cheerio"
},
{
"$kind": "Microsoft.Test.AssertReply",
"text": "goodbye intent"
}
]
}