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 <strong>Enterprise</strong> <strong>Library</strong> Core 71<br />

Code test case<br />

Verify that the Exception-<br />

Policy façade uses the<br />

ExceptionPolicyFactory<br />

class to create an ExceptionPolicyImpl<br />

object,<br />

which handles exception<br />

policies.<br />

Implemented?<br />

Yes<br />

Feature that is implemented<br />

The client code calls static methods on the ExceptionPolicy<br />

class to handle exceptions. The static<br />

method instantiates a factory class. The factory uses<br />

the configuration data from the configuration file and<br />

creates the exception policies. The following code<br />

demonstrates how the ExceptionPolicy.HandleException<br />

method calls the ExceptionPolicyFactory class to<br />

create an ExceptionPolicyImpl object that handles the<br />

exception.<br />

public static class ExceptionPolicy<br />

{<br />

private static readonly ExceptionPolicyFactory<br />

factory = new ExceptionPolicyFactory();<br />

public static bool HandleException(Exception<br />

exceptionToHandle, string policyName)<br />

{<br />

…<br />

ExceptionPolicyImpl policy = GetExceptionPoli<br />

cy(exceptionToHandle, policyName);<br />

…<br />

}<br />

private static ExceptionPolicyImpl GetExcept<br />

ionPolicy(Exception exception, string policy-<br />

Name)<br />

{<br />

…<br />

return factory.Create(policyName);<br />

…<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!