Permalink
Browse files

New should extension method to match one object with an expression (n…

…ot just equals or sameAs)
  • Loading branch information...
TomasEkeli authored and agross committed Mar 15, 2012
1 parent eb611c9 commit 5fe88cd8f83d9b533c6180a70c0e78c3cb881f97
Showing with 8 additions and 0 deletions.
  1. +8 −0 Source/Machine.Specifications/ExtensionMethods.cs
@@ -159,6 +159,14 @@ public static void ShouldNotBeOfType(this object actual, Type expected)
}
}
+ public static void ShouldMatch<T>(this T actual, Expression<Func<T, bool>> condition)
+ {
+ var matches = condition.Compile().Invoke(actual);
+
+ if (matches) return;
+ throw new SpecificationException(string.Format("Should match expression [{0}], but does not.", condition));
+ }
+
public static void ShouldEachConformTo<T>(this IEnumerable<T> list, Expression<Func<T, bool>> condition)
{
var source = new List<T>(list);

0 comments on commit 5fe88cd

Please sign in to comment.