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

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

Verify that the<br />

application block<br />

validates the input<br />

at all of its entry<br />

points.<br />

Yes<br />

For example, the Tracer class that traces the log methods<br />

first validates the LogWriter object before it starts<br />

to trace a method. An invalid input causes an exception.<br />

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

public Tracer(…, LogWriter writer, …)<br />

{<br />

if (writer == null) throw new ArgumentNullExcep<br />

tion("writer", …);<br />

}<br />

Verify that the<br />

errors that occur<br />

during a logging<br />

operation are<br />

logged to the errors<br />

special trace<br />

source, if it is in<br />

the configuration<br />

source.<br />

Verify that the<br />

application block<br />

can log information<br />

to multiple trace<br />

sources.<br />

Yes<br />

Yes<br />

For example, in the following code, if the missingCategories<br />

category is not in the configuration source, the<br />

application block logs an error to the errors special trace<br />

source that is in the configuration source.<br />

private void ReportMissingCategories(List missingCategories, LogEntry logEntry)<br />

{<br />

…<br />

structureHolder.ErrorsTraceSource.TraceData(…);<br />

…<br />

}<br />

The Logger.Write method calls the LogWriter.Process-<br />

Log private method. This method logs the information<br />

to multiple trace sources. This is shown in the following<br />

code example.<br />

private void ProcessLog(LogEntry log)<br />

{<br />

…<br />

foreach (LogSource traceSource in matching-<br />

TraceSources)<br />

{<br />

…<br />

traceSource.TraceData(…);<br />

…<br />

}<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!