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 Security Application Block 119<br />

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

Verify that<br />

custom authorization<br />

classes that<br />

derive from the<br />

AuthorizationProvider<br />

class can<br />

be added to the<br />

application block<br />

and configured<br />

from the configuration<br />

source.<br />

Passed<br />

In this example, the CustomAuthorizationProvider custom authorization<br />

class derives from the AuthorizationProvider class. The<br />

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

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

The following is the configuration information.<br />

public DictionaryConfigurationSource BuildDictionarySourceSection()<br />

{<br />

DictionaryConfigurationSource section = new Dictionary-<br />

ConfigurationSource();<br />

SecuritySettings secSettings = new SecuritySettings();<br />

CustomAuthorizationProviderData customAuthProvider<br />

= new CustomAuthorizationProviderData("MyA<br />

uthorizationProvider",Type.GetType("….CustomAuthorizationProvider,…"));<br />

customAuthProvider.Attributes.Add("key1",<br />

"value1");<br />

secSettings.AuthorizationProviders.Add(cus<br />

tomAuthProvider);<br />

section.Add("securityConfiguration", secSettings);<br />

}<br />

The following is the custom class.<br />

[ConfigurationElementType(typeof(CustomAuthorizationPro<br />

viderData))]<br />

public class CustomAuthorizationProvider:AuthorizationProvider<br />

{<br />

public CustomAuthorizationProvider()<br />

{<br />

}<br />

public CustomAuthorizationProvider(System.Collections.<br />

Specialized.NameValueCollection collection )<br />

{<br />

}<br />

public override bool Authorize(IPrincipal principal,<br />

string context)<br />

{<br />

…<br />

}<br />

}<br />

The following is the test.<br />

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

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

{<br />

continued

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

Saved successfully!

Ooh no, something went wrong!