If you want to use exactly as many virtual users as you have user accounts in your test data, you could use a web test plugin like this:
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.ComponentModel;
namespace Plugins
{
[DisplayName("Lock Data Table Row to Virtual User Id")]
[Description("Makes each virtual user use the same data row as their user id. "
+ "Only works on first table of first data source. \r\n"
+ "LoadTest > Scenario > Percentage of New Users must be set to 0.")]
public class LockDataTableRowToVirtualUserIdWebTestPlugin : WebTestPlugin
{
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
int id = e.WebTest.Context.WebTestUserId;
// correct discrepancy (WebTests start at id 1, LoadTests start at id 0)
if (!e.WebTest.Context.ContainsKey("$LoadTestUserContext")) id -= 1;
int rows = e.WebTest.GetDataTableRowCount(e.WebTest.DataSources[0].Name, e.WebTest.DataSources[0].Tables[0].Name);
if (id > rows - 1) // not enough rows
throw new WebTestException("Not enough rows to provide all users with unique data; id=" + id + " rows=" + rows);
e.WebTest.MoveDataTableCursor(e.WebTest.DataSources[0].Name, e.WebTest.DataSources[0].Tables[0].Name, id);
}
}
}
Requires "Percentage of New Users" setting in the Load Test Scenario properties be set to 0, which keeps the virtual user ids constant for each virtual user. Otherwise, new virtual users will get new ids that exceed the data rows.
Could easily be enhanced to work on named DataSources/DataTables via properties.