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.

Using the <strong>Test</strong> Cases 255<br />

Verification<br />

Running the test case again after applying the preceding code verified that no scavenging<br />

took place when the number of items to scavenge was set to zero.<br />

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

The test case checked to see that the Security Application Block’s secure cache did not<br />

generate valid tokens for an invalid identity, principal, or profile. Instead, the cache<br />

should throw an exception.<br />

<strong>Test</strong> Case<br />

The test case used the SecurityCacheFactory to create an in-memory cache store. It<br />

passed null values to the SaveIdentity, SavePrincipal, and SaveProfile methods. The<br />

following code shows the test case for the SaveProfile method.<br />

[<strong>Test</strong>Method]<br />

[ExpectedException(typeof(ArgumentNullException))]<br />

public void InMemorySaveWithNullProfile<strong>Test</strong>Fixture()<br />

{<br />

ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCachePro<br />

vider("CacheProvider");<br />

IToken token = securityCache.SaveProfile(null);<br />

if (token != null)<br />

{<br />

Assert.Fail();<br />

}<br />

}<br />

Problem<br />

The test case failed because the cache issued a valid token for an invalid value. The<br />

problem was that the CachingStoreProvider class did not validate the input values.<br />

The following is the code that caused the problem.<br />

public override IToken SaveProfile(object profile)<br />

{<br />

GuidToken guidToken = new GuidToken();<br />

SaveProfile(profile, guidToken);<br />

return guidToken;<br />

}

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

Saved successfully!

Ooh no, something went wrong!