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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using the <strong>Test</strong> Cases 241<br />

use reflection. The following code shows the SymmetricAlgorithmInstrumentation-<br />

Binder class, which implements the IExplicitInstrumentationBinder interface.<br />

public class SymmetricAlgorithmInstrumentationBinder : IExplicitInstrumentation-<br />

Binder<br />

{<br />

public void Bind(object source, object listener)<br />

{<br />

SymmetricAlgorithmInstrumentationListener castedListener = (SymmetricAlgor<br />

ithmInstrumentationListener)listener;<br />

SymmetricAlgorithmInstrumentationProvider castedProvider = (SymmetricAlgor<br />

ithmInstrumentationProvider)source;<br />

castedProvider.cyptographicOperationFailed += castedListener.Cyptographic-<br />

OperationFailed;<br />

castedProvider.symmetricDecryptionPerformed+= castedListener.SymmetricDecryptionPerformed;<br />

castedProvider.symmetricEncryptionPerformed += castedListener.SymmetricEncryptionPerformed;<br />

}<br />

}<br />

Verification<br />

Running the two test cases again after applying the preceding code verified that the<br />

cost of creating the instrumentation objects was within acceptable limits.<br />

Determining the Cost of Creating Objects Using the FileConfigurationSource Class<br />

Another example of a general performance test is the cost of creating objects with<br />

data contained in a configuration file as opposed to data that is in memory. The<br />

following example uses the Data Access Application Block to determine the cost of<br />

creating a domain object from data in the file configuration source. To pass the test,<br />

the cost of creating domain objects with the FileConfigurationSource class could be<br />

slightly more than when using the SystemConfigurationSource class.<br />

<strong>Test</strong> Cases<br />

Two test cases determined the cost of creating domain objects with the FileConfigurationSource<br />

class. One test created a Database object with the DatabaseProviderFactory<br />

class and used the FileConfigurationSource class to retrieve the<br />

configuration data from a file. The other test did the same but used the SystemConfigurationSource<br />

class to retrieve the data from memory. Comparing the results<br />

showed whether the application block’s performance was acceptable.<br />

Problems<br />

The results from the performance tests showed that it was more expensive to create a<br />

Database object with the FileConfigurationSource class than to create one with the<br />

SystemConfigurationSource class. An analysis of the application block revealed that<br />

the FileConfigurationSource class read the appropriate sections from the configuration<br />

file each time it created a Database object. This increased the number of I/O<br />

operations and impacted the application block’s performance.

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

Saved successfully!

Ooh no, something went wrong!