public async Task Intents_ValidateEnablerOrder() { IntentRecognizerMiddleware m = new IntentRecognizerMiddleware(); string shouldRun = "first"; /* * Filters are required to run in reverse order. This code validates that by registering 3 filters and * running a simple state machine across them. */ m.OnEnabled(async(context) => { Assert.IsTrue(shouldRun == "first", "1st enabler did not run first."); shouldRun = "second"; return(true); }); m.OnEnabled(async(context) => { Assert.IsTrue(shouldRun == "second", "2nd enabler did not run second"); shouldRun = "third"; return(true); }); m.OnEnabled(async(context) => { Assert.IsTrue(shouldRun == "third", "3rd enabler did not run last"); shouldRun = "done"; return(true); }); TurnContext bc = TestUtilities.CreateEmptyContext(); shouldRun = "first"; var resultingIntents = await m.Recognize(bc); Assert.IsTrue(shouldRun == "done", "Final recognizer did not run"); }
public async Task Intents_DisableIntent() { string targetName = Guid.NewGuid().ToString(); IntentRecognizerMiddleware m = new IntentRecognizerMiddleware(); m.OnRecognize(async(context) => { return(new List <Intent> { new Intent() { Name = targetName }, }); }); bool enabled = false; m.OnEnabled(async(context) => { return(enabled); }); TurnContext bc = TestUtilities.CreateEmptyContext(); // Test that the Intent comes back when the OnEnabled method returns true enabled = true; var resultingIntents = await m.Recognize(bc); Assert.IsTrue(resultingIntents.Count == 1, "Expected exactly 1 intent"); Assert.IsTrue(resultingIntents.First().Name == targetName, $"Unexpected Intent Name. Expected {targetName}"); // Test that NO Intent comes back when the OnEnabled method returns false enabled = false; var resultingIntents2 = await m.Recognize(bc); Assert.IsTrue(resultingIntents2.Count == 0, "Expected exactly 0 intent"); }