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.

90<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

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

Verify that the<br />

application block<br />

responds to runtime<br />

configuration<br />

changes.<br />

Yes<br />

The LogWriterStructureHolderUpdater internal class registers<br />

a handler with the configuration source that will be<br />

notified if its data changes. This is shown in the following<br />

code example.<br />

configurationSource.AddSectionChangeHandler(Logg<br />

ingSettings.SectionName, UpdateLogWriter);<br />

If the configuration source changes at run time, the configuration<br />

source notifies the UpdateLogWriter method.<br />

This method replaces the old object with a new LogWriterStructureHolder<br />

object. This is shown in the following<br />

code example.<br />

public void UpdateLogWriter(…)<br />

{<br />

…<br />

logWriter.ReplaceStructureHolder(newStructureH<br />

older);<br />

}<br />

Verify that the<br />

application block<br />

disposes of the<br />

old LogWriteStructureHolder<br />

object<br />

and creates a<br />

new one when the<br />

configuration information<br />

changes<br />

during run time.<br />

Yes<br />

The UpdateLogWriter method calls the LogWriter.<br />

ReplaceStructureHolder method when the configuration<br />

data changes. This method creates a new LogWriter-<br />

StructureHolder object and disposes of the old one. This<br />

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

internal void ReplaceStructureHolder(LogWriterS<br />

tructureHolder newStructureHolder)<br />

{<br />

LogWriterStructureHolder oldStructureHolder =<br />

structureHolder;<br />

structureHolder = newStructureHolder;<br />

Verify that the Logger<br />

façade creates<br />

the LogWriter object<br />

only once and<br />

that it uses the<br />

same object for all<br />

logging requests<br />

that come from the<br />

same application.<br />

Yes<br />

oldStructureHolder.Dispose();<br />

}<br />

The Logger class only creates a Writer object if the<br />

object is currently null and is static. This is shown in the<br />

following code example.<br />

public static LogWriter Writer<br />

{<br />

get<br />

{<br />

if (writer == null)<br />

{<br />

…<br />

writer = factory.Create();<br />

}<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!