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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Test</strong>ing the Logging Application Block 97<br />

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

Verify that custom<br />

classes can be added<br />

to the application<br />

block and configured<br />

from information in<br />

the configuration<br />

source.<br />

Passed In this example, the CustomRegistryListener custom trace<br />

listener derives from the CustomTraceListener class. The<br />

<strong>Enterprise</strong> <strong>Library</strong> Core uses information in the configuration<br />

source to add the custom class to the application<br />

block. The test verifies that the custom trace listener logs<br />

the registry data to the registry path that is specified in the<br />

configuration file.<br />

The following code defines the CustomRegistryListener<br />

class.<br />

CustomRegistryListener class<br />

[ConfigurationElementType(typeof(CustomTraceListe<br />

nerData))]<br />

public class CustomRegistryListener: Custom-<br />

TraceListener<br />

{<br />

public<br />

CustomRegistryListener():base(){}<br />

public CustomRegistryListener(string initialize-<br />

Data): base(){}<br />

public override void TraceData(…)<br />

{<br />

…write it to registry<br />

}<br />

public override void Write(){…}<br />

public override void WriteLine(string message){…}<br />

The following is the information in the configuration file.<br />

<br />

<br />

The following is the test.<br />

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

public void LogToRegistryListener()<br />

{<br />

LogEntry log = new LogEntry();<br />

log.Message = "To test CustomTrace Listener that<br />

derives from CustomTraceListener";<br />

log.Title= "LogToRegistryListener";<br />

log.Categories.Add("RegistryCategory");<br />

Logger.Write(log);<br />

RegistryKey key = Registry.LocalMachine.<br />

OpenSubKey(@"Software\Entlib<strong>Test</strong>App");<br />

string content = (string) key.<br />

GetValue("LogEntry");<br />

key.Close();<br />

Assert.IsTrue(content.Contains(log.Message));<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!