title: How to call MoveDataTableCursor in a web test plugin to go through a limited set of rows in a table?
body: <p>I have some difficulties understanding how the access method "Do not move cursor automatically" works for a web test data source. And the documentation out there seems to be far from exhaustive.</p>
  
  <p>First of all, let's assume there is a simple web test with only one request. It uses a data source called DS with a table called StepList, that contains 5 rows.</p>
  
  <p>The Access Method for the table is set to "Do not move cursor automatically" and the current test settings have "One run per data source row" enabled in the web test properties. The web test is not part of a load test.</p>
  
  <p>In these conditions, the test is run 5 times, for each row, so it basically moves the cursor automatically. Is this intended?</p>
  
  <p>Now, on to the practical question, which is the subject of this post.</p>
  
  <p>My StepList table above has, among others, an identity column and a StepId column. The web test in question is actually called from another web test, and it's supposed to run only for the table rows that have a StepId set in the test context.</p>
  
  <pre><code>Id  StepId
  1   1
  2   1
  3   2
  4   2
  5   2
  </code></pre>
  
  <p>In order to achieve this, I followed the guidelines from <a href="http://blogs.msdn.com/b/slumley/archive/2010/01/04/vsts-2010-feature-data-source-enhancements.aspx" rel="nofollow noreferrer">here</a> and wrote a web test plugin with the PreWebTest method looking like this:</p>
  
  <pre><code>public override void PreWebTest(object sender, PreWebTestEventArgs e)
  {
      string stepId = string.Empty;
  
      if (e.WebTest.Context.ContainsKey(ContextParameterName))
      {
          stepId = e.WebTest.Context[ContextParameterName].ToString();
      }
  
      while (e.WebTest.Context["DS.StepList.StepId"].ToString() != stepId)
      {
          e.WebTest.MoveDataTableCursor("DS", "StepList");
      }
  }
  </code></pre>
  
  <p>The code above seems to work properly on the example table only if the stepId has the value "2". If it's "1", then MoveDataTableCursor throws WebTestEndOfDataException exception: "No more rows of data in a data source table with AccessMethod Unique".</p>
  
  <p>I tried catching the exception and stopping the web test, but this doesn't work, as the test seems to never end.</p>