title: How to mock IDataReader to test method which converts SqlDataReader to System.DataView
body: <p>I'm new to Moq and I'm struggling to write Unit Test to test a method which converts <code>SqlDataAdapter</code> to <code>System.DataView</code>. This is my method:</p>
  
  <pre><code>private DataView ResolveDataReader(IDataReader dataReader)
  {
      DataTable table = new DataTable();
  
      for (int count = 0; count &lt; dataReader.FieldCount; count++)
      {
          DataColumn col = new DataColumn(dataReader.GetName(count), 
                                          dataReader.GetFieldType(count));
          table.Columns.Add(col);
      }
  
      while (dataReader.Read())
      {
          DataRow dr = table.NewRow();
          for (int i = 0; i &lt; dataReader.FieldCount; i++)
          {
              dr[i] = dataReader.GetValue(dataReader.GetOrdinal(dataReader.GetName(i)));
          }
          table.Rows.Add(dr);
      }
  
      return table.DefaultView;
  }
  </code></pre>
  
  <p>I'm trying to create to create something like:</p>
  
  <pre><code>var dataReaderMock = new Mock&lt;IDataReader&gt;();
  var records = new Mock&lt;IDataRecord&gt;();
  dataReaderMock.Setup(x =&gt; x.FieldCount).Returns(2);
  dataReaderMock.Setup(x =&gt; x.Read()).Returns(() =&gt; records);
  </code></pre>
  
  <p>I would like to pass some data and verify that it is converted.</p>
  
  <p>Thanks.</p>