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

<strong>Test</strong> case Result Automated test<br />

Verify that the<br />

logging exception<br />

handlers log the<br />

exceptions to the<br />

trace listeners that<br />

are in the configuration<br />

source.<br />

Passed In the following test, the LoggingExceptionHandler class is<br />

configured to log exceptions to the event log. (The Logging<br />

Application Block configuration is not shown.) The test case<br />

verifies that the exception is logged to the event log. Similar<br />

tests exist for other handlers, such as the WrapHandler and<br />

the ReplaceHandler classes.<br />

The following is the configuration information.<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The following is the test.<br />

[<strong>Test</strong>Method]<br />

public void LoggingNoneActionEventSink<strong>Test</strong>()<br />

{<br />

Exception originalException = new System.Security.<br />

SecurityException("Security Exception logged in<br />

event sink");<br />

bool rethrow = ExceptionPolicy.HandleException(ori<br />

ginalException, "Logging To Event Sink PostHandlingAction<br />

None");<br />

using (EventLog eventlog = new<br />

EventLog("Application"))<br />

{<br />

int entryCount = eventlog.Entries.Count;<br />

Assert.AreEqual("ExceptionHandlingLogging",<br />

eventlog.Entries[eventlog.Entries.Count -<br />

1].Source);<br />

Assert.AreEqual(Convert.ToInt64(100), eventlog.<br />

Entries[eventlog.Entries.Count - 1].InstanceId);<br />

}<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!