|
13 Mar 2015 by Super Human
Case Insensitive String.Contains Extension MethodContract
GlobalExtensionMethods
public static bool Contains(this string source, string toSeek, StringComparison comparisonType);
Test Cases
WhenStringContainsSearchedWord_ReturnsTrue
Created By Super Human
public void WhenStringContainsSearchedWord_ReturnsTrue()
{
var str = "This string contains what you seek.";
Assert.IsTrue(str.Contains("SEEK", StringComparison.OrdinalIgnoreCase));
Assert.IsTrue(str.Contains("seek", StringComparison.OrdinalIgnoreCase));
}
WhenStringDoesNotContainsSearchedWord_ReturnsFalse
Created By Super Human
public void WhenStringDoesNotContainsSearchedWord_ReturnsFalse()
{
var str = "This string contains what you seek.";
Assert.IsFalse(str.Contains("other", StringComparison.OrdinalIgnoreCase));
}
WhenStringInTurkishLocale_ContainsSearchedWord_ReturnsTrue
Created By Super Human
using System.Globalization;
public void WhenStringInTurkishLocale_ContainsSearchedWord_ReturnsTrue()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
var str = "This string contains an integer.";
Assert.IsTrue(str.Contains("INTEGER", StringComparison.OrdinalIgnoreCase));
}
You must be logged in to add test cases
|
|
13 Mar 2015 by Super Human
public static class GlobalExtensionMethods
{
public static bool Contains(this string source, string toSeek, StringComparison comparisonType)
{
return source.IndexOf(toSeek, comparisonType) >= 0;
}
}
|
|||
|
|
||||
|
Test Case Run Summary
WhenStringContainsSearchedWord_ReturnsTrue
WhenStringDoesNotContainsSearchedWord_ReturnsFalse
WhenStringInTurkishLocale_ContainsSearchedWord_ReturnsTrue
|
||||
| download solution | ||||
| Try this Solution | ||||
|
Comments
|