title: Mocking a TraceListener with Moq
body: <p>Why does the Moq Verify fail with a "Moq.MockException : Invocation was not performed on the mock"?</p>
  
  <pre><code>var mock = new Mock&lt;TraceListener&gt;();
  var ts = new TraceSource("traceSourceName", SourceLevels.Verbose);
  ts.Listeners.Add(mock.Object);
  
  var message = "the message";
  
  ts.TraceEvent(TraceEventType.Verbose, 0, message);
  ts.Flush();
  mock.Verify(x =&gt; x.WriteLine(message));
  </code></pre>