Are you binding a field in the web test to a context parameter at design time and then trying to place the values into the TestContext at runtime from the PreRequest handler
When I call this function from the WebTest's constructor, an item called testitem appears in the WebTest's context. If, instead, I add MyFunc as an event handler for the WebTest's PreWebTest event, it still gets called before the test runs, but testitem does not appear in the WebTest's context.
This behavior is due to the fact that we only load data sources at the start of a test run (the whole run, not per test iteration). You can only call those methods from within InitializeDataBinding since that method only gets called once per web test at the start of a run. Normally, you'd just use the DataBinding and DataSource attributes.
That said, you can certainly load data into the context yourself at any point during a test run. What you would do is use standard ADO.NET calls to read from a database (or anywhere) and add that data to the context with this.Context.Add().
Adding data bindings from a webtestplugin
wserra
Can you provide some details please
Are you binding a field in the web test to a context parameter at design time and then trying to place the values into the TestContext at runtime from the PreRequest handler
Thanks,
Rick
BrianAnger
Here is another way to reproduce the problem.
In a coded WebTest I have the following function:
public void MyFunc( object sender, PreWebTestEventArgs e ) { this.AddDataSource( "DataSource1", CONNECTION_STRING, DataBindingAccessMethod.Sequential, "WebServers" ); this.AddDataSourceBinding( "DataSource1", "WebServers", "ServerName", "testitem" ); }When I call this function from the WebTest's constructor, an item called testitem appears in the WebTest's context. If, instead, I add MyFunc as an event handler for the WebTest's PreWebTest event, it still gets called before the test runs, but testitem does not appear in the WebTest's context.
Kryton
Daryl,
This behavior is due to the fact that we only load data sources at the start of a test run (the whole run, not per test iteration). You can only call those methods from within InitializeDataBinding since that method only gets called once per web test at the start of a run. Normally, you'd just use the DataBinding and DataSource attributes.
That said, you can certainly load data into the context yourself at any point during a test run. What you would do is use standard ADO.NET calls to read from a database (or anywhere) and add that data to the context with this.Context.Add().
Josh