Skip to content

Commit

Permalink
Adding list contains extension + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Kotzen authored and Ryan Kotzen committed Oct 3, 2014
1 parent 9140682 commit 52c7569
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Entelect/Strings/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;

// ReSharper disable once CheckNamespace - All extensions are within the same name space otherwise they don't show up in intellisense


Expand All @@ -20,5 +23,17 @@ public static bool Contains(this string input, string value, StringComparison st
{
return input.IndexOf(value, stringComparison) >= 0;
}

/// <summary>
/// Determines whether the provided list of strings contains the specified string using the provided StringComparison object.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="value">The value.</param>
/// <param name="stringComparison">The string comparison object to use.</param>
/// <returns>True if the list contains the value otherwise false</returns>
public static bool Contains(this IEnumerable<string> input, string value, StringComparison stringComparison)
{
return input.Any(item => item.Equals(value, stringComparison));
}
}
}
9 changes: 8 additions & 1 deletion test/Entelect.Tests/Strings/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ namespace Entelect.Tests.Strings
public class StringExtensionsTests
{
[Test]
public void CanCompareIgnoringCase()
public void ContainsIgnoringCase()
{
var doesContain = "asd".Contains("S",StringComparison.OrdinalIgnoreCase);
Assert.True(doesContain);
}
[Test]
public void ListContainsIgnoringCase()
{
var list = new[] {"asd", "qwe", "zxc"};
var doesContain = list.Contains("ASD", StringComparison.OrdinalIgnoreCase);
Assert.True(doesContain);
}
}
}

0 comments on commit 52c7569

Please sign in to comment.