Class StringAssertExtensions
Provides fluent assertion extension methods for strings.
Inherited Members
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class StringAssertExtensions
Methods
| Edit this page View SourceShouldBeNullOrEmpty(string?, string)
Verifies that the string is null or empty.
Declaration
public static string? ShouldBeNullOrEmpty(this string? actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to check. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string is not null or empty. |
ShouldBeNullOrWhiteSpace(string?, string)
Verifies that the string is null or whitespace.
Declaration
public static string? ShouldBeNullOrWhiteSpace(this string? actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to check. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string is not null or whitespace. |
ShouldContain(string, string, string)
Verifies that the string contains the expected substring.
Declaration
public static string ShouldContain(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not contain the expected substring. |
ShouldContain(string, string, StringComparison, string)
Verifies that the string contains the expected substring using the specified comparison.
Declaration
public static string ShouldContain(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not contain the expected substring. |
ShouldEndWith(string, string, string)
Verifies that the string ends with the expected substring.
Declaration
public static string ShouldEndWith(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not end with the expected substring. |
ShouldEndWith(string, string, StringComparison, string)
Verifies that the string ends with the expected substring using the specified comparison.
Declaration
public static string ShouldEndWith(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not end with the expected substring. |
ShouldEqualIgnoreCase(string, string, string)
Verifies that two strings are equal ignoring case.
Declaration
public static string ShouldEqualIgnoreCase(this string actual, string expected, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The actual string. |
| string | expected | The expected string. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| string | The actual string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the strings are not equal ignoring case. |
ShouldHaveLength(string, int, string)
Verifies that the string has the expected length.
Declaration
public static string ShouldHaveLength(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not have the expected length. |
ShouldMatch(string, string, string)
Verifies that the string matches the specified regular expression pattern.
Declaration
public static string ShouldMatch(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not match the pattern. |
ShouldMatch(string, string, RegexOptions, string)
Verifies that the string matches the specified regular expression pattern with options.
Declaration
public static string ShouldMatch(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not match the pattern. |
ShouldNotBeNullOrEmpty(string?, string)
Verifies that the string is not null or empty.
Declaration
public static string ShouldNotBeNullOrEmpty(this string? actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to check. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string is null or empty. |
ShouldNotBeNullOrWhiteSpace(string?, string)
Verifies that the string is not null or whitespace.
Declaration
public static string ShouldNotBeNullOrWhiteSpace(this string? actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The string to check. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string is null or whitespace. |
ShouldNotContain(string, string, string)
Verifies that the string does not contain the expected substring.
Declaration
public static string ShouldNotContain(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string contains the substring. |
ShouldNotContain(string, string, StringComparison, string)
Verifies that the string does not contain the expected substring using the specified comparison.
Declaration
public static string ShouldNotContain(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string contains the substring. |
ShouldNotEqualIgnoreCase(string, string, string)
Verifies that two strings are not equal ignoring case.
Declaration
public static string ShouldNotEqualIgnoreCase(this string actual, string notExpected, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| string | actual | The actual string. |
| string | notExpected | The string that should not match the actual string. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| string | The actual string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the strings are equal ignoring case. |
ShouldNotMatch(string, string, string)
Verifies that the string does not match the specified regular expression pattern.
Declaration
public static string ShouldNotMatch(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string matches the pattern. |
ShouldNotMatch(string, string, RegexOptions, string)
Verifies that the string does not match the specified regular expression pattern with options.
Declaration
public static string ShouldNotMatch(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string matches the pattern. |
ShouldStartWith(string, string, string)
Verifies that the string starts with the expected substring.
Declaration
public static string ShouldStartWith(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not start with the expected substring. |
ShouldStartWith(string, string, StringComparison, string)
Verifies that the string starts with the expected substring using the specified comparison.
Declaration
public static string ShouldStartWith(this 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. |
Returns
| Type | Description |
|---|---|
| string | The string for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the string does not start with the expected substring. |