title: Mock IDbDataAdapter Fill Method With Moq
body: <p>I have an object that reads data from an Excel file using, which takes a <code>IDbConnection</code>, <code>IDbDataAdapter</code> and an <code>IDbCommand</code>. I use the adapters fill method to populate a table with data, and this is how I am currently mocking it:</p>
  
  <pre><code>[TestCase]
  public void TestReadCellsFromSpreadsheetReadsSuccessfully()
  {
      var cells = new List&lt;ReportData&gt;
                      {
                          new ReportData { CellId = 1, ExcelCellLocation = "A1"},
                          new ReportData { CellId = 2, ExcelCellLocation = "A2"},
                          new ReportData { CellId = 3, ExcelCellLocation = "A3"},
                          new ReportData { CellId = 4, ExcelCellLocation = "A4"}
                      };
  
      _mockAdapter.Setup(a =&gt; a.Fill(It.IsAny&lt;DataSet&gt;()))
          .Callback((DataSet ds) =&gt;
                        {
                            if (ds.Tables["Table"] == null)
                            {
                                ds.Tables.Add("Table");
                                ds.Tables["Table"].Columns.Add(new DataColumn());
                            }
  
                            var row = ds.Tables["Table"].NewRow();
                            row[0] = "Test";
  
                            ds.Tables["Table"].Rows.Add(row);
                        });
  
      var excelReader = new ExcelReader(_mockConnection.Object, _mockAdapter.Object, _mockCommand.Object);
      excelReader.ReadCellsFromSpreadsheet("Deal Summary", cells);
  
      _mockCommand.VerifySet(c =&gt; c.CommandText = It.IsAny&lt;string&gt;(), Times.Exactly(cells.Count));
      _mockAdapter.VerifySet(a =&gt; a.SelectCommand = _mockCommand.Object, Times.Exactly(cells.Count));
      _mockAdapter.Verify(a =&gt; a.Fill(It.IsAny&lt;DataSet&gt;()), Times.Exactly(cells.Count));
  }
  </code></pre>
  
  <p>This implementation works, but I feel like I'm doing too much to Mock the adapter... is there a better way to do this?</p>