title: How to write a moq test to setup a method to return a count value
body: <p>In my controller action, whenever a new product is added I check in the database that this product no is not present already. The code for this check looks like</p>
  
  <pre><code> public ActionResult Index(ProductModel model)
      {
        var productCount = _productsService.GetAll(true).Count(x =&gt; x.ProductNumber == model.ProductNumber);
  
        if (productCount &gt; 0)
            ModelState.AddModelError("ProductNumber", Product already present in the system!");
  
         // more processing
       }
  </code></pre>
  
  <p>I m new to MOQ testing and trying to write a unit test to setup the GetAll method which will return 0. I have written something like this but it does not seem to work</p>
  
  <pre><code> var _productsService = new Mock&lt;IProductsService&gt;();
  _productsService.Setup(m =&gt; m.GetAll(true).Count()).Returns(0);
  </code></pre>
  
  <p>Any ideas? thanks</p>