Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
80<br />
<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />
<strong>Test</strong> case Result Automated test<br />
Verify that ExceptionHandler<br />
objects<br />
can be created<br />
directly, without<br />
using a configuration<br />
source.<br />
Passed The following example verifies that a WrapHandler object<br />
can be created directly, without using a configuration source.<br />
There are similar tests for ReplaceHandler objects and LoggingExceptionHandler<br />
objects.<br />
[<strong>Test</strong>Method]<br />
public void WrapExceptionCreateDirect()<br />
{<br />
Exception originalException = new System.Arithmetic<br />
Exception("Arithmetic Exception is not handled");<br />
WrapHandler handler = new WrapHandler("Wrapped<br />
Exception: Arithmetic Exception wrapped with Security<br />
Exception", Type.GetType("System.Security.<br />
SecurityException, mscorlib, Version=2.0.0.0,<br />
Culture=neutral, PublicKeyToken=b77a5c561934e089")<br />
);<br />
Exception wrappedException = handler.HandleExceptio<br />
n(originalException, new Guid());<br />
Assert.IsTrue(wrappedException is System.Security.<br />
SecurityException);<br />
Assert.AreEqual(wrappedException.Message,<br />
"Wrapped Exception: Arithmetic Exception<br />
wrapped with Security Exception");<br />
Assert.IsTrue(wrappedException.InnerException<br />
is ArithmeticException);<br />
}<br />
Verify that custom<br />
exception handlers<br />
can be added to the<br />
application block<br />
from information in<br />
the configuration<br />
source.<br />
Passed<br />
In this example, a custom exception handler implements the<br />
IExceptionHandler interface. The test verifies that that custom<br />
handler class can be added to the application block from information<br />
in the configuration source.<br />
The following is the custom exception hander.<br />
CustomExceptionHandler class<br />
[ConfigurationElementType(typeof(CustomHandlerData)<br />
)]<br />
public class CustomExceptionHandler : IException-<br />
Handler<br />
{<br />
…<br />
NameValueCollection attributes;<br />
public CustomExceptionHandler(){}<br />
public CustomExceptionHandler(NameValueCollection<br />
attributes){…}<br />
public Exception HandleException(Exception exception,<br />
Guid correlationID)<br />
{<br />
…<br />
return exception;<br />
}<br />
}