Lambda/LINQ based Assertions

We have named this feature The Satisfier.
The satisfier is an extension method whose parameter is Func<TActual, bool> so there isn't something special to say about the syntax because it is only, and pure, .NET's language.

1.Satisfies(x => x == 1 || x == 2);
1.Satisfies(x => x > 0);
1.Satisfies(x => 2 > x);

const int y = 2;
const int z = 4;
4.Satisfies(x => x == y * y);
2.Satisfies(x => x == z / y);

"1".Satisfies(x => x == 1.ToString());

var y = 2;
new[] { 1, 2 }.Satisfies(x => x.Contains(y));
var y = new[] { 1, 2 };
var z = new[] { 2, 1 };
1.Satisfies(x => x == y[0] && x == z[1]);

new[] {1, 2}.Satisfies(x => x.SequenceEqual(new[] {1, 2}));

Last edited Nov 22, 2016 at 2:30 PM by fabiomaulo, version 2

Comments

adamralph May 8, 2011 at 1:43 AM 
I agree with ceilidhboy

ceilidhboy Oct 25, 2010 at 10:42 AM 
Your other assertions use the present tense, e.g. something.Should().Contain(...). Satisfy is inconsistent - it's an imperative and doesn't read as well to a native English speaker. Consider changing it to Satisfies:

1.Satisfies( x => x == 1 );