Class AssertThatString
Provides static methods for making assertions on strings with descriptive failure messages.
Inherited Members
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class AssertThatString
Methods
| Edit this page View SourceAreEqualIgnoreCase(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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |