Show / Hide Table of Contents

Class StringAssertExtensions

Provides fluent assertion extension methods for strings.

Inheritance
object
StringAssertExtensions
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 StringAssertExtensions

Methods

| Edit this page View Source

ShouldBeNullOrEmpty(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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

| Edit this page View Source

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.

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