public static string BuildMessage(MustAssertionRecord assertionRecord) { var _newLine = Environment.NewLine; var _s = assertionRecord?.Description == null ? "Assertion failed" : $"Assertion failed: Asserts that {assertionRecord.Description}"; if (assertionRecord?.CallerFilePath != null) { _s += $"{_newLine}Location: {assertionRecord.CallerFilePath}"; if (assertionRecord.CallerLineNumber.GetValueOrDefault() != 0) { _s += $":{assertionRecord.CallerLineNumber}"; } } if (assertionRecord?.CallerMemberName != null) { _s += $"{_newLine}Member: {assertionRecord.CallerMemberName}"; } if (assertionRecord?.Data?.Count > 0) { foreach (var _data in assertionRecord.Data) { string _dataString; try { _dataString = _data.Value?.ToString() ?? "<null>"; } catch (Exception _exception) { _dataString = $"<unrepresentable: {_exception.Message}>"; } _s += $"{_newLine}{_data.Key} <{_data.Type}>: {_dataString}"; } } return(_s); }
public static Exception CreateAssertionException( [CanBeNull][InstantHandle] TransformExceptionDelegate transformException, [CanBeNull] MustAssertionRecord assertionRecord, [CanBeNull] params Exception[] additionalExceptions) { var _assertionException = new MustAssertionException(assertionRecord); Exception _transformedException; Exception _transformExceptionErrorException; if (transformException == null) { _transformedException = _assertionException; _transformExceptionErrorException = null; } else { try { _transformedException = transformException(_assertionException) ?? _assertionException; _transformExceptionErrorException = null; } catch (Exception _exception) { _transformedException = _assertionException; _transformExceptionErrorException = _exception; } } var _finalException = ExceptionHelper.Combine( ExceptionHelper.Yield(_transformedException), ExceptionHelper.Yield(_transformExceptionErrorException), additionalExceptions); return(_finalException); }