Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://gallio.org" rel="nofollow noreferrer"><strong>Gallio/MbUnit</strong></a> has a <a href="http://gallio.org/wiki/doku.php?id=mbunit:contract_verifiers" rel="nofollow noreferrer">contract verifier</a> which does exactly what you are looking for. A typical usage of <a href="http://gallio.org/api/html/T_MbUnit_Framework_ContractVerifiers_AccessorContract_2.htm" rel="nofollow noreferrer"><strong>AccessContract</strong></a> is the following:</p> <pre><code>public class Foo // Dummy reference type. { private readonly int value; public int Value { get { return value; } } public Foo (int value) { this.value = value; } } public class Bar { private Foo foo; public Bar(string unusedParameter) { } public Foo Foo // A complex property to be tested! { get { return foo; } set { if (value == null) throw new ArgumentNullException("value"); if (value.Value &lt; 0) throw new ArgumentOutOfRangeException(); if (value.Value == 666) throw new ArgumentException("Inferno value strictly forbidden."); foo = value; } } } </code></pre> <p>And the test fixture which uses AccessorContract to run various tests on the property.</p> <pre><code>[TestFixture] public class BarTest { [VerifyContract] public readonly IContract AccessorTests = new AccessorContract&lt;Bar, Foo&gt; { Getter = target =&gt; target.Foo, Setter = (target, value) =&gt; target.Foo = value, ValidValues = { new Foo(123), new Foo(456), new Foo(789) }, AcceptNullValue = false, DefaultInstance = () =&gt; new Bar("Hello"), InvalidValues = { { typeof(ArgumentOutOfRangeException), new Foo(-123), new Foo(-456) }, { typeof(ArgumentException), new Foo(666) } } }; } </code></pre> <p>The contract verifier generates the following unit tests:</p> <p><img src="https://i.stack.imgur.com/uOVH0.png" alt="enter image description here"></p> <p>Have a look at the <a href="http://code.google.com/p/mb-unit/source/browse/trunk/v3/src/MbUnit/MbUnit.Tests/Framework/ContractVerifiers/AccessorContractTest.cs" rel="nofollow noreferrer">MbUnit test project</a> for more usage examples.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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