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
                = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource).GetInstance<ISecurityCacheProvider>("custom");

            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
                = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource).GetInstance<ISecurityCacheProvider>("custom");

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomSecurityCacheProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomSecurityCacheProvider)custom).customValue);
        }
        public void Setup()
        {
            CustomSecurityCacheProviderData securityCacheProviderData = new CustomSecurityCacheProviderData();
            securityCacheProviderData.Name = "Custom Cache Provider";
            securityCacheProviderData.Type = typeof(FaultyType);

            settings = new SecuritySettings();
            settings.SecurityCacheProviders.Add(securityCacheProviderData);
        }
        public void Setup()
        {
            CustomSecurityCacheProviderData securityCacheProviderData = new CustomSecurityCacheProviderData();
            securityCacheProviderData.Name = "Custom Cache Provider";
            securityCacheProviderData.Type = typeof(MockCustomSecurityCacheProvider);

            SecuritySettings settings = new SecuritySettings();
            settings.SecurityCacheProviders.Add(securityCacheProviderData);

            registrations = settings.GetRegistrations(null);
        }
        public void RegisteredSecurityCacheProviderDataProviderIsCalledWithCorrectOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(CustomSecurityCacheProviderData), registeredProvider);
            provider = new SecuritySettingsManageabilityProvider(subProviders);

            CustomSecurityCacheProviderData securitycacheProviderData = new CustomSecurityCacheProviderData("securitycacheProvider1", typeof(Object));
            section.SecurityCacheProviders.Add(securitycacheProviderData);

            MockRegistryKey machinesecuritycacheProvidersKey = new MockRegistryKey(false);
            machineKey.AddSubKey(SecuritySettingsManageabilityProvider.SecurityCacheProvidersKeyName, machinesecuritycacheProvidersKey);
            MockRegistryKey machinesecuritycacheProviderKey = new MockRegistryKey(false);
            machinesecuritycacheProvidersKey.AddSubKey("securitycacheProvider1", machinesecuritycacheProviderKey);
            MockRegistryKey machineOthersecuritycacheProviderKey = new MockRegistryKey(false);
            machinesecuritycacheProvidersKey.AddSubKey("securitycacheProvider2", machineOthersecuritycacheProviderKey);

            MockRegistryKey usersecuritycacheProvidersKey = new MockRegistryKey(false);
            userKey.AddSubKey(SecuritySettingsManageabilityProvider.SecurityCacheProvidersKeyName, usersecuritycacheProvidersKey);
            MockRegistryKey usersecuritycacheProviderKey = new MockRegistryKey(false);
            usersecuritycacheProvidersKey.AddSubKey("securitycacheProvider1", usersecuritycacheProviderKey);
            MockRegistryKey userOthersecuritycacheProviderKey = new MockRegistryKey(false);
            usersecuritycacheProvidersKey.AddSubKey("securitycacheProvider2", userOthersecuritycacheProviderKey);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(securitycacheProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreSame(machinesecuritycacheProviderKey, registeredProvider.machineKey);
            Assert.AreSame(usersecuritycacheProviderKey, registeredProvider.userKey);

            Assert.IsTrue(
                MockRegistryKey.CheckAllClosed(machinesecuritycacheProvidersKey, machinesecuritycacheProviderKey, machineOthersecuritycacheProviderKey,
                                               usersecuritycacheProvidersKey, usersecuritycacheProviderKey, userOthersecuritycacheProviderKey));
        }
        public void RegisteredSecurityCacheProviderDataProviderIsCalledWithNoOverrides()
        {
            MockConfigurationElementManageabilityProvider registeredProvider
                = new MockConfigurationElementManageabilityProvider();
            Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders
                = new Dictionary<Type, ConfigurationElementManageabilityProvider>();
            subProviders.Add(typeof(CustomSecurityCacheProviderData), registeredProvider);
            provider = new SecuritySettingsManageabilityProvider(subProviders);

            CustomSecurityCacheProviderData securitycacheProviderData = new CustomSecurityCacheProviderData("securitycacheProvider1", typeof(Object));
            section.SecurityCacheProviders.Add(securitycacheProviderData);

            provider.OverrideWithGroupPolicies(section, true, machineKey, userKey);

            Assert.IsTrue(registeredProvider.called);
            Assert.AreSame(securitycacheProviderData, registeredProvider.LastConfigurationObject);
            Assert.AreEqual(null, registeredProvider.machineKey);
            Assert.AreEqual(null, registeredProvider.userKey);
        }