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.

52<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

Table 5: Visual Studio Team System <strong>Test</strong>s for the Cryptography Application Block<br />

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

Verify that the<br />

application block<br />

throws the appropriate<br />

exception<br />

when it receives<br />

Passed The following test uses a null message as input and expects<br />

an ArgumentNullException exception.<br />

[ExpectedException(typeof(ArgumentNullException<br />

))]<br />

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

invalid data.<br />

{<br />

Cryptographer.EncryptSymmetric(("DESCryptoServic<br />

eProvider", (String)null);<br />

}<br />

Verify that the<br />

application block<br />

encrypts valid<br />

input data.<br />

Verify that the symmetric<br />

and hash<br />

providers can be<br />

created directly,<br />

without using<br />

a configuration<br />

source.<br />

Passed<br />

Passed<br />

The following test encrypts a string.<br />

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

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

{<br />

String encryptedStrMessage = Cryptographer.Encr<br />

yptSymmetric(("DESCryptoServiceProvider","Sample<br />

Text");<br />

Assert.IsFalse(encryptedStrMessage.Equals(""));<br />

Assert.IsFalse(encryptedStrMessage.<br />

Equals("SampleText"));<br />

}<br />

The following test uses the new operator to directly create<br />

the hash provider and verifies that the object is created.<br />

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

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

{<br />

HashAlgorithmProvider provider = new HashAlgorit<br />

hmProvider(Type.GetType("System.Security.Cryptography.SHA1Managed,<br />

mscorlib, Version=2.0.0.0,<br />

Culture=neutral, PublicKeyToken=b77a5c561934e089<br />

"), true);<br />

Assert.IsNotNull(provider);<br />

}

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

Saved successfully!

Ooh no, something went wrong!