// **************************************************************** // 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.Collections; namespace NUnit.Framework.Constraints { /// /// EmptyConstraint tests a whether a string or collection is empty, /// postponing the decision about which test is applied until the /// type of the actual argument is known. /// public class EmptyConstraint : Constraint { private Constraint RealConstraint { get { if ( actual is string ) return new EmptyStringConstraint(); else return new EmptyCollectionConstraint(); } } /// /// Test whether the constraint is satisfied by a given value /// /// The value to be tested /// True for success, false for failure public override bool Matches(object actual) { this.actual = actual; return this.RealConstraint.Matches( actual ); } /// /// Write the constraint description to a MessageWriter /// /// The writer on which the description is displayed public override void WriteDescriptionTo(MessageWriter writer) { this.RealConstraint.WriteDescriptionTo( writer ); } } }