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.

<strong>Test</strong>ing for Performance and Scalability 199<br />

ID Scenario <strong>Test</strong> code<br />

8 Retrieve multiple rows<br />

as XML.<br />

protected void Button_Click(object sender, EventArgs<br />

e)<br />

{<br />

SqlDatabase dbSQL =<br />

DatabaseFactory.CreateDatabase("DataSQL<strong>Test</strong>") as<br />

SqlDatabase;<br />

// Use "FOR XML AUTO" to have SQL return XML<br />

data.<br />

string sqlCommand = "Select CategoryID from<br />

Categories where Description LIKE'Cheeses'FOR XML<br />

AUTO";<br />

System.Data.Common.DbCommand dbCommandWrapper =<br />

dbSQL.GetSqlStringCommand(sqlCommand) as DbCommand;<br />

XmlReader productsReader = null<br />

// We pass a transaction object to<br />

// ExecuteXmlReader with transaction<br />

// test cases.<br />

productsReader = dbSQL.ExecuteXmlReader(dbCommand<br />

Wrapper);<br />

dbCommandWrapper.Connection.Close();<br />

productsReader.Close();<br />

dbCommandWrapper.Dispose();<br />

}<br />

Table 13 lists the ADO.NET Framework test code.<br />

Table 13: ADO.NET Framework <strong>Test</strong> Code<br />

ID Scenario <strong>Test</strong> code<br />

5 Use the equivalent of the protected void ButtonAdo<strong>Net</strong>_Click(object sender,<br />

ExecuteNonQuery method EventArgs e)<br />

to retrieve output parameters.<br />

{<br />

SqlConnection sqlcon = new SqlConnect<br />

ion("server=****;database=Northwind;User<br />

Id=****;password=****");<br />

sqlcon.Open();<br />

SqlCommand sqlcommand = new SqlCommand();<br />

sqlcommand.Connection = sqlcon;<br />

sqlcommand.CommandType = CommandType.StoredProcedure;<br />

sqlcommand.CommandText = "TenMostExpensiveProducts";<br />

sqlcommand.ExecuteNonQuery();<br />

sqlcommand.Dispose();<br />

sqlcon.Close();<br />

}

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

Saved successfully!

Ooh no, something went wrong!