title: Moq Verify method not working with ToList
body: <p>I am fairly new to unit testing in C# and learning to use Moq. Below is the example of my problem with Moq <code>Verify()</code> method.</p>
  <pre><code>[Theory]
  [AutoData]
  public async Task WhenSomething_ThenSomething(IEnumerable&lt;string&gt; stringCollection)
  {
          //Arange
          //Mock of the method used in Handle() that returns stringCollection.
          someMock.Setup(x =&gt; x.MethodReturningStringCollectionForHandler()).ReturnsAsync(stringCollection);
          var someList = stringCollection.ToList();
  
          //Act
          await handler.Handle(new SomeRequest(someId));
  
          //Assert
          //I want to verify if someMethod() inside handler was called once but with appropriate stringCollection
          problematicMock.Verify(x =&gt; x.someMethod(someList), Times.Once());
  }
  </code></pre>
  <p>The above scenerio works, but when I remove <code>someList</code> variable and use <code>ToList()</code> directly in <code>Verify()</code>, like this:</p>
  <pre><code>problematicMock.Verify(x =&gt; x.someMethod(stringCollection.ToList()), Times.Once());
  </code></pre>
  <p>then I get the following exception:</p>
  <pre><code>Message: 
      Moq.MockException : 
      Expected invocation on the mock once, but was 0 times: x =&gt; x.someMethod([&quot;83436e1f-bd2f-44d3-9f8c-ba6afbf73e95&quot;, &quot;16593c11-0959-4ebe-aafd-d5fbe0cfbd17&quot;, &quot;633e6557-bed0-4ff0-b550-8790fab9e629&quot;])
  </code></pre>
  <p>As one could imagine, this is quite problematic, what if <code>someMethod()</code> would accept many collection-type parameters? For this particular example I would have to create many variables to pass to <code>Verify()</code> method. Why does it work this way?</p>