// ****************************************************************
// Copyright 2007, Charlie Poole
// This is free software licensed under the NUnit license. You may
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
// ****************************************************************
using System;
using System.IO;
using System.Collections;
using NUnit.Framework.Constraints;
namespace NUnit.Framework
{
///
/// MessageWriter is the abstract base for classes that write
/// constraint descriptions and messages in some form. The
/// class has separate methods for writing various components
/// of a message, allowing implementations to tailor the
/// presentation as needed.
///
public abstract class MessageWriter : StringWriter
{
///
/// Construct a MessageWriter given a culture
///
public MessageWriter() : base( System.Globalization.CultureInfo.InvariantCulture ) { }
///
/// Abstract method to get the max line length
///
public abstract int MaxLineLength { get; set; }
///
/// Method to write single line message with optional args, usually
/// written to precede the general failure message.
///
/// The message to be written
/// Any arguments used in formatting the message
public void WriteMessageLine(string message, params object[] args)
{
WriteMessageLine(0, message, args);
}
///
/// Method to write single line message with optional args, usually
/// written to precede the general failure message, at a givel
/// indentation level.
///
/// The indentation level of the message
/// The message to be written
/// Any arguments used in formatting the message
public abstract void WriteMessageLine(int level, string message, params object[] args);
///
/// Display Expected and Actual lines for a constraint. This
/// is called by MessageWriter's default implementation of
/// WriteMessageTo and provides the generic two-line display.
///
/// The constraint that failed
public abstract void DisplayDifferences(Constraint constraint);
///
/// Display Expected and Actual lines for given values. This
/// method may be called by constraints that need more control over
/// the display of actual and expected values than is provided
/// by the default implementation.
///
/// The expected value
/// The actual value causing the failure
public abstract void DisplayDifferences(object expected, object actual);
///
/// Display Expected and Actual lines for given values, including
/// a tolerance value on the Expected line.
///
/// The expected value
/// The actual value causing the failure
/// The tolerance within which the test was made
public abstract void DisplayDifferences(object expected, object actual, object tolerance);
///
/// Display the expected and actual string values on separate lines.
/// If the mismatch parameter is >=0, an additional line is displayed
/// line containing a caret that points to the mismatch point.
///
/// The expected string value
/// The actual string value
/// The point at which the strings don't match or -1
/// If true, case is ignored in locating the point where the strings differ
/// If true, the strings should be clipped to fit the line
public abstract void DisplayStringDifferences(string expected, string actual, int mismatch, bool ignoreCase, bool clipping);
///
/// Writes the text for a connector.
///
/// The connector.
public abstract void WriteConnector(string connector);
///
/// Writes the text for a predicate.
///
/// The predicate.
public abstract void WritePredicate(string predicate);
///
/// Writes the text for an expected value.
///
/// The expected value.
public abstract void WriteExpectedValue(object expected);
///
/// Writes the text for a modifier
///
/// The modifier.
public abstract void WriteModifier(string modifier);
///
/// Writes the text for an actual value.
///
/// The actual value.
public abstract void WriteActualValue(object actual);
///
/// Writes the text for a generalized value.
///
/// The value.
public abstract void WriteValue(object val);
///
/// Writes the text for a collection value,
/// starting at a particular point, to a max length
///
/// The collection containing elements to write.
/// The starting point of the elements to write
/// The maximum number of elements to write
public abstract void WriteCollectionElements(ICollection collection, int start, int max);
}
}