Fluent Syntax for Assertion in msTest
Switching from Nunit to MsTest is quite simple, but the first thing I really miss with mstest was the lack of a fluent assertion syntax. Consider the assertion you must write if you want to check that a number is lesser than 100 or greater than 200
|
|
It is quite clear, but with fluent syntax you can write test like this
|
|
I find it really clearer than the first form. The advantage of a fluent syntax is that you can read the assertion as if were English text. I’m actually writing an helper assembly to support fluent syntax with msTest, if someone is interested in I can publish in source form. For now I’m able to support basic syntax with operator precedence and parenthesis
|
|
As you can see the first test pass because the And operator ( expressed by & because you cannot overload &&) has higher precedence over the or operator. The second test pass because you can alter precedence with parenthesis.
Alk.