Moq Verify Fails - Unit Test Fails When Run in Batch, Succeeds When Run Singularly
<p>I'm finding this Unit Test behaviour very strange.  If I run this unit test on its own it is successful, every time.</p>

<p>If I run it along with the other tests in the same class, it fails.  I could understand it if there was anything shared with other tests at runtime but as far as I can see all the objects in use in this test are created specifically for this test.</p>

<pre><code>public void AttemptLoginFailsEmailValidates()
{
    const string emailAddress = "test@test.com";
    const string password = "Password";

    ClearAll();

    var moqSettingsService = new Mock&lt;ISettingsService&gt;();
    var moqLoginService = new Mock&lt;ILoginService&gt;();
    var moqMessenger = new Mock&lt;IMvxMessenger&gt;();
    var moqDialogService = new Mock&lt;IDialogService&gt;();

    var validationService = new ValidatorService();
    moqLoginService.Setup(li =&gt; li.Login(It.Is&lt;string&gt;(s =&gt; s == emailAddress), It.Is&lt;string&gt;(s =&gt; s == password), false, It.Is&lt;string&gt;(s =&gt; s == "User"))).Returns(Task.FromResult(false));

    var vm = new LoginViewModel(moqLoginService.Object, moqSettingsService.Object, validationService, moqDialogService.Object, moqMessenger.Object) { EmailLogin = emailAddress, Password = password };

    Assert.AreEqual(emailAddress, vm.EmailLogin);
    Assert.AreEqual(password, vm.Password);

    vm.LoginCommand.Execute(new object());

    moqLoginService.Verify(p =&gt; p.Login(It.Is&lt;string&gt;(s =&gt; s == emailAddress), It.Is&lt;string&gt;(s =&gt; s == password), false, It.Is&lt;string&gt;(s =&gt; s == "User")), Times.Once);
}
</code></pre>

<p>The Moq exception is:</p>

<pre><code>Moq.MockException : 
Expected invocation on the mock once, but was 0 times: p =&gt; p.Login(It.Is&lt;String&gt;(s =&gt; s == "test@test.com"), It.Is&lt;String&gt;(s =&gt; s == "Password"), False, It.Is&lt;String&gt;(s =&gt; s == "User"))

Configured setups:
li =&gt; li.Login(It.Is&lt;String&gt;(s =&gt; s == "test@test.com"), It.Is&lt;String&gt;(s =&gt; s == "Password"), False, It.Is&lt;String&gt;(s =&gt; s == "User")), Times.Never
No invocations performed.
</code></pre>