Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The exact order of When..Do and Arg.Do isn't defined, and I wouldn't recommend counting on it as I imagine it could change between versions depending on implementation. (If you have a good reason to define it in a particular order please post your suggestion to the <a href="http://groups.google.com/group/nsubstitute" rel="nofollow">usergroup</a>.) </p> <p>If you just want to check logThing received the expected LogEntry, you can check the argument after the fact using Arg.Is():</p> <pre><code>logThing.Received().AddEntry(Arg.Is(expectedEntry)); </code></pre> <p>If you need more complex comparison logic, you can do the same thing but use a method to check the argument:</p> <pre><code>logThing.Received().AddEntry(Arg.Is&lt;LogEntry&gt;(x =&gt; CheckLogEntry(x))); </code></pre> <p><code>CheckLogEntry</code> can do whatever checks you require, and you can keep the When..Do throwing as before.</p> <p>If you need to use the When..Do approach, you can can keep your existing approach but move the capture of the argument into the <code>Do</code> call to ensure the order of calls that you expect:</p> <pre><code>logThing.When( lt =&gt; lt.AddEntry(Arg.Any&lt;LogEntry&gt;())).Do( call =&gt; { actualEntries.Add(call.Arg&lt;LogEntry&gt;()); throw new InvalidOperationException("testMessage"); }); </code></pre> <p>In terms of suggestions for other ways of testing this, I'm not entirely clear on what you are trying to do here, but if you are having trouble isolating where the wrapped output is coming from maybe you could move this responsibility to another dependency? This would let you substitute for this dependency and control exactly where this happened from the perspective of this test.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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