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

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

Verify that the application<br />

block performs scavenging<br />

when the cached items<br />

exceed the configured limit.<br />

In addition, verify that the<br />

number of items to be scavenged<br />

is configurable.<br />

Yes<br />

When an item is added to an instance of the<br />

Cache class, the application block checks to<br />

see if the limit set in the configuration source<br />

has been reached. If it has, the scavenging<br />

process begins. This is shown in the following<br />

code example.<br />

public void Add(…)<br />

{<br />

if (scavengingPolicy.IsScavengingNeeded<br />

(inMemoryCache.Count))<br />

{<br />

cacheScavenger.StartScavenging();<br />

}<br />

}<br />

The number of items that are scavenged<br />

depends on the value set in the configuration<br />

source. This value is injected into the ScavengerTask<br />

class. The RemoveScavengableItems<br />

method checks for this value before it removes<br />

the specified number of items from the cache.<br />

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

private void RemoveScavengableItems(Sor<br />

tedList scavengableItems)<br />

{<br />

int scavengedItemCount = 0;<br />

foreach (CacheItem scavengableItem in<br />

scavengableItems.Values)<br />

{<br />

…<br />

if (scavengedItemCount == NumberOfItemsToBeScavenged)<br />

{<br />

break;<br />

}<br />

}<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!