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.

<strong>Test</strong>ing the Cryptography Application Block 53<br />

<strong>Test</strong> case Result Automated test<br />

Verify that a<br />

custom class can<br />

be added from<br />

information in<br />

the configuration<br />

source.<br />

Passed<br />

In this example, a custom hash provider, the Custom Hash<br />

class, implements the IHashProvider interface. The <strong>Enterprise</strong><br />

<strong>Library</strong> Core uses information in the configuration<br />

source to add the custom class to the application block.<br />

CustomHash class<br />

[ConfigurationElementType(typeof(CustomHashProvid<br />

erData))]<br />

public class CustomHash:IHashProvider<br />

{<br />

public NameValueCollection ObjCol;<br />

public CustomHash(NameValueCollection obj)<br />

{<br />

this.ObjCol = obj;<br />

}<br />

byte[] CreateHash(byte[] plaintext){…}<br />

bool CompareHash(byte[] plaintext, byte[]<br />

hashedtext){…}<br />

}<br />

The following is the information in the configuration file.<br />

<br />

The following is the test case.<br />

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

public void <strong>Test</strong>CustomHash()<br />

{<br />

HashProviderFactory factory = new<br />

HashProviderFactory(new SystemConfiguration-<br />

Source());<br />

IHashProvider provider = factory.<br />

Create("CustomHash1");<br />

Assert.IsNotNull(provider);<br />

Assert.IsTrue(provider is CustomHash);<br />

}<br />

continued

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

Saved successfully!

Ooh no, something went wrong!