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 Application Block 29<br />

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

Verify that the application<br />

block uses WMI and the<br />

event log to monitor errors<br />

during caching operations<br />

when WMI and the event log<br />

are enabled.<br />

Yes<br />

For example, if an exception occurs when the<br />

application block refreshes the cache, the<br />

RefreshActionInvoker.InvokeRefreshAction<br />

method handles the exception. This method<br />

uses an instance of the CachingInstrumentationProvider<br />

to notify WMI and the event log.<br />

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

public static void InvokeRefreshAction(…)<br />

{<br />

try<br />

{<br />

…<br />

refreshActionData.InvokeOnThread-<br />

PoolThread();<br />

}<br />

catch (Exception e)<br />

{<br />

instrumentationProvider.FireCache-<br />

Failed(…);<br />

}<br />

}<br />

The CachingInstrumentationProvider class<br />

raises the cacheFailed event. The CacheFailed<br />

method consumes the event and notifies WMI<br />

and logs the exception to the event log. This is<br />

shown in the following code example.<br />

[InstrumentationConsumer("CacheFailed"<br />

)]<br />

public void CacheFailed(…)<br />

{<br />

if (WmiEnabled)<br />

{<br />

System.Management.Instrumentation.<br />

Instrumentation.Fire(new CacheFailur<br />

eEvent(instanceName, e.ErrorMessage,<br />

e.Exception.ToString()));<br />

}<br />

if (EventLoggingEnabled)<br />

{<br />

…<br />

EventLog.WriteEntry(GetEventSourceName(<br />

), entryText, EventLogEntryType.Error);<br />

}<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!