Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
// ****************************************************************
// 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 NUnit.Framework.Constraints;
namespace NUnit.Framework.SyntaxHelpers
{
/// <summary>
/// Summary description for HasNoPrefixB.
/// </summary>
public class Has
{
/// <summary>
/// Nested class that allows us to restrict the number
/// of key words that may appear after Has.No.
/// </summary>
public class HasNoPrefixBuilder
{
/// <summary>
/// Return a ConstraintBuilder conditioned to apply
/// the following constraint to a property.
/// </summary>
/// <param name="name">The property name</param>
/// <returns>A ConstraintBuilder</returns>
public ConstraintBuilder Property(string name)
{
return new ConstraintBuilder().Not.Property(name);
}
/// <summary>
/// Return a Constraint that succeeds if the expected object is
/// not contained in a collection.
/// </summary>
/// <param name="expected">The expected object</param>
/// <returns>A Constraint</returns>
public Constraint Member(object expected)
{
return new NotConstraint( new CollectionContainsConstraint(expected) ) ;
}
}
#region Prefix Operators
/// <summary>
/// Has.No returns a ConstraintBuilder that negates
/// the constraint that follows it.
/// </summary>
public static HasNoPrefixBuilder No
{
get { return new HasNoPrefixBuilder(); }
}
/// <summary>
/// Has.AllItems returns a ConstraintBuilder, which will apply
/// the following constraint to all members of a collection,
/// succeeding if all of them succeed.
/// </summary>
public static ConstraintBuilder All
{
get { return new ConstraintBuilder().All; }
}
/// <summary>
/// Has.Some returns a ConstraintBuilder, which will apply
/// the following constraint to all members of a collection,
/// succeeding if any of them succeed. It is a synonym
/// for Has.Item.
/// </summary>
public static ConstraintBuilder Some
{
get { return new ConstraintBuilder().Some; }
}
/// <summary>
/// Has.None returns a ConstraintBuilder, which will apply
/// the following constraint to all members of a collection,
/// succeeding only if none of them succeed.
/// </summary>
public static ConstraintBuilder None
{
get { return new ConstraintBuilder().None; }
}
/// <summary>
/// Returns a new ConstraintBuilder, which will apply the
/// following constraint to a named property of the object
/// being tested.
/// </summary>
/// <param name="name">The name of the property</param>
public static ConstraintBuilder Property( string name )
{
return new ConstraintBuilder().Property(name);
}
#endregion
#region Property Constraints
/// <summary>
/// Returns a new PropertyConstraint checking for the
/// existence of a particular property value.
/// </summary>
/// <param name="name">The name of the property to look for</param>
/// <param name="expected">The expected value of the property</param>
public static Constraint Property( string name, object expected )
{
return new PropertyConstraint( name, new EqualConstraint( expected ) );
}
/// <summary>
/// Returns a new PropertyConstraint for the Length property
/// </summary>
/// <param name="length"></param>
/// <returns></returns>
public static Constraint Length( int length )
{
return Property( "Length", length );
}
/// <summary>
/// Returns a new PropertyConstraint or the Count property
/// </summary>
/// <param name="count"></param>
/// <returns></returns>
public static Constraint Count( int count )
{
return Property( "Count", count );
}
#endregion
#region Member Constraint
/// <summary>
/// Returns a new CollectionContainsConstraint checking for the
/// presence of a particular object in the collection.
/// </summary>
/// <param name="expected">The expected object</param>
public static Constraint Member( object expected )
{
return new CollectionContainsConstraint( expected );
}
#endregion
}
}

View File

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

View File

@@ -0,0 +1,30 @@
// ****************************************************************
// 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
{
/// <summary>
/// The List class is a helper class with properties and methods
/// that supply a number of constraints used with lists and collections.
/// </summary>
public class List
{
/// <summary>
/// List.Map returns a ListMapper, which can be used to map
/// the original collection to another collection.
/// </summary>
/// <param name="actual"></param>
/// <returns></returns>
public static ListMapper Map( ICollection actual )
{
return new ListMapper( actual );
}
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections;
using System.Reflection;
namespace NUnit.Framework.SyntaxHelpers
{
/// <summary>
/// ListMapper is used to transform a collection used as an actual argument
/// producing another collection to be used in the assertion.
/// </summary>
public class ListMapper
{
ICollection original;
/// <summary>
/// Construct a ListMapper based on a collection
/// </summary>
/// <param name="original">The collection to be transformed</param>
public ListMapper( ICollection original )
{
this.original = original;
}
/// <summary>
/// Produces a collection containing all the values of a property
/// </summary>
/// <param name="name">The collection of property values</param>
/// <returns></returns>
public ICollection Property( string name )
{
ArrayList propList = new ArrayList();
foreach( object item in original )
{
PropertyInfo property = item.GetType().GetProperty( name,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
if ( property == null )
throw new ArgumentException( string.Format(
"{0} does not have a {1} property", item, name ) );
propList.Add( property.GetValue( item, null ) );
}
return propList;
}
}
}

View File

@@ -0,0 +1,104 @@
// ****************************************************************
// 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 NUnit.Framework.Constraints;
namespace NUnit.Framework.SyntaxHelpers
{
/// <summary>
/// The Text class is a helper class with properties and methods
/// that supply a number of constraints used with strings.
/// </summary>
public class Text
{
/// <summary>
/// Text.All returns a ConstraintBuilder, which will apply
/// the following constraint to all members of a collection,
/// succeeding if all of them succeed.
/// </summary>
public static ConstraintBuilder All
{
get { return new ConstraintBuilder().All; }
}
/// <summary>
/// Contains returns a constraint that succeeds if the actual
/// value contains the substring supplied as an argument.
/// </summary>
public static Constraint Contains(string substring)
{
return new SubstringConstraint(substring);
}
/// <summary>
/// DoesNotContain returns a constraint that fails if the actual
/// value contains the substring supplied as an argument.
/// </summary>
public static Constraint DoesNotContain(string substring)
{
return new NotConstraint( Contains(substring) );
}
/// <summary>
/// StartsWith returns a constraint that succeeds if the actual
/// value starts with the substring supplied as an argument.
/// </summary>
public static Constraint StartsWith(string substring)
{
return new StartsWithConstraint(substring);
}
/// <summary>
/// DoesNotStartWith returns a constraint that fails if the actual
/// value starts with the substring supplied as an argument.
/// </summary>
public static Constraint DoesNotStartWith(string substring)
{
return new NotConstraint( StartsWith(substring) );
}
/// <summary>
/// EndsWith returns a constraint that succeeds if the actual
/// value ends with the substring supplied as an argument.
/// </summary>
public static Constraint EndsWith(string substring)
{
return new EndsWithConstraint(substring);
}
/// <summary>
/// DoesNotEndWith returns a constraint that fails if the actual
/// value ends with the substring supplied as an argument.
/// </summary>
public static Constraint DoesNotEndWith(string substring)
{
return new NotConstraint( EndsWith(substring) );
}
/// <summary>
/// Matches returns a constraint that succeeds if the actual
/// value matches the pattern supplied as an argument.
/// </summary>
/// <param name="pattern"></param>
/// <returns></returns>
public static Constraint Matches(string pattern)
{
return new RegexConstraint(pattern);
}
/// <summary>
/// DoesNotMatch returns a constraint that failss if the actual
/// value matches the pattern supplied as an argument.
/// </summary>
/// <param name="pattern"></param>
/// <returns></returns>
public static Constraint DoesNotMatch(string pattern)
{
return new NotConstraint( Matches(pattern) );
}
}
}