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.

16<br />

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

Code test case<br />

Verify that the<br />

<strong>Enterprise</strong> <strong>Library</strong><br />

Core has configuration<br />

watchers that<br />

monitor specific sections<br />

of the external<br />

configuration source.<br />

If there are changes,<br />

these watchers<br />

should notify the<br />

appropriate class to<br />

update the configuration<br />

data.<br />

Verify that there are<br />

methods to properly<br />

dispose of the configuration<br />

watchers<br />

when the watchers<br />

are unregistered<br />

from the configuration<br />

source.<br />

Implemented?<br />

Yes<br />

Yes<br />

Feature that is implemented<br />

The BaseFileConfigurationSourceImplementation class<br />

implements the CreateWatcherForConfigSource method<br />

that adds a watcher. This watcher monitors specific sections<br />

of the external configuration source and notifies the OnExternalConfigurationChanged<br />

method when the configuration<br />

data changes. The OnExternalConfigurationChanged<br />

method then calls the RefreshExternalSections method of<br />

a class that derives from the BaseFileConfigurationSourceImplementation<br />

class to refresh the configuration data<br />

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

private ConfigurationSourceWatcher CreateWatcherFo<br />

rConfigSource(string configSource)<br />

{<br />

…<br />

watcher = new ConfigurationFileSourceWatcher(…<br />

,configSource,…,new ConfigurationChangedEventHandle<br />

r(OnExternalConfigurationChanged));<br />

…<br />

}<br />

In the following code example, the FileConfigurationSourceImplementation<br />

object, which derives from the BaseFile-<br />

ConfigurationSourceImplementation class, refreshes the<br />

configuration data by calling the UpdateCache method.<br />

protected override void RefreshExternalSections(s<br />

tring[] sectionsToRefresh)<br />

{<br />

UpdateCache();<br />

}<br />

The SystemConfigurationSourceImplementation class<br />

derives from the BaseFileConfigurationSourceImplementation<br />

class and implements a method named RemoveConfigSourceWatcher.<br />

This method disposes of the watchers<br />

when they are no longer needed. The same holds true for<br />

the FileConfigurationSourceImpementation class, which<br />

also derives from the BaseFileConfigurationSourceImplementation<br />

class.<br />

The following code example shows how the RemoveConfigSourceWatcher<br />

method disposes of the configuration<br />

watchers.<br />

private void RemoveConfigSourceWatcher(Configuratio<br />

nSourceWatcher watcher)<br />

{<br />

…<br />

(watcher as IDisposable).Dispose();<br />

}

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

Saved successfully!

Ooh no, something went wrong!