Class StringAssertExtensions
Defines a code assertion helper for string-based scenarios.
public static class StringAssertExtensions
- Inheritance
-
StringAssertExtensions
- Inherited Members
Methods
ShouldContain(string?, string, StringComparison)
Tests whether the specified string contains the given substring and throws an exception if it does not.
public static void ShouldContain(this string? value, string substring, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
valuestringThe string to test.
substringstringThe substring to search for.
comparisonTypeStringComparisonThe string comparison type to use. Default is Ordinal.
Exceptions
- AssertFailedException
Thrown if the
valuedoes not contain thesubstring.
ShouldEndWith(string?, string, StringComparison)
Tests whether the specified string ends with the given suffix and throws an exception if it does not.
public static void ShouldEndWith(this string? value, string suffix, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
valuestringThe string to test.
suffixstringThe suffix to search for.
comparisonTypeStringComparisonThe string comparison type to use. Default is Ordinal.
Exceptions
- AssertFailedException
Thrown if the
valuedoes not end with thesuffix.
ShouldNotContain(string?, string, StringComparison)
Tests whether the specified string does not contain the given substring and throws an exception if it does.
public static void ShouldNotContain(this string? value, string substring, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
valuestringThe string to test.
substringstringThe substring to search for.
comparisonTypeStringComparisonThe string comparison type to use. Default is Ordinal.
Exceptions
- AssertFailedException
Thrown if the
valuecontains thesubstring.
ShouldStartWith(string?, string, StringComparison)
Tests whether the specified string starts with the given prefix and throws an exception if it does not.
public static void ShouldStartWith(this string? value, string prefix, StringComparison comparisonType = StringComparison.Ordinal)
Parameters
valuestringThe string to test.
prefixstringThe prefix to search for.
comparisonTypeStringComparisonThe string comparison type to use. Default is Ordinal.
Exceptions
- AssertFailedException
Thrown if the
valuedoes not start with theprefix.