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.

<strong>Test</strong>ing the Cryptography Application Block 47<br />

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

Verify that the<br />

application block<br />

uses performance<br />

counters to monitor<br />

hash and symmetric<br />

operations<br />

when the performance<br />

counters<br />

are enabled.<br />

Yes<br />

Verify that the<br />

application block<br />

uses WMI and the<br />

event log to monitor<br />

errors during<br />

encryption, decryption,<br />

and hash<br />

operations when<br />

WMI and event log<br />

are enabled.<br />

Yes<br />

For example, the SymmtericAlgorithmProvider.Encrypt<br />

method increments the symmetric encryption performance<br />

counter whenever there is a successful encryption<br />

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

example. The process is similar for hash operations.<br />

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

{<br />

crypto.Encrypt(plaintext);<br />

InstrumentationProvider.FireSymmetricEncryptionPerformed();<br />

}<br />

[InstrumentationConsumer("SymmetricEncryptio<br />

nPerformed")]<br />

public void SymmetricEncryptionPerformed(obje<br />

ct sender, EventArgs e)<br />

{<br />

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

}<br />

For example, the SymmtericAlgorithmProvider.Encrypt<br />

method uses WMI and the event log when the encryption<br />

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

example. The process is similar for other operations.<br />

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

{<br />

try<br />

{<br />

output = crypto.Encrypt(plaintext);<br />

}<br />

catch (Exception e)<br />

{<br />

InstrumentationProvider.FireCyptographicOperationFailed(…);<br />

throw;<br />

}<br />

}<br />

[InstrumentationConsumer("CyptographicOperati<br />

onFailed")]<br />

public void CyptographicOperationFailed(…)<br />

{<br />

if (EventLoggingEnabled)<br />

{<br />

EventLog.WriteEntry(GetEventSourceName(),<br />

entryText, EventLogEntryType.Error);<br />

}<br />

if (WmiEnabled) ManagementInstrumentation.<br />

Fire(new SymmetricOperationFailedEvent(…));<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!