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.

118<br />

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

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

Verify that authorization<br />

providers<br />

and security<br />

cache providers<br />

can be created<br />

from a dictionary<br />

or from an inmemory<br />

Passed This test verifies that an AuthorizationRuleProvider can be created<br />

from a dictionary source. Similar tests were used with an<br />

AzmanAuthorizationProvider object and a CachingStoreProvider<br />

object. The following code defines the dictionary.<br />

public class AuthorizationRuleDictSource<br />

{<br />

public DictionaryConfigurationSource BuildDictionarySourceSection()<br />

configu-<br />

{<br />

ration source.<br />

DictionaryConfigurationSource section = new Dictionary-<br />

ConfigurationSource();<br />

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

secSettings.DefaultAuthorizationProvider-<br />

Name = "DefaultRuleProviderDic";<br />

…<br />

arpd.Type = Type.GetType("Microsoft.Practices.<strong>Enterprise</strong><strong>Library</strong>.Security.AuthorizationRuleProvider,<br />

Microsoft.Practices.<strong>Enterprise</strong><strong>Library</strong>.Security");<br />

secSettings.AuthorizationProviders.<br />

Add(arpd);<br />

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

return section;<br />

}<br />

The following is the test.<br />

// This initializes the constructor<br />

[<strong>Test</strong>Initialize()]<br />

public void My<strong>Test</strong>Initialize()<br />

{<br />

AuthorizationRuleDictSource sourceSection = new AuthorizationRuleDictSource();<br />

configSource = sourceSection.BuildDictionarySourceSection();<br />

AuthorizationProviderFactory authFactory =<br />

new AuthorizationProviderFactory(configSource);<br />

authRuleProvider = authFactory.Create("DefaultRuleProv<br />

iderDic") as AuthorizationRuleProvider;<br />

identity = new GenericIdentity("<strong>Test</strong>User");<br />

string[] roles = new string[] { "Manager" };<br />

principal = new GenericPrincipal(identity, roles);<br />

}<br />

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

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

{<br />

bool authorized = authRuleProvider.<br />

Authorize(principal, "<strong>Test</strong>IdentityRuleDic");<br />

Assert.IsTrue(authorized);<br />

}

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

Saved successfully!

Ooh no, something went wrong!