Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a simple class only a few lines long that I wrote a while ago ( from here : <a href="http://code.google.com/p/hotwire-queue/wiki/QuickAssert" rel="nofollow">http://code.google.com/p/hotwire-queue/wiki/QuickAssert</a>) that does something similar to fluent validation, uses a slightly different style that I find a bit easier to read (ymmv). Doesn't require any third party libraries, and if the validation fails, you get a simple error message with the exact code that failed.</p> <pre><code>config.Active.Should().BeTrue(); config.RootServiceName.Should().Be("test-animals"); config.MethodValidation.Should().Be(MethodValidation.afterUriValidation); var endpoints = config.Endpoints; endpoints.Should().NotBeNull().And.HaveCount(2); </code></pre> <p>to this:</p> <pre><code>config.Ensure(c =&gt; c.Active, c =&gt; c.RootServiceName == "test-animals", c =&gt; c.MethodValidation == MethodValidation.afterUriValidation, c =&gt; c.Endpoints != null &amp;&amp; c.Endpoints.Count() == 2); </code></pre> <p>Here's the class, hope it's helpful as a starting point for someone ;-D</p> <pre><code>using System; using System.Linq.Expressions; using NUnit.Framework; namespace Icodeon.Hotwire.Tests.Framework { public static class QuickAssert { public static void Ensure&lt;TSource&gt;(this TSource source, params Expression&lt;Func&lt;TSource, bool&gt;&gt;[] actions) { foreach (var expression in actions) { Ensure(source,expression); } } public static void Ensure&lt;TSource&gt;(this TSource source, Expression&lt;Func&lt;TSource, bool&gt;&gt; action) { var propertyCaller = action.Compile(); bool result = propertyCaller(source); if (result) return; Assert.Fail("Property check failed -&gt; " + action.ToString()); } } } </code></pre> <p>At the time I wrote Ensure, code contracts were not supported in Visual studio 2010, but are now, see <a href="http://msdn.microsoft.com/en-us/magazine/hh148151.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/hh148151.aspx</a> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload