We have some new features in the upcoming release of Visual Studio Team System (Orcas). I'm going to talk about a commonly requested feature to make binding of tests to simple sources like CSV and XML easy to do (other team members will be blogging about other enhancements).
In Visual Studio 2005 binding to a simple source like a file with comma-separated values (CSV) required a deep understanding of how OLEDB over JET handled such files. Sean, one of my co-workers, blogged about this somewhat unintuitive process. XML was even trickier and required the use of a custom data source, Sean explained this too, in this article.
With Orcas the process is much easier, and with minor differences can be applied to Web Tests, Coded Web Tests or Unit Tests. Lets take a look at adding a CSV based data source to a Web Test.
Create a new web test and in the web test editor, right click and select "Add Data Source...". The new Data Source Wizard will appear:
The first page of the wizard allows you to select CSV, XML or Database. Pick CSV and browse for the file you want to use. To help select the file a preview of the file content is shown.
When you are happy with the file you have selected, click on finish. At this point you have achieved in a handful of steps what would have been very difficult before.
When a file based data source is used you will be presented with the option to copy the file into your project.
This is recommended since the test project will then be self contained, complete with a data source file which will be automatically deployed, there is no need to manually specify the file as a deployment item. There is an added benefit which is that when working in a team environment other users can just grab the project and go.
For an XML file the process is almost identical, except since XML files support multiple tables in a single file there is the added step of selecting one or more tables. One issue with XML files is knowing the correct format. Since all data sources are expected to be tabular, not just any XML file will do. In a future posting I plan to go into more detail on this, including how to create appropriate data files from code, but to get you going here is an example using the simplest format.
Here we define two tables, Users and Products. Users has the columns UserName and Role, Products has the columns ProductName and Quantity.
<?xml version="1.0" standalone="yes"?><SampleData> <Users> <UserName>Tony</UserName> <Role>Guest</Role> </Users> <Users> <UserName>Andy</UserName> <Role>Admin</Role> </Users> <Users> <UserName>Sarah</UserName> <Role>User</Role> </Users> <Users> <UserName>Ben</UserName> <Role>User</Role> </Users> <Products> <ProductName>SuperMixer 3000</ProductName> <Quantity>16</Quantity> </Products> <Products> <ProductName>Bath Magic</ProductName> <Quantity>5</Quantity> </Products> <Products> <ProductName>Rainbow Selection</ProductName> <Quantity>45</Quantity> </Products></SampleData>
In case you want to plunge in and investigate other supported formats, just know that we use the built in capability of a DataSet to load from XML, as described in detail here: XML and the DataSet.