title: How to use moq object in unit testing?
body: <p>I am doing unit testing of one of my <code>Service layer class(ProductService)</code>.That layer serves DI facility to one of <code>controller class(ProductController)</code>.And for ProductController unit testing, there is already a unit test class ProductControllerTest.</p>
  
  <p>But for unit test ProductController's <strong>service layer(ProductService)</strong>,i have created one new unit <strong>test class(ProductServiceTest)</strong>.</p>
  
  <p><strong>But i don't know whether i should create a new unit test class to do Service Layer unit testing or not.</strong></p>
  
  <p><strong>Also i want to know the concept of <code>DI(Dependency Injection) and Mocking(MOQ object)</code> in unit testing.Means where to use MOQ in unit testing and when it's necessary to use ?</strong> </p>
  
  <p>I have written unit test code for one of the action method of ProductService .And i want to know whether it's correct or not ? </p>
  
  <p>Below is the piece of code of Action Method :-</p>
  
  <pre><code>public class ProductService : IProductService
  {
      private readonly IProductDal&lt;Product&gt; _productDal;
      private readonly IUserDal&lt;Users&gt; _userDal;
  
      public ProductService(IProductDal&lt;Product&gt; ProductDAL)
      {
          _productDal = ProductDAL;
      }
  
  
      public List&lt;ProductDto&gt; GetProducts(string SearchInName, string SearchInDescription)
      {
            List&lt;ProductDto&gt; productList = new List&lt;ProductDto&gt;();
            foreach (Product product in _productDal.GetProducts(SearchInName, SearchInDescription))
            {
                 productList.Add(Adapter.AdaptOmToDto(product));
            }
            return productList;
      }
  }
  </code></pre>
  
  <p>Below is the piece of code of Unit Testing(ProductServiceTest) class :-</p>
  
  <pre><code>    [TestMethod]
      public void GetProductsTest()
      {
          var productList = new List&lt;ProductDto&gt;();
  
          // Arrrange            
          var Name = "CreateSave";
          var Description = "CreateSave";
  
          // Act
          List&lt;ProductDto&gt; output = _productService.GetProducts(Name, Description);
  
          // Assert       
          Assert.IsNotNull(output);
          Assert.IsInstanceOfType(output, typeof(List&lt;ProductDto&gt;));
      }
  </code></pre>
  
  <p>Can any one suggest me the best way to unit test such kind of methods ? </p>