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 the Data Access Application Block 59<br />

Table 4: Data Access Application Block Code Verification<br />

Code test case Implemented? Feature that is implemented<br />

Verify that the DatabaseProviderFactory<br />

class creates<br />

a new instance of a Database-derived<br />

object for each<br />

request.<br />

Yes<br />

The DatabaseFactory class calls the DatabaseProviderFactory<br />

class, which derives<br />

from the NameTypeFactory base class.<br />

For each request, this class creates a new<br />

instance of a database provider that derives<br />

from the Database class.<br />

Verify that an assembler class<br />

that implements the IDatabaseAssembler<br />

interface<br />

creates the Database-derived<br />

objects and injects the configuration<br />

object values into<br />

those domain objects.<br />

Verify that the application<br />

block uses performance<br />

counters to monitor database<br />

operations when the performance<br />

counters are enabled.<br />

Yes<br />

Yes<br />

The following code demonstrates how the<br />

SqlDatabaseAssembler class, which implements<br />

the IDatabaseAssembler interface,<br />

creates a SQL Server database provider. The<br />

process is similar for Oracle databases and<br />

generic databases.<br />

public class SqlDatabaseAssembler :<br />

IDatabaseAssembler<br />

{<br />

public Database Assemble(string name,<br />

ConnectionStringSettings connection-<br />

StringSettings, IConfigurationSource<br />

configurationSource)<br />

{<br />

return new SqlDatabase(…);<br />

}<br />

}<br />

For example, the Database.OpenConnection<br />

method increments the Connections<br />

Opened/sec performance counter when a database<br />

connection succeeds. This is shown<br />

in the following code example.<br />

protected DbConnection OpenConnection()<br />

{<br />

connection = CreateConnection();<br />

connection.Open();<br />

instrumentationProvider.FireConnectionOpenedEvent();<br />

}<br />

The FireConnectionOpenedEvent method<br />

raises the connectionOpened event. The<br />

ConnectionOpened method consumes this<br />

event and increments the performance<br />

counter. This is shown in the following code<br />

example.<br />

[InstrumentationConsumer("ConnectionO<br />

pened")]<br />

public void ConnectionOpened(…)<br />

{<br />

if (PerformanceCountersEnabled) connectionOpenedCounter.Increment();<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!