title: Moq function in repository with a lambda expression as an argument
body: <p>I'm using Moq. I want to mock a repository. Specifically, I want to mock the Exists function of the repository. The problem is that the Exist function takes a lambda expression as an argument.</p>
  
  <p>This is a method in my business object that uses the repository.</p>
  
  <pre><code>    public override bool Validate(Vendor entity)
      {
          // check for duplicate entity
          if (Vendors.Exists(v =&gt; v.VendorName == entity.VendorName &amp;&amp; v.Id != entity.Id))
              throw new ApplicationException("A vendor with that name already exists");
  
          return base.Validate(entity);
      }
  </code></pre>
  
  <p>This is what I have now for my test:</p>
  
  <pre><code>    [TestMethod]
      public void Vendor_DuplicateCheck()
      {
          var fixture = new Fixture();
          var vendors = fixture.CreateMany&lt;Vendor&gt;();
  
          var repoVendor = new Mock&lt;IVendorRepository&gt;();
  
          // this is where I'm stuck
          repoWashVendor.Setup(o =&gt; o.Exists(/* what? */)).Returns(/* what */);
  
          var vendor = vendors.First();
  
          var boVendor = new VendorBO(repoVendor);
          boVendor.Add(vendor);
      }
  </code></pre>
  
  <p>How do I mock Exists()?</p>