title: Mocking using Moq in c#
body: <p>I have the following code:</p>
  
  <pre><code>public interface IProductDataAccess
  {
      bool CreateProduct(Product newProduct);
  }
  </code></pre>
  
  <p>Class <code>ProductDataAccess</code> implements that interface.</p>
  
  <pre><code>public class ProductBusiness
  {
      public bool CreateProduct(Product newProduct)
      {
          IProductDataAccess pda = new ProductDataAccess();
          bool result = pda.CreateProduct(newProduct);
          return result;
      }
  }
  </code></pre>
  
  <p>In this case, how to create unit test for <code>CreateProduct</code> method by mocking the <code>IProductDataAccess</code> interface? I thought of having an public instance of <code>IProductDataAccess</code> within <code>ProductBusiness</code> and initialize it using <code>Mock&lt;IProductDataAccess&gt;</code> object but it is not a good practice to expose the data access to the UI layer. Can any one help me?</p>