Show / Hide Table of Contents

Class AssertThatString

Provides static methods for making assertions on strings with descriptive failure messages.

Inheritance
object
AssertThatString
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class AssertThatString

Methods

| Edit this page View Source

AreEqualIgnoreCase(string, string, string)

Verifies that two strings are equal ignoring case.

Declaration
public static void AreEqualIgnoreCase(string expected, string actual, string message)
Parameters
Type Name Description
string expected

The expected string.

string actual

The actual string.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the strings are not equal ignoring case.

| Edit this page View Source

AreNotEqualIgnoreCase(string, string, string)

Verifies that two strings are not equal ignoring case.

Declaration
public static void AreNotEqualIgnoreCase(string expected, string actual, string message)
Parameters
Type Name Description
string expected

The string that should not match the actual string.

string actual

The actual string.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the strings are equal ignoring case.

| Edit this page View Source

Contains(string, string, string)

Verifies that the string contains the expected substring.

Declaration
public static void Contains(string actual, string expected, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The expected substring.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not contain the expected substring.

| Edit this page View Source

Contains(string, string, StringComparison, string)

Verifies that the string contains the expected substring using the specified comparison.

Declaration
public static void Contains(string actual, string expected, StringComparison comparisonType, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The expected substring.

StringComparison comparisonType

The type of comparison to perform.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not contain the expected substring.

| Edit this page View Source

DoesNotContain(string, string, string)

Verifies that the string does not contain the expected substring.

Declaration
public static void DoesNotContain(string actual, string expected, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The substring that should not be present.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string contains the substring.

| Edit this page View Source

DoesNotContain(string, string, StringComparison, string)

Verifies that the string does not contain the expected substring using the specified comparison.

Declaration
public static void DoesNotContain(string actual, string expected, StringComparison comparisonType, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The substring that should not be present.

StringComparison comparisonType

The type of comparison to perform.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string contains the substring.

| Edit this page View Source

DoesNotMatch(string, string, string)

Verifies that the string does not match the specified regular expression pattern.

Declaration
public static void DoesNotMatch(string actual, string pattern, string message)
Parameters
Type Name Description
string actual

The actual string.

string pattern

The regular expression pattern.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string matches the pattern.

| Edit this page View Source

DoesNotMatch(string, string, RegexOptions, string)

Verifies that the string does not match the specified regular expression pattern with options.

Declaration
public static void DoesNotMatch(string actual, string pattern, RegexOptions options, string message)
Parameters
Type Name Description
string actual

The actual string.

string pattern

The regular expression pattern.

RegexOptions options

The regular expression options.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string matches the pattern.

| Edit this page View Source

EndsWith(string, string, string)

Verifies that the string ends with the expected substring.

Declaration
public static void EndsWith(string actual, string expected, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The expected substring.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not end with the expected substring.

| Edit this page View Source

EndsWith(string, string, StringComparison, string)

Verifies that the string ends with the expected substring using the specified comparison.

Declaration
public static void EndsWith(string actual, string expected, StringComparison comparisonType, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The expected substring.

StringComparison comparisonType

The type of comparison to perform.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not end with the expected substring.

| Edit this page View Source

HasLength(string, int, string)

Verifies that the string has the expected length.

Declaration
public static void HasLength(string actual, int expectedLength, string message)
Parameters
Type Name Description
string actual

The actual string.

int expectedLength

The expected length.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not have the expected length.

| Edit this page View Source

IsNotNullOrEmpty(string?, string)

Verifies that the string is not null or empty.

Declaration
public static void IsNotNullOrEmpty(string? value, string message)
Parameters
Type Name Description
string value

The string to check.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string is null or empty.

| Edit this page View Source

IsNotNullOrWhiteSpace(string?, string)

Verifies that the string is not null or whitespace.

Declaration
public static void IsNotNullOrWhiteSpace(string? value, string message)
Parameters
Type Name Description
string value

The string to check.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string is null or whitespace.

| Edit this page View Source

IsNullOrEmpty(string?, string)

Verifies that the string is null or empty.

Declaration
public static void IsNullOrEmpty(string? value, string message)
Parameters
Type Name Description
string value

The string to check.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string is not null or empty.

| Edit this page View Source

IsNullOrWhiteSpace(string?, string)

Verifies that the string is null or whitespace.

Declaration
public static void IsNullOrWhiteSpace(string? value, string message)
Parameters
Type Name Description
string value

The string to check.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string is not null or whitespace.

| Edit this page View Source

Matches(string, string, string)

Verifies that the string matches the specified regular expression pattern.

Declaration
public static void Matches(string actual, string pattern, string message)
Parameters
Type Name Description
string actual

The actual string.

string pattern

The regular expression pattern.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not match the pattern.

| Edit this page View Source

Matches(string, string, RegexOptions, string)

Verifies that the string matches the specified regular expression pattern with options.

Declaration
public static void Matches(string actual, string pattern, RegexOptions options, string message)
Parameters
Type Name Description
string actual

The actual string.

string pattern

The regular expression pattern.

RegexOptions options

The regular expression options.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not match the pattern.

| Edit this page View Source

StartsWith(string, string, string)

Verifies that the string starts with the expected substring.

Declaration
public static void StartsWith(string actual, string expected, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The expected substring.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not start with the expected substring.

| Edit this page View Source

StartsWith(string, string, StringComparison, string)

Verifies that the string starts with the expected substring using the specified comparison.

Declaration
public static void StartsWith(string actual, string expected, StringComparison comparisonType, string message)
Parameters
Type Name Description
string actual

The actual string.

string expected

The expected substring.

StringComparison comparisonType

The type of comparison to perform.

string message

The message to display if the assertion fails.

Exceptions
Type Condition
AssertionException

Thrown when the string does not start with the expected substring.

  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com