Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you want to look at is the "Swap" functionality of Isolator.</p> <pre><code>// First set up your fake Xyz. var fakeXyz = Isolate.Fake.Instance&lt;Xyz&gt;(); Isolate.WhenCalled(() =&gt; fakeXyz.SomeMethod()).WillReturn("Value"); // Now tell Isolator that the next time someone does // "new Xyz()" you want it to be your fake. Isolate.Swap.NextInstance&lt;Xyz&gt;().With(fakeXyz); // Create your Abc and do your assertions. This should pass: var realAbc = new Abc(); Assert.AreEqual("Value", realAbc.Context.SomeMethod(); </code></pre> <p>A good reference for figuring out this sort of basic Isolator functionality is <a href="http://docs.typemock.com/Isolator/##typemock.chm/Documentation/Welcome.htm" rel="nofollow">the online documentation on the Typemock site</a>. Check out the "Quick Start" and the "Using Typemock Isolator" sections. There are plenty more examples to show you how to do similar and more advanced things.</p> <p><strong>UPDATE:</strong> I previously showed <code>Assert.AreSame(fakeXyz, realAbc.Context)</code> as the way to verify the swap took place. It appears that in some versions of Typemock the <code>Assert.AreSame</code> will fail because there is some sort of dynamic proxy mechanism at work - they aren't actually swapping in for <em>literally the same instance</em> of the fake, they're doing some trickery to get things to happen. However, the calls on the fake instance will still be called and you'll still get the expected result. I've updated the sample snippet accordingly.</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. 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