/// <summary> /// Validates an <see cref="Activity"/> according to an expected activity <see cref="TestScriptItem"/> using XUnit. /// </summary> /// <param name="expectedActivity">The expected activity of type <see cref="TestScriptItem"/>.</param> /// <param name="actualActivity">The actual response <see cref="Activity"/> recieved.</param> /// <param name="cancellationToken">Optional. A <see cref="CancellationToken"/> that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A task that represents the work queued to execute.</returns> protected override Task AssertActivityAsync(TestScriptItem expectedActivity, Activity actualActivity, CancellationToken cancellationToken = default) { foreach (var assertion in expectedActivity.Assertions) { var(result, error) = Expression.Parse(assertion).TryEvaluate <bool>(actualActivity); Assert.True(result, $"The bot's response was different than expected. The assertion: \"{assertion}\" was evaluated as false.\nExpected Activity:\n{JsonConvert.SerializeObject(expectedActivity, Formatting.Indented)}\nActual Activity:\n{JsonConvert.SerializeObject(actualActivity, Formatting.Indented)}"); } return(Task.CompletedTask); }
/// <summary> /// Validates an <see cref="Activity"/> according to an expected activity <see cref="TestScriptItem"/> using XUnit. /// </summary> /// <param name="expectedActivity">The expected activity of type <see cref="TestScriptItem"/>.</param> /// <param name="actualActivity">The actual response <see cref="Activity"/> received.</param> /// <param name="cancellationToken">Optional. A <see cref="CancellationToken"/> that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A task that represents the work queued to execute.</returns> protected override Task AssertActivityAsync(TestScriptItem expectedActivity, Activity actualActivity, CancellationToken cancellationToken = default) { var templateRegex = new Regex(@"\{\{[\w\s]*\}\}"); foreach (var assertion in expectedActivity.Assertions) { var template = templateRegex.Match(assertion); if (template.Success) { ValidateVariable(template.Value, actualActivity); } var(result, _) = Expression.Parse(assertion).TryEvaluate <bool>(actualActivity); Assert.True(result, $"The bot's response was different than expected. The assertion: \"{assertion}\" was evaluated as false.\nExpected Activity:\n{JsonConvert.SerializeObject(expectedActivity, Formatting.Indented)}\nActual Activity:\n{JsonConvert.SerializeObject(actualActivity, Formatting.Indented)}"); } return(Task.CompletedTask); }