/// <summary> /// Calls the recognizer's `RecognizeAsync` method and validates appropriate telemetry properties are logged. /// </summary> /// <param name="text">The activity's text used run recognition against.</param> /// <param name="recognizer">The recognizer used to call `RecognizeAsync`.</param> /// <param name="telemetryClient">The telemetry client used to log telemetry.</param> /// <param name="callCount">How many times the telemetry client should have logged the `RecognizerResult` of our target recognizer.</param> /// <returns>Task representing the validation work done.</returns> internal static async Task RecognizeIntentAndValidateTelemetry(string text, AdaptiveRecognizer recognizer, Mock <IBotTelemetryClient> telemetryClient, int callCount) { var dc = TestUtils.CreateContext(text); var activity = dc.Context.Activity; var result = await recognizer.RecognizeAsync(dc, activity, CancellationToken.None); if (ValidateIntent.ContainsKey(text)) { ValidateIntent[text](result); } ValidateTelemetry(recognizer, telemetryClient, dc, activity, result, callCount); }
/// <summary> /// Ensure recognizer correctly logs telemetry. /// /// More specifically, verify that <see cref="IBotTelemetryClient"/>.TrackEvent is called with: /// <list type="bullet"> /// <item>Appropriate event name (e.g. "RegexRecognizerResult" for <see cref="RegexRecognizer"/>.</item> /// <item>Recognizer properly called <see cref="IBotTelemetryClient.TrackEvent(string, IDictionary{string, string}, IDictionary{string, double})"/> method to log telemetry with correct telemetry properties.</item> /// <item><see cref="IBotTelemetryClient"/>.TrackEvent is called correct number of times.</item> /// </list> /// </summary> /// <param name="recognizer">The recognizer used to call `RecognizeAsync` and, in turn, that logged telemetry.</param> /// <param name="telemetryClient">The telemetry client used to log telemetry.</param> /// <param name="dc">The <see cref="DialogContext"/>.</param> /// <param name="activity">The activity used to recognize intent with in `RecognizeAsync`.</param> /// <param name="result">The <see cref="RecognizerResult"/>.</param> /// <param name="callCount">How many times the telemetry client should have logged the `RecognizerResult` of our target recognizer.</param> internal static void ValidateTelemetry(AdaptiveRecognizer recognizer, Mock <IBotTelemetryClient> telemetryClient, DialogContext dc, IActivity activity, RecognizerResult result, int callCount) { var eventName = $"{recognizer.GetType().Name}Result"; var(logPersonalInfo, error) = recognizer.LogPersonalInformation.TryGetValue(dc.State); var actualTelemetryProps = (IDictionary <string, string>)telemetryClient.Invocations[callCount - 1].Arguments[1]; var expectedTelemetryProps = GetExpectedProps(activity, result, logPersonalInfo); telemetryClient.Verify( client => client.TrackEvent( eventName, It.Is <Dictionary <string, string> >(d => HasValidTelemetryProps(expectedTelemetryProps, actualTelemetryProps, activity)), null), Times.Exactly(callCount)); }
/// <summary> /// Calls the recognizer's `RecognizeAsync` method and validates appropriate telemetry properties are logged, /// using a custom activity, separate from the activity found in <see cref="DialogContext"/>. /// </summary> /// <param name="text">The activity's text used run recognition against.</param> /// <param name="recognizer">The recognizer used to call `RecognizeAsync`.</param> /// <param name="telemetryClient">The telemetry client used to log telemetry.</param> /// <param name="callCount">How many times the telemetry client should have logged the `RecognizerResult` of our target recognizer.</param> /// <returns>Task representing the validation work done.</returns> internal static async Task RecognizeIntentAndValidateTelemetry_WithCustomActivity(string text, AdaptiveRecognizer recognizer, Mock <IBotTelemetryClient> telemetryClient, int callCount) { var dc = TestUtils.CreateContext(string.Empty); var customActivity = Activity.CreateMessageActivity(); customActivity.Text = text; customActivity.Locale = Culture.English; var result = await recognizer.RecognizeAsync(dc, (Activity)customActivity, CancellationToken.None); if (ValidateIntent.ContainsKey(text)) { ValidateIntent[text](result); } ValidateTelemetry(recognizer, telemetryClient, dc, (Activity)customActivity, result, callCount); }