Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
76<br />
<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />
Code test case<br />
Verify that the application<br />
block supports post<br />
handling actions such as<br />
None, NotifyRethrow, and<br />
ThrowNewException after<br />
it executes the exception<br />
handlers.<br />
Verify that the application<br />
block uses the Logging<br />
Application Block to log the<br />
exceptions.<br />
Verify that the performance<br />
counters and the event log<br />
that are required by the application<br />
block are installed<br />
during installation.<br />
Implemented?<br />
Yes<br />
Yes<br />
Yes<br />
Feature that is implemented<br />
The ExceptionPolicyEntry class executes the exception<br />
handlers for the given exception. This class<br />
contains a method named Handle that calls the private<br />
method RethrowRecommended. This method executes<br />
the post handling action. This is shown in the<br />
following code example.<br />
private bool RethrowRecommended(Exception<br />
chainException, Exception originalException)<br />
{<br />
if (postHandlingAction == PostHandlingAction.<br />
None) return false;<br />
if (postHandlingAction == PostHandlingAction.<br />
ThrowNewException)<br />
{<br />
throw IntentionalRethrow(chainException,<br />
originalException);<br />
}<br />
return true;<br />
}<br />
The LoggingExceptionHandler class logs the exceptions.<br />
This class has a method named WriteToLog that<br />
uses an instance of the Logging Application Block’s<br />
LogWriter class. This is shown in the following code<br />
example.<br />
public class LoggingExceptionHandler : IExceptionHandler<br />
{<br />
private readonly LogWriter logWriter;<br />
protected virtual void WriteToLog(string log-<br />
Message, IDictionary exceptionData)<br />
{<br />
this.logWriter.Write(entry);<br />
}<br />
}<br />
For example, the ExceptionHandlingInstrumentation-<br />
Listener class contains the installer attribute type<br />
[HasInstallableResourcesAttribute]. The EventLogInstallerBuilder<br />
and the PerformanceCounterInstaller-<br />
Builder installer classes, which are in the <strong>Enterprise</strong><br />
<strong>Library</strong> Core, recognize this attribute and install the<br />
performance counters and event logs.