Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This seems to be a bug in the documentation. When examining the <code>Rhino.Mocks.dll</code> (3.6.0.0) in the Object Browser I see that <code>Rhino.Mocks.Arg&lt;T&gt;</code> only offers the methods <code>Is</code> and <code>List</code> but not <code>Property</code>.</p> <p>However <code>Rhino.Mocks.Constraints</code> contains the <code>Property</code> class. Using the "old" syntax you should be able to do the same:</p> <p>AAA syntax (producing compile error):</p> <pre><code>myStub.Expect(x =&gt; x.MethodToCall(Arg&lt;T&gt;.Property.Value("PropertyName", myDesiredPropertyValue))).Result(myMockResult); </code></pre> <p>Old syntax (working):</p> <pre><code>myStub.Expect(x =&gt; x.MethodToCall(null)).Constraints(Property.Value("PropertyName", myDesiredPropertyValue)).Result(myMockResult); </code></pre> <p>The documentation says <em>"You're probably used to <code>IgnoreArguments()</code>, <code>Constraints()</code> and <code>RefOut()</code>. [...] It is encouraged to use only <code>Arg&lt;T&gt;</code>, it is more consistent and easier to understand, even if sometimes a little more to write."</em></p> <p>As Jeff Bridgman noted, you can also use <code>Arg&lt;T&gt;.Matches</code>:</p> <pre><code>myStub.Expect(x =&gt; x.MethodToCall(Arg&lt;T&gt;.Matches(m =&gt; m.PropertyName == myDesiredPropertyValue))).Result(myMockResult); </code></pre> <p>It has the advantage of being 'refactory safe', meaning that you can refactor the name of the property safely without the need to search for any 'magic strings'. It also meets the suggestion in the documentation to rather use <code>Arg&lt;T&gt;</code> instead of <code>Constraints()</code>.</p>
 

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