title: Visual Studio 2012 Fakes - How do I verify a method was called?
body: <p>Coming from using Moq, I'm used to being able to Setup mocks as Verifiable.  As you know, this is handy when you want to ensure your code under test actually called a method on a dependency.</p>
  
  <p>e.g. in Moq:</p>
  
  <pre><code>// Set up the Moq mock to be verified
  mockDependency.Setup(x =&gt; x.SomethingImportantToKnow()).Verifiable("Darn, this did not get called.");
  target = new ClassUnderTest(mockDependency);
  // Act on the object under test, using the mock dependency
  target.DoThingsThatShouldUseTheDependency();
  // Verify the mock was called.
  mockDependency.Verify();
  </code></pre>
  
  <p>I've been using VS2012's "Fakes Framework" (for lack of knowing a better name for it), which is quite slick and I'm starting to prefer it to Moq, as it seems a bit more expressive and makes Shims easy.  However, I can't figure out how to reproduce behavior similar to Moq's Verifiable/Verify implementation.  I found the InstanceObserver property on the Stubs, which sounds like it might be what I want, but there's no documentation as of 9/4/12, and I'm not clear how to use it, if it's even the right thing.</p>
  
  <p>Can anyone point me in the right direction on doing something like Moq Verifiable/Verify with VS2012's Fakes?</p>
  
  <p>-- 9/5/12 Edit --<br>
  I realized a solution to the problem, but I'd still like to know if there's a built-in way to do it with VS2012 Fakes.  I'll leave this open a little while for someone to claim if they can.  Here's the basic idea I have (apologies if it doesn't compile).</p>
  
  <pre><code>[TestClass]
  public class ClassUnderTestTests
  {
      private class Arrangements
      {
          public ClassUnderTest Target;
          public bool SomethingImportantToKnowWasCalled = false;  // Create a flag!
          public Arrangements()
          {
              var mockDependency = new Fakes.StubIDependency  // Fakes sweetness.
              {
                  SomethingImportantToKnow = () =&gt; { SomethingImportantToKnowWasCalled = true; }  // Set the flag!
              }
              Target = new ClassUnderTest(mockDependency);
          }
      }
  
      [TestMethod]
      public void DoThingThatShouldUseTheDependency_Condition_Result()
      {
          // arrange
          var arrangements = new Arrangements();
          // act
          arrangements.Target.DoThingThatShouldUseTheDependency();
          // assert
          Assert.IsTrue(arrangements.SomethingImportantToKnowWasCalled);  // Voila!
      }
  }
  </code></pre>
  
  <p>-- 9/5/12 End edit --</p>