title: How to verify an event has been unsubscribed from on a mock
body: <p>Moq version: 3.1.416.3</p>
  <p>We found a bug caused by an event not being unsubscribed. I am trying to write a unit test to verify that the event is unsubscribed from. Is it possible to verify this using <code>Mock&lt;T&gt;.Verify(expression)</code>?</p>
  <p>My initial thought was:</p>
  <pre><code>mockSource.Verify(s =&gt; s.DataChanged -= It.IsAny&lt;DataChangedHandler&gt;());
  </code></pre>
  <p>But apparently</p>
  <blockquote>
  <p>An expression tree may not contain an assignment operator</p>
  </blockquote>
  <p>Then I tried</p>
  <pre><code>mockSource.VerifySet(s =&gt; s.DataChanged -= It.IsAny&lt;DataChangedHandler&gt;());
  </code></pre>
  <p>But that gives me</p>
  <blockquote>
  <p>System.ArgumentException: Expression is not a property setter invocation.</p>
  </blockquote>
  <p>How can I verify that the unsubscribe has taken place?</p>
  <h3>How the event is used</h3>
  <pre><code>public class Foo
  {
      private ISource _source;
  
      public Foo(ISource source)
      {
          _source = source;
      }
  
      public void DoCalculation()
      {
          _source.DataChanged += ProcessData;
  
          var done = false;
  
          while(!done)
          {
              if(/*something is wrong*/)
              {
                  Abort();
                  return;
              }
              //all the things that happen
              if(/*condition is met*/)
              {
                  done = true;
              }
          }
  
          _source.DataChanged -= ProcessData;
      }
  
      public void Abort()
      {
          _source.DataChanged -= ProcessData; //this line was added to fix the bug
           //other cleanup
      }
  
      private void ProcessData(ISource)
      {
          //process the data
      }
  }
  </code></pre>
  <p>Ignore the convoluted nature of the code, we're dealing with signals from external hardware. This actually makes sense for the algorithm.</p>