title: Return a single object from list
body: <p>When setting up my repository I am trying to return a single Account object. It should return this object from a List where the username is equal to the parameter. </p>
  
  <p>However I get the exception</p>
  
  <blockquote>
    <p>Object of type 'System.String' cannot be converted to type 'IncrediStaff.DataAccess.Models.Account'.</p>
  </blockquote>
  
  <pre><code>    [TestInitialize]
      public void Setup()
      {
          var repository = new Mock&lt;IAccountRepository&gt;();
          var accounts = new List&lt;Account&gt;
          {
              new Account { AccountId = 1, Username = "John", Hash = "9f3Iv0NW9Jr3l+EmOS/zWCPe96k=", Salt = "y7qwIY0ep8aHiiSwl57dt4ueuCo=" }, // Password is, "TestPassword"
              new Account { AccountId = 2, Username = "Ryan", Hash = "63mnR/gbFIIU6vGEFqoY5H1QCCI=", Salt = "xi/lkLFqPPTR5Q9rX3m/PJ4FH0rECyalYdyRJ6pCpfE=" }, // Password is, "NewPassword"
              new Account { AccountId = 3, Username = "Sarah", Hash = null, Salt = null, FirstLogin = 1 }
          };
  
          repository.Setup(x =&gt; x.GetAccount(It.IsAny&lt;string&gt;()))
              .Returns&lt;Account&gt;(r =&gt; accounts.FirstOrDefault(x =&gt; x.Username == It.IsAny&lt;string&gt;()));
  
          _service = new AccountService(repository.Object);
      }
  
      [TestMethod]
      [TestCategory("Accounts")]
      public void UserPasswordIsCorrect()
      {
          Assert.IsTrue(_service.Login("John", "TestPassword"));
      }
  </code></pre>
  
  <p>If I return a single Account object the test passes.</p>
  
  <pre><code>        repository.Setup(x =&gt; x.GetAccount(It.IsAny&lt;string&gt;()))
              .Returns(new Account
              {
                  AccountId = 1,
                  Username = "John",
                  Hash = "9f3Iv0NW9Jr3l+EmOS/zWCPe96k=",
                  Salt = "y7qwIY0ep8aHiiSwl57dt4ueuCo="
              });
  </code></pre>
  
  <p>I'm not sure why it can't return a single object from the list. Furthermore I have another setup which uses the same list and the test passes. I'm not sure why this works and the other doesn't.</p>
  
  <pre><code>        repository.Setup(r =&gt; r.SelectIfUsernameExists(It.IsAny&lt;string&gt;()))
              .Returns&lt;string&gt;(username =&gt; accounts.Exists(r =&gt; r.Username == username));
  </code></pre>