EndsWith Constraint
EndsWithConstraint tests that a string ends with the expected substring.
Usage
Does.EndWith(string expected)
Does.Not.EndWith(string expected)
Modifiers
.IgnoreCase
.Using(StringComparison comparisonType)
.Using(CultureInfo culture)
Examples
[Test]
public void EndsWithConstraint_Examples()
{
string phrase = "Make your tests fail before passing!";
Assert.That(phrase, Does.EndWith("!"));
Assert.That(phrase, Does.EndWith("passing!"));
Assert.That(phrase, Does.EndWith("PASSING!").IgnoreCase);
Assert.That(phrase, Does.Not.EndWith("failing"));
}
Specifying a StringComparison
Assert.That("Hello World!", Does.EndWith("WORLD!").Using(StringComparison.OrdinalIgnoreCase));
Assert.That("Hello World!", Does.EndWith("World!").Using(StringComparison.Ordinal));
Specifying a CultureInfo
The Using(CultureInfo) modifier allows for culture-specific string comparisons.
It can be combined with .IgnoreCase for case-insensitive culture-aware comparisons:
// Using Turkish culture where 'i' and 'I' have special casing rules
Assert.That("text TITLE", Does.EndWith("title").IgnoreCase.Using(new CultureInfo("tr-TR")));
// Culture-specific comparison without case-insensitivity
Assert.That("Main Straße", Does.EndWith("Straße").Using(new CultureInfo("de-DE")));
Notes
- Only one
Usingmodifier may be specified. Attempting to use multipleUsingmodifiers will throw anInvalidOperationException.