public void CanCreateSecurityCacheProvider()
        {
            SecurityCacheProviderFactory factory  = new SecurityCacheProviderFactory(GetConfigurationSource());
            ISecurityCacheProvider       provider = factory.Create("provider1");

            Assert.AreEqual(typeof(MockSecurityCacheProvider), provider.GetType());
        }
        [Ignore]    //TODO try a different instrumentation mechanism
        public void CreatedProviderHasCorrectInstrumentationListener()
        {
            SecurityCacheProviderFactory factory  = new SecurityCacheProviderFactory(GetConfigurationSource());
            ISecurityCacheProvider       provider = factory.Create("provider1");

            Assert.AreEqual(typeof(MockSecurityCacheProvider), provider.GetType());

            MockSecurityCacheProvider mockProvider = (MockSecurityCacheProvider)provider;
            ISecurityCacheProviderInstrumentationProvider instrumentationProvider = mockProvider.GetInstrumentationProvder();

            Assert.IsInstanceOfType(instrumentationProvider, typeof(SecurityCacheProviderInstrumentationProvider));

            SecurityCacheProviderInstrumentationProvider castedProvider = (SecurityCacheProviderInstrumentationProvider)instrumentationProvider;

            using (WmiEventWatcher eventWatcher = new WmiEventWatcher(1))
            {
                IToken token = new GuidToken();
                castedProvider.FireSecurityCacheReadPerformed(SecurityEntityType.Identity, token);
                eventWatcher.WaitForEvents();

                Assert.AreEqual(1, eventWatcher.EventsReceived.Count);
                Assert.AreEqual("SecurityCacheReadPerformedEvent", eventWatcher.EventsReceived[0].ClassPath.ClassName);
                Assert.AreEqual(SecurityEntityType.Identity.ToString(), eventWatcher.EventsReceived[0].Properties["EntityType"].Value);
                Assert.AreEqual("provider1", eventWatcher.EventsReceived[0].Properties["InstanceName"].Value);
                Assert.AreEqual(token.Value, eventWatcher.EventsReceived[0].Properties["TokenUsed"].Value);
            }
        }
        public void CanBuildCustomSecurityCacheProviderFromGivenConfiguration()
        {
            CustomSecurityCacheProviderData customData
                = new CustomSecurityCacheProviderData("custom", typeof(MockCustomSecurityCacheProvider));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            SecuritySettings settings = new SecuritySettings();

            settings.SecurityCacheProviders.Add(customData);
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(SecuritySettings.SectionName, settings);

            ISecurityCacheProvider custom
                = EnterpriseLibraryFactory.BuildUp <ISecurityCacheProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomSecurityCacheProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomSecurityCacheProvider)custom).customValue);
        }
        public void CanBuildCustomSecurityCacheProviderFromSavedConfiguration()
        {
            CustomSecurityCacheProviderData customData
                = new CustomSecurityCacheProviderData("custom", typeof(MockCustomSecurityCacheProvider));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            SecuritySettings settings = new SecuritySettings();

            settings.SecurityCacheProviders.Add(customData);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(1);

            sections[SecuritySettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            ISecurityCacheProvider custom
                = EnterpriseLibraryFactory.BuildUp <ISecurityCacheProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomSecurityCacheProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomSecurityCacheProvider)custom).customValue);
        }