// **************************************************************** // 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; using NUnit.Framework.Constraints; namespace NUnit.Framework.SyntaxHelpers { /// /// The Is class is a helper class with properties and methods /// that supply a number of constraints used in Asserts. /// public class Is { #region Prefix Operators /// /// Is.Not returns a ConstraintBuilder that negates /// the constraint that follows it. /// public static ConstraintBuilder Not { get { return new ConstraintBuilder().Not; } } /// /// Is.All returns a ConstraintBuilder, which will apply /// the following constraint to all members of a collection, /// succeeding if all of them succeed. This property is /// a synonym for Has.AllItems. /// public static ConstraintBuilder All { get { return new ConstraintBuilder().All; } } #endregion #region Constraints Without Arguments /// /// Is.Null returns a static constraint that tests for null /// public static readonly Constraint Null = new EqualConstraint( null ); /// /// Is.True returns a static constraint that tests whether a value is true /// public static readonly Constraint True = new EqualConstraint(true); /// /// Is.False returns a static constraint that tests whether a value is false /// public static readonly Constraint False = new EqualConstraint(false); /// /// Is.NaN returns a static constraint that tests whether a value is an NaN /// public static readonly Constraint NaN = new EqualConstraint(double.NaN); /// /// Is.Empty returns a static constraint that tests whether a string or collection is empty /// public static readonly Constraint Empty = new EmptyConstraint(); /// /// Is.Unique returns a static constraint that tests whether a collection contains all unque items. /// public static readonly Constraint Unique = new UniqueItemsConstraint(); #endregion #region Constraints with an expected value #region Equality and Identity /// /// Is.EqualTo returns a constraint that tests whether the /// actual value equals the supplied argument /// /// /// public static EqualConstraint EqualTo(object expected) { return new EqualConstraint(expected); } /// /// Is.SameAs returns a constraint that tests whether the /// actual value is the same object as the supplied argument. /// /// /// public static Constraint SameAs(object expected) { return new SameAsConstraint(expected); } #endregion #region Comparison Constraints /// /// Is.GreaterThan returns a constraint that tests whether the /// actual value is greater than the suppled argument /// public static Constraint GreaterThan(IComparable expected) { return new GreaterThanConstraint(expected); } /// /// Is.GreaterThanOrEqualTo returns a constraint that tests whether the /// actual value is greater than or equal to the suppled argument /// public static Constraint GreaterThanOrEqualTo(IComparable expected) { return new GreaterThanOrEqualConstraint(expected); } /// /// Is.AtLeast is a synonym for Is.GreaterThanOrEqualTo /// public static Constraint AtLeast(IComparable expected) { return GreaterThanOrEqualTo(expected); } /// /// Is.LessThan returns a constraint that tests whether the /// actual value is less than the suppled argument /// public static Constraint LessThan(IComparable expected) { return new LessThanConstraint(expected); } /// /// Is.LessThanOrEqualTo returns a constraint that tests whether the /// actual value is less than or equal to the suppled argument /// public static Constraint LessThanOrEqualTo(IComparable expected) { return new LessThanOrEqualConstraint(expected); } /// /// Is.AtMost is a synonym for Is.LessThanOrEqualTo /// public static Constraint AtMost(IComparable expected) { return LessThanOrEqualTo(expected); } #endregion #region Type Constraints /// /// Is.TypeOf returns a constraint that tests whether the actual /// value is of the exact type supplied as an argument. /// public static Constraint TypeOf(Type expectedType) { return new ExactTypeConstraint(expectedType); } /// /// Is.InstanceOfType returns a constraint that tests whether /// the actual value is of the type supplied as an argument /// or a derived type. /// public static Constraint InstanceOfType(Type expectedType) { return new InstanceOfTypeConstraint(expectedType); } /// /// Is.AssignableFrom returns a constraint that tests whether /// the actual value is assignable from the type supplied as /// an argument. /// /// /// public static Constraint AssignableFrom(Type expectedType) { return new AssignableFromConstraint(expectedType); } #endregion #region Collection Constraints /// /// Is.EquivalentTo returns a constraint that tests whether /// the actual value is a collection containing the same /// elements as the collection supplied as an arument /// public static Constraint EquivalentTo(ICollection expected) { return new CollectionEquivalentConstraint(expected); } /// /// Is.SubsetOf returns a constraint that tests whether /// the actual value is a subset of the collection /// supplied as an arument /// public static Constraint SubsetOf(ICollection expected) { return new CollectionSubsetConstraint(expected); } #endregion #endregion } /// /// The Iz class is a synonym for Is intended for use in VB, /// which regards Is as a keyword. /// public class Iz : Is { } }