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.

Introduction<br />

<br />

Performing Code Reviews<br />

Code reviews happen periodically throughout the development cycle. The process is<br />

similar to that of the design reviews. Each test case must be satisfied by a specific part<br />

of the implementation. The Microsoft test team used checklists for the code review<br />

that were similar to the ones used for the design review. Table 4 is an example of the<br />

code checklist for the Cryptography Application Block.<br />

Table 4: Cryptography Application Block Code Verification<br />

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

Verify that the Cryptographer<br />

facade exposes<br />

all public members as<br />

static and supports<br />

methods for encryption,<br />

decryption, and hashing.<br />

Implemented?<br />

Yes<br />

Feature That is Implemented<br />

The Cryptographer class is a facade that exposes the<br />

CreateHash method to compute the hash value of plain<br />

text, the CompareHash method to compare plain text<br />

with a hash value, the EncryptSymmetric method to<br />

encrypt plain text, and the DecryptSymmetric method<br />

to decrypt a symmetrically encrypted secret. These<br />

methods are shown in the following code.<br />

public static byte[] CreateHash(string<br />

hashInstance, byte[] plaintext) {}<br />

public static bool CompareHash(string<br />

hashInstance, string plaintext, string<br />

hashedText) {}<br />

public static string EncryptSymmetric(string<br />

symmetricInstance, string plaintext) {}<br />

Verify that the Cryptographer<br />

facade uses the<br />

SymmetricCryptoProviderFactory<br />

class and<br />

the HashProviderFactory<br />

class to create the cryptography<br />

providers.<br />

Yes<br />

public static string DecryptSymmetric(string<br />

symmetricInstance, string ciphertextBase64) {}<br />

The client code calls static methods on the Cryptographer<br />

class to create hashes, compare hashes, encrypt<br />

data, and decrypt data. Each static method instantiates a<br />

factory class and passes the configuration source to the<br />

factory class’s constructor. The factory uses the configuration<br />

data to determine the type of provider to create.<br />

The following code demonstrates how the Cryptographer.<br />

EncryptSymmetric method calls the SymmetricCrypto-<br />

ProviderFactory class to create a symmetric provider. The<br />

process is similar for hash providers.<br />

public static byte[] EncryptSymmetric(string<br />

symmetricInstance, byte[] plaintext)<br />

{<br />

…<br />

SymmetricCryptoProviderFactory factory = new<br />

SymmetricCryptoProviderFactory(ConfigurationSou<br />

rceFactory.Create());<br />

…<br />

}

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

Saved successfully!

Ooh no, something went wrong!