/// <summary> /// Validates an <see cref="Activity"/> according to an expected activity <see cref="TestScriptItem"/>. /// </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 virtual 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, error) = Expression.Parse(assertion).TryEvaluate <bool>(actualActivity); if (!result) { throw new InvalidOperationException($"Assertion failed: {assertion}."); } if (error != null) { throw new InvalidOperationException(error); } } return(Task.CompletedTask); }
private bool IgnoreScriptActivity(TestScriptItem activity) { return(activity.Type == ActivityTypes.Trace || activity.Type == ActivityTypes.Typing); }