title: Dependency Injection - adding Customer object causing test to fail
body: <p>I have used Constructor injection on a repository for class, I have noticed the following works:</p>
  
  <pre><code>    public CreateInvoiceResult CreateInvoice(string Code, int qty, string Name)
      {
  
          if (string.IsNullOrEmpty(Code) || qty &lt;= 0 || repository.GetByName(Name).ID &lt;= 0)
          {
              return new CreateInvoiceResult(false);
          }
  </code></pre>
  
  <p>However changing to the following code (adding in 'Customer cust') causes test to fail?</p>
  
  <pre><code> public CreateInvoiceResult CreateInvoice(string stockCode, int quantity, string customerName)
   {
       Customer cust = repository.GetByName(Name);
  
       if (string.IsNullOrEmpty(Code) || qty &lt;= 0 || cust.ID &lt;= 0)
       {
           return new CreateInvoiceResult(false);
       }
  </code></pre>
  
  <p>Example Test:</p>
  
  <p>Please can you explain why this is happening and how I can correct?</p>
  
  <p>EDIT: Have updated test using Moq, to use correct repository:</p>
  
  <pre><code>[TestClass]
  public class MockCustomerRepositoryDBTests
  {
      public MockCustomerRepositoryDBTests()
      {
          IList&lt;Customer&gt; customers = new List&lt;Customer&gt;
          {
              new Customer { ID = 1, Name = "Jim Smith",
                  Address = "14 Main Road"},
              new Customer { ID = 2, Name = "Alex Smith",
                  Address = "78 Avanue"},
              new Customer { ID = 3, Name = "Paul Brown",
                  Address = "1 Main Road"}
          };
  
          // Mock the CustomerRepositoryDB Repository using Moq
          Mock&lt;ICustomerRepository&gt; mockCustomerRepository = new Mock&lt;ICustomerRepository&gt;();
  
          // Return a customer by Name
          mockCustomerRepository.Setup(mr =&gt; mr.GetByName(
              It.IsAny&lt;string&gt;())).Returns((string s) =&gt; customers.Where(
              x =&gt; x.Name == s).Single());
  
          // Complete the setup of the Mock Customer Repository
          this.MockCustomerRepository = mockCustomerRepository.Object;
      }
  
      public readonly ICustomerRepository MockCustomerRepository;
  
      [TestMethod]
      public void stockCodeIsNullOrEmpty()
      {
          //Arrange
          var x = new InvoiceController(MockCustomerRepository);
  
          //Act
          bool result = x.CreateInvoice("", 1, "test").Success;
  
          //Assert
          Assert.AreEqual(result, false);
      }
  </code></pre>
  
  <p>Getting 'System.InvalidOperationException: Sequence contains no elements'</p>