using System; using System.Collections; namespace NUnit.Framework { /// /// ListContentsAsserter implements an assertion that a given /// item is found in an array or other List. /// public class ListContentsAsserter : AbstractAsserter { private object expected; private IList list; /// /// Constructs a ListContentsAsserter for a particular list and object. /// /// The expected object /// The list to be examined /// The message to issue on failure /// Arguments to apply in formatting the message public ListContentsAsserter( object expected, IList list, string message, params object[] args ) : base( message, args ) { this.expected = expected; this.list = list; } /// /// Test that the object is contained in the list /// /// True if the object is found public override bool Test() { return list != null && list.Contains( expected ); } /// /// Error message to display after a failure. /// public override string Message { get { FailureMessage.DisplayExpectedValue( expected ); FailureMessage.DisplayListElements( "\t but was: ", list, 0, 5 ); return FailureMessage.ToString(); } } } }