/// <exception cref="Exception">Can't compile/invoke <paramref name="requestExpression"/>.</exception> protected AsserterBase(Expression <Func <TRequest> > requestExpression, LogAssertionDelegate log) { _log = log; try { _request = requestExpression.Compile()(); _parameterName = requestExpression.Path(); } catch (Exception e) { log?.Invoke(TraceEventType.Error, $"Can't get object for assertion throuth expression {requestExpression}.\n\n{e}"); throw; } }
public IAssert <TRequest> That(Expression <Func <TRequest, bool> > that) { if (_isDone) { return(this); } var task = Task.Factory.StartNew(() => { try { var callback = that.Compile(); bool result; try { result = callback(_request); } catch { result = false; } if (result) { return(null); } var message = that.ToString(); _log?.Invoke(TraceEventType.Error, $"{typeof (TRequest)}{_parameterName} does not meet the assertion '{message}'", _request); return(FormatExpression(message)); } catch (Exception e) { var message = that.ToString(); _log?.Invoke(TraceEventType.Error, $"{typeof (TRequest)}{_parameterName} does not meet the assertion '{message}'\n'n{e}", _request); return(FormatExpression(message)); } }); _tasks.Add(task); return(this); }