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.

250<br />

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

<strong>Test</strong> Case<br />

The test case created an instance of the DpapiCryptographer class and passed the<br />

DataProtectionScope mode as LocalMachine. It called the DpapiCryptographer.<br />

Encrypt method with null entropy. It then checked to verify that the data was encrypted.<br />

Problem<br />

The Encrypt method checked to see whether the DataProtectionScope enumeration<br />

was set to LocalMachine. If it was, and there was no entropy, the method threw an<br />

exception. This is incorrect. Entropy is not a requirement for local stores in highly<br />

trusted computers that are used for server-side applications. The DataProtection-<br />

Scope.LocalMachine setting with no entropy is actually valid. The following code<br />

caused the problem.<br />

public byte[] Encrypt(byte[] plaintext)<br />

{<br />

if (DataProtectionScope.LocalMachine == storeScope)<br />

{<br />

throw new InvalidOperationException(Resources.DpapiMustHaveEntropyForMachineMode);<br />

}<br />

return Encrypt(plaintext, null);<br />

}<br />

Solution<br />

To solve the problem, the code that checked for the LocalMachine setting when there<br />

was no entropy was removed. The following is the modified code.<br />

public byte[] Encrypt(byte[] plaintext)<br />

{<br />

}<br />

return Encrypt(plaintext, null);<br />

Verification<br />

Running the modified code verified that the Encrypt method no longer threw an<br />

exception.<br />

<strong>Test</strong>ing the Data Access Application Block<br />

The test case determined whether the Data Access Application Block could read configuration<br />

information from a configuration source other than a file. For the test, the<br />

configuration source was an in-memory dictionary and the configuration information<br />

was a connection string.

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

Saved successfully!

Ooh no, something went wrong!