public void ReadAndWriteToEncryptedConfiguration()
        {
            const string sectionName = "MyEncryptedConfig";

            KeyAlgorithmPair keyAlgorithmPair = new KeyAlgorithmPair();

            keyAlgorithmPair.Key = new SymmetricAlgorithmKeyCreator(typeof(RijndaelManaged).AssemblyQualifiedName).GenerateKey();
            keyAlgorithmPair.AlgorithmTypeName = typeof(RijndaelManaged).AssemblyQualifiedName;

            FileKeyAlgorithmPairStorageProvider provider = new FileKeyAlgorithmPairStorageProvider();

            provider.ConfigurationName = "FileKeyAlgorithmPairStorageProviderData";

            using (ConfigurationBuilder builder = new ConfigurationBuilder())
            {
                // change wher the file is
                RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new NonDisposingWrapper(builder)));

                FileKeyAlgorithmPairStorageProviderData fileData = (FileKeyAlgorithmPairStorageProviderData)view.GetKeyAlgorithmPairStorageProviderData();
                fileData.Path = Path.GetTempFileName();
                provider.Initialize(view);
                provider.Save(keyAlgorithmPair);
                builder.WriteConfiguration(sectionName, data);
                MockConfigurationData myData = (MockConfigurationData)builder.ReadConfiguration(sectionName);
                Assert.AreEqual(myData.ToString(), data.ToString());
                builder.ClearSectionCache();
                myData = (MockConfigurationData)builder.ReadConfiguration(sectionName);
                Assert.AreEqual(myData.ToString(), data.ToString());
            }
        }
        public void SpaceInPathConfigWriteTest()
        {
            builder.WriteConfiguration(mockConfigSection, data);
            MockConfigurationData readData = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;

            Assert.IsNotNull(readData);
            Assert.AreEqual(data.ToString(), readData.ToString());
        }
        public void ReadWriteWebConfigTest()
        {
            string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, webConfigFile);

            using (ConfigurationBuilder builder = new ConfigurationBuilder(configFile))
            {
                ConfigurationSettings configData = new ConfigurationSettings(mockConfigSection);
                configData.ConfigurationSections.Add(GetConfigurationSection());
                builder.WriteMetaConfiguration(configData);
                builder.WriteConfiguration(mockConfigSection, data);
                MockConfigurationData readData = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
                Assert.IsNotNull(readData);
                Assert.AreEqual(data.ToString(), readData.ToString());
            }
        }