// ****************************************************************
// 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.ComponentModel;
using NUnit.Framework.Constraints;
namespace NUnit.Framework
{
///
/// Basic Asserts on strings.
///
public class StringAssert
{
#region Equals and ReferenceEquals
///
/// The Equals method throws an AssertionException. This is done
/// to make sure there is no mistake by calling this function.
///
///
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static new bool Equals(object a, object b)
{
throw new AssertionException("Assert.Equals should not be used for Assertions");
}
///
/// override the default ReferenceEquals to throw an AssertionException. This
/// implementation makes sure there is no mistake in calling this function
/// as part of Assert.
///
///
///
public static new void ReferenceEquals(object a, object b)
{
throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");
}
#endregion
#region Contains
///
/// Asserts that a string is found within another string.
///
/// The expected string
/// The string to be examined
/// The message to display in case of failure
/// Arguments used in formatting the message
static public void Contains( string expected, string actual, string message, params object[] args )
{
Assert.That(actual, new SubstringConstraint(expected), message, args);
}
///
/// Asserts that a string is found within another string.
///
/// The expected string
/// The string to be examined
/// The message to display in case of failure
static public void Contains( string expected, string actual, string message )
{
Contains( expected, actual, message, null );
}
///
/// Asserts that a string is found within another string.
///
/// The expected string
/// The string to be examined
static public void Contains( string expected, string actual )
{
Contains( expected, actual, string.Empty, null );
}
#endregion
#region StartsWith
///
/// Asserts that a string starts with another string.
///
/// The expected string
/// The string to be examined
/// The message to display in case of failure
/// Arguments used in formatting the message
static public void StartsWith( string expected, string actual, string message, params object[] args )
{
Assert.That(actual, new StartsWithConstraint(expected), message, args);
}
///
/// Asserts that a string starts with another string.
///
/// The expected string
/// The string to be examined
/// The message to display in case of failure
static public void StartsWith( string expected, string actual, string message )
{
StartsWith( expected, actual, message, null );
}
///
/// Asserts that a string starts with another string.
///
/// The expected string
/// The string to be examined
static public void StartsWith( string expected, string actual )
{
StartsWith( expected, actual, string.Empty, null );
}
#endregion
#region EndsWith
///
/// Asserts that a string ends with another string.
///
/// The expected string
/// The string to be examined
/// The message to display in case of failure
/// Arguments used in formatting the message
static public void EndsWith( string expected, string actual, string message, params object[] args )
{
Assert.That(actual, new EndsWithConstraint(expected), message, args);
}
///
/// Asserts that a string ends with another string.
///
/// The expected string
/// The string to be examined
/// The message to display in case of failure
static public void EndsWith( string expected, string actual, string message )
{
EndsWith( expected, actual, message, null );
}
///
/// Asserts that a string ends with another string.
///
/// The expected string
/// The string to be examined
static public void EndsWith( string expected, string actual )
{
EndsWith( expected, actual, string.Empty, null );
}
#endregion
#region AreEqualIgnoringCase
///
/// Asserts that two strings are equal, without regard to case.
///
/// The expected string
/// The actual string
/// The message to display in case of failure
/// Arguments used in formatting the message
static public void AreEqualIgnoringCase( string expected, string actual, string message, params object[] args )
{
Assert.That(actual, new EqualConstraint(expected).IgnoreCase, message, args);
}
///
/// Asserts that two strings are equal, without regard to case.
///
/// The expected string
/// The actual string
/// The message to display in case of failure
static public void AreEqualIgnoringCase( string expected, string actual, string message )
{
AreEqualIgnoringCase( expected, actual, message, null );
}
///
/// Asserts that two strings are equal, without regard to case.
///
/// The expected string
/// The actual string
static public void AreEqualIgnoringCase( string expected, string actual )
{
AreEqualIgnoringCase( expected, actual, string.Empty, null );
}
#endregion
#region IsMatch
///
/// Asserts that a string matches an expected regular expression pattern.
///
/// The expected expression
/// The actual string
/// The message to display in case of failure
/// Arguments used in formatting the message
static public void IsMatch( string expected, string actual, string message, params object[] args )
{
Assert.That(actual, new RegexConstraint(expected), message, args);
}
///
/// Asserts that a string matches an expected regular expression pattern.
///
/// The expected expression
/// The actual string
/// The message to display in case of failure
static public void IsMatch( string expected, string actual, string message )
{
IsMatch( expected, actual, message, null );
}
///
/// Asserts that a string matches an expected regular expression pattern.
///
/// The expected expression
/// The actual string
static public void IsMatch( string expected, string actual )
{
IsMatch( expected, actual, string.Empty, null );
}
#endregion
}
}