07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

180<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

list that displays the cache manager, you could enter the name Cache in the first row,<br />

the value DefaultCacheManager in the second row, and the value SqlCacheManager<br />

in the third row, as shown here:<br />

Cache<br />

DefaultCacheManager<br />

SqlCacheManager<br />

After you create the data source, you can bind it to the correct form post parameter.<br />

<br />

To data bind a form post parameter<br />

1. In Visual Studio, click the Web test. The Web test opens in the Web <strong>Test</strong> Editor.<br />

2. In the Web <strong>Test</strong> Editor, right-click the top node of your Web test, and then click<br />

Add Data Source.<br />

3. In the OLE DB Provider drop-down list, select your data provider.<br />

4. In the Web test request tree, expand the Form Post Parameters node. Click the<br />

Web control that will be bound to the database or .csv file.<br />

5. In the Properties window, click the Value property, and then click the down arrow<br />

that appears.<br />

6. Click DataSource1. Expand the node that is named after the database table or .csv<br />

file. Click the name of the column that contains the values for the Web control. The<br />

Web control is now data bound. You should see this if you look at the Web control<br />

in the Web test request tree.<br />

After the Web control is data bound, click the Generate Code button on the toolbar.<br />

This generates a new test script that includes the data binding. The following code is<br />

an example of a test script that uses data binding.<br />

<strong>Test</strong> code with the data binding information. Note that the post contains the call<br />

to request2Body.FormPostParameters.Add("TextBox1", this.Context["DataSource1.<br />

cache#csv.cacheitem"].ToString());<br />

[DataSource("DataSource1", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\<br />

pag\\entlibcode;Extended Propertie" +<br />

"s=text", Microsoft.VisualStudio.<strong>Test</strong>Tools.Web<strong>Test</strong>ing.DataBindingAccess-<br />

Method.Sequential, "cache#csv")]<br />

[DataBinding("DataSource1", "cache#csv", "cacheitem", "DataSource1.cache#csv.<br />

cacheitem")]<br />

public class Web<strong>Test</strong>2Coded : Web<strong>Test</strong><br />

{<br />

public Web<strong>Test</strong>2Coded()<br />

{<br />

this.PreAuthenticate = true;<br />

}<br />

public override IEnumerator GetRequestEnumerator()<br />

{<br />

Web<strong>Test</strong>Request request1 = new Web<strong>Test</strong>Request("http://localhost/<br />

entlibtests/caching.aspx");

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!