/// <summary> /// If (a) <paramref name="expression"/> is of type `bool` and (b) it is `false`, attempts to return a string representation of *why* it is `false`. /// Otherwise, behaves the same as <see cref="GetFullString"/>. /// <paramref name="expression"/> must be compilable without arguments. /// </summary> public static (string ExpressionString, IReadOnlyCollection <(string Name, object Value)> DebugValues) GetDiagnosticString(Expression expression) { var vistor = new DebugValueExpressionVisitor(); vistor.VisitDiagnosticRoot(expression); return(vistor.ToString(), vistor.DebugValues); }
/// <summary> /// Starts a chain of assertions on <paramref name="value"/>. /// Asserts that <paramref name="value"/> is not `null`. /// </summary> public static Assertable <T> HasValue <T>(T value, string name = null) where T : class { var parameter = DebugValueExpressionVisitor.GetDebugExpresssion(name ?? "value", value); if (value == null) { TestFrameworkProvider.Fail(GetDiagnosticMessage(Expression.NotEqual(parameter, Expression.Constant(null, typeof(T))), null, s_emptyContext)); return(Assertable <T> .NoOp()); } return(Assertable <T> .FromValueExpression(value, parameter)); }