using System; using System.Collections; namespace NUnit.Framework { #region ConditionAsserter /// /// ConditionAsserter class represents an asssertion /// that tests a particular condition, which is passed /// to it in the constructor. The failure message is /// not specialized in this class, but derived classes /// are free to do so. /// public class ConditionAsserter : AbstractAsserter { /// /// The condition we are testing /// protected bool condition; /// /// Phrase indicating what we expected to find /// Ignored unless set by derived class /// protected string expectation; /// /// Constructor /// /// The condition to be tested /// The message issued upon failure /// Arguments to be used in formatting the message public ConditionAsserter( bool condition, string message, params object[] args ) : base( message, args ) { this.condition = condition; } /// /// Test the condition being asserted directly /// public override bool Test() { return condition; } } #endregion #region TrueAsserter /// /// Class to assert that a condition is true /// public class TrueAsserter : ConditionAsserter { /// /// Constructor /// /// The condition to assert /// The message to issue on failure /// Arguments to apply in formatting the message public TrueAsserter( bool condition, string message, params object[] args ) : base( condition, message, args ) { } } #endregion #region FalseAsserter /// /// Class to assert that a condition is false /// public class FalseAsserter : ConditionAsserter { /// /// Constructor /// /// The condition to assert /// The message to issue on failure /// Arguments to apply in formatting the message public FalseAsserter( bool condition, string message, params object[] args ) : base( !condition, message, args ) { } } #endregion #region NullAsserter /// /// Class to assert that an object is null /// public class NullAsserter : ConditionAsserter { /// /// Constructor /// /// The object to test /// The message to issue on failure /// Arguments to apply in formatting the message public NullAsserter( object anObject, string message, params object[] args ) : base( anObject == null, message, args ) { } } #endregion #region NotNullAsserter /// /// Class to assert that an object is not null /// public class NotNullAsserter : ConditionAsserter { /// /// Constructor /// /// The object to test /// The message to issue on failure /// Arguments to apply in formatting the message public NotNullAsserter( object anObject, string message, params object[] args ) : base( anObject != null, message, args ) { } } #endregion #region NaNAsserter /// /// Class to assert that a double is an NaN /// public class NaNAsserter : ConditionAsserter { /// /// Constructor /// /// The value to test /// The message to issue on failure /// Arguments to apply in formatting the message public NaNAsserter( double aDouble, string message, params object[] args ) : base( double.IsNaN( aDouble ), message, args ) { } } #endregion #region EmptyAsserter /// /// Class to Assert that a string or collection is empty /// public class EmptyAsserter : ConditionAsserter { /// /// Construct an EmptyAsserter for a string /// /// The string to be tested /// The message to display if the string is not empty /// Arguements to use in formatting the message public EmptyAsserter( string aString, string message, params object[] args ) : base( aString == string.Empty, message, args ) { } /// /// Construct an EmptyAsserter for a collection /// /// The collection to be tested /// The message to display if the collection is not empty /// Arguements to use in formatting the message public EmptyAsserter( ICollection collection, string message, params object[] args ) : base( collection.Count == 0, message, args ) { } } #endregion #region NotEmptyAsserter /// /// Class to Assert that a string or collection is not empty /// public class NotEmptyAsserter : ConditionAsserter { /// /// Construct a NotEmptyAsserter for a string /// /// The string to be tested /// The message to display if the string is empty /// Arguements to use in formatting the message public NotEmptyAsserter( string aString, string message, params object[] args ) : base( aString != string.Empty, message, args ) { } /// /// Construct a NotEmptyAsserter for a collection /// /// The collection to be tested /// The message to display if the collection is empty /// Arguements to use in formatting the message public NotEmptyAsserter( ICollection collection, string message, params object[] args ) : base( collection.Count != 0, message, args ) { } } #endregion }