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 75<br />

Code test case<br />

Verify that the configuration<br />

properties of the exception<br />

handling policies are<br />

exposed as public and that<br />

they are strongly typed.<br />

Verify that the configuration<br />

properties for the custom<br />

exception handlers are<br />

exposed as public and that<br />

they are implemented as a<br />

collection.<br />

Verify that the application<br />

block validates the input at<br />

all the entry points, such<br />

as the ExceptionPolicy<br />

façade.<br />

Verify that the Exception-<br />

PolicyFactory class only<br />

creates a single instance<br />

of the exception handling<br />

provider for all requests.<br />

Implemented?<br />

Yes<br />

Yes<br />

Yes<br />

Yes<br />

Feature that is implemented<br />

For example, in the ExceptionHandlingSettings class,<br />

the ExceptionPolicies property can only contain an<br />

ExceptionPolicyData collection. The following code<br />

demonstrates this.<br />

[ConfigurationProperty(policiesProperty)]<br />

public NamedElementCollection ExceptionPolicies<br />

{<br />

get { return (NamedElementCollection<br />

)this[policiesProperty];<br />

}<br />

}<br />

The CustomHandlerData class has a reference to the<br />

CustomProviderDataHelper class. This class adds the<br />

properties that are defined in the configuration source<br />

to an instance of the NameValueCollection class. This<br />

is shown in the following code example.<br />

private NameValueCollection attributes;<br />

private void AddAttributesFromConfigurationProperties()<br />

{<br />

foreach (ConfigurationProperty property in<br />

propertiesCollection)<br />

{<br />

…<br />

attributes.Add(property.Name, (string)helped<br />

CustomProviderData.BaseGetPropertyValue(prop<br />

erty));<br />

}<br />

}<br />

The ExceptionPolicy façade validates the input parameters<br />

that are passed to the HandleException method.<br />

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

public static bool HandleException(Exception<br />

exceptionToHandle, string policyName)<br />

{<br />

if (exceptionToHandle == null) throw new<br />

ArgumentNullException("exceptionToHandle");<br />

if(string.IsNullOrEmpty(policyName))<br />

throw new ArgumentException(…);<br />

}<br />

The ExceptionPolicyFactory class derives from the<br />

LocatorNameTypeFactoryBase class. This class only<br />

creates a single instance for all requests.<br />

continued

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

Saved successfully!

Ooh no, something went wrong!