title: Verifying event handler code executed
body: <p>I have code very similar to this but cannot work out how I test whether an event handler occured.</p>
  
  <pre><code>public class MyClass : MyAbstractClass
  { 
    IFileSystem FileSystem;
  
    public MyClass(IFileSystem myFileSys)
    {
      FileSystem = myFileSys;
      FileSystem.EventHit += new EventHandler(FileSystem_EventHit);
    }
  
    public void FileSystem_EventHit(object sender, EventArgs e)
    {
      //Testing base.OnOutput is not possible which I wont go into
      base.OnOutput("EventHit");
    }
  }
  </code></pre>
  
  <p>Testing code is here:</p>
  
  <pre><code>    [Test]
      public void DoSomething_WhenCalled_EventFired()
      {
           var mock = new Moq.Mock&lt;IFileSystem&gt;();
  
           MyClass plugin = new MyClass (mock.Object);
  
           mock.Object.DoSomething();
  
           mock.Raise(x =&gt; x.EventHit += null, new EventArgs());
  
          //Verify/Assert that MyClass handled and did something in the event handler
  
      }
  </code></pre>