/// <summary> /// Sets the failure message when the assertion is not met, or completes the failure message set to a /// prior call to to <see cref="WithExpectation"/>. /// </summary> /// <remarks> /// In addition to the numbered <see cref="string.Format(string,object[])"/>-style placeholders, messages may contain a few /// specialized placeholders as well. For instance, {reason} will be replaced with the reason of the assertion as passed /// to <see cref="BecauseOf"/>. Other named placeholders will be replaced with the <see cref="Current"/> scope data /// passed through <see cref="AddNonReportable"/> and <see cref="AddReportable"/>. Finally, a description of the /// current subject can be passed through the {context:description} placeholder. This is used in the message if no /// explicit context is specified through the <see cref="AssertionScope"/> constructor. /// Note that only 10 <paramref name="args"/> are supported in combination with a {reason}. /// If an expectation was set through a prior call to <see cref="WithExpectation"/>, then the failure message is appended to that /// expectation. /// </remarks> /// <param name="message">The format string that represents the failure message.</param> /// <param name="args">Optional arguments to any numbered placeholders.</param> public Continuation FailWith(string message, params object[] args) { try { if (evaluateCondition && !Succeeded) { string result = new MessageBuilder(useLineBreaks).Build(message, args, reason, contextData); if (!string.IsNullOrEmpty(expectation)) { result = expectation + result; } assertionStrategy.HandleFailure(result.Capitalize()); } return(new Continuation(this, Succeeded)); } finally { Succeeded = false; } }
/// <summary> /// Define the failure message for the assertion. /// </summary> /// <remarks> /// If the <paramref name="failureMessage"/> contains the text "{reason}", this will be replaced by the reason as /// defined through <see cref="BecauseOf"/>. Only 10 <paramref name="failureArgs"/> are supported in combination with /// a {reason}. /// </remarks> /// <param name="failureMessage">The format string that represents the failure message.</param> /// <param name="failureArgs">Optional arguments for the <paramref name="failureMessage"/></param> public bool FailWith(string failureMessage, params object[] failureArgs) { try { if (!succeeded) { string message = ReplaceReasonTag(failureMessage); message = ReplaceTags(message); message = BuildExceptionMessage(message, failureArgs); assertionStrategy.HandleFailure(message); } return(succeeded); } finally { succeeded = false; } }