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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Test</strong>ing the Application Block 33<br />

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

Verify that the application<br />

block operations, such as<br />

the Add and Remove methods<br />

enforce a strong exception<br />

guarantee. This means<br />

that if an operation fails,<br />

the state of the cache rolls<br />

back to what it was before<br />

the attempted operation.<br />

Yes<br />

The CacheManager class has an internal reference<br />

to a Cache object. This object guarantees<br />

exception-safe caching operations. For example,<br />

if an exception occurs during an add operation,<br />

the state of the cache rolls back to what it was<br />

before the attempted operation. This is shown<br />

in the following code example.<br />

public void Add(…)<br />

{<br />

try<br />

{<br />

…<br />

backingStore.<br />

Add(newCacheItem);<br />

inMemoryCache[key] = cacheItemBefore-<br />

Lock;<br />

}<br />

catch<br />

{<br />

backingStore.Remove(key);<br />

inMemoryCache.Remove(key);<br />

throw;<br />

}<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!