public void CanAddMultiLevelKeys()
        {
            try
            {
                using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) )
                {
                    source.Sections[SectionName].Set( "key", "value" );
                    source.Add( new ConfigurationSection( "NewSettings" ) );
                    source.Sections["NewSettings"].Set( "count", 5 );
                    source.Add( new ConfigurationSection( "NewSettings\\Legacy" ) );
                    source.Sections["NewSettings\\Legacy"].Set( "count", 5 );
                    source.Save();
                }

                string root = TestKeyName;
                Assert.IsTrue( KeyExists( root ) );
                Assert.IsFalse( KeyExists( string.Format( "{0}\\{1}", root, SectionName ) ) );
                Assert.IsTrue( KeyExists( root + "\\NewSettings" ) );
                Assert.IsTrue( KeyExists( root + "\\NewSettings\\Legacy" ) );
            }
            finally
            {
                DeleteKey( TestKeyName );
            }
        }
        public void CanWriteRegistryValueKinds()
        {
            try
            {
                CreateRegistryValueKindSamples( TestKey, SectionName );

                using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) )
                {
                    IConfigurationSection section = source.Sections[SectionName];
                    section.Set( "QuadWordValue", 13 );
                    section.Set( "DWordValue", 13 );
                    section.Set( "StringValue", 13.ToString() );
                    section.Set( "ExpandedStringValue", "13 %PATH%" );
                    section.Set( "MultipleStringValue", new[] { 13.ToString(), 13.ToString() } );
                    section.Set( "BinaryValue", new byte[] { 13, 13 } );
                    source.Save();
                }
                using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) )
                {
                    IConfigurationSection section = source.Sections[SectionName];
                    var quadWord = section.Get<long>( "QuadWordValue" );
                    Assert.AreEqual( 13, quadWord );

                    var dWord = section.Get<int>( "DWordValue" );
                    Assert.AreEqual( 13, dWord );

                    var strings = section.Get<string[]>( "MultipleStringValue" );
                    Assert.AreEqual( new[] { 13.ToString(), 13.ToString() }, strings );

                    var newStringValue = section.Get<string>( "StringValue" );
                    Assert.AreEqual( 13.ToString(), newStringValue );

                    var newExpandedStringValue = section.Get<string>( "ExpandedStringValue" );
                    Assert.AreNotEqual( expandedStringValue, newExpandedStringValue );
                    string realExpandedValue = "13 %PATH%".Replace( "%PATH%",
                                                                    Environment.GetEnvironmentVariable( "PATH" ) );
                    Assert.AreEqual( realExpandedValue, newExpandedStringValue );

                    var data = section.Get<byte[]>( "BinaryValue" );
                    Assert.AreEqual( new byte[] { 13, 13 }, data );
                }
            }
            finally
            {
                DeleteKey( TestKeyName );
            }
        }
        public void CanReadRegistryValueKinds()
        {
            try
            {
                CreateRegistryValueKindSamples( TestKey, SectionName );

                using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) )
                {
                    IConfigurationSection section = source.Sections[SectionName];

                    var quadWord = section.Get<long>( "QuadWordValue" );
                    Assert.AreEqual( quadWordValue, quadWord );

                    var dWord = section.Get<int>( "DWordValue" );
                    Assert.AreEqual( quadWordValue, dWord );

                    var strings = section.Get<string[]>( "MultipleStringValue" );
                    Assert.AreEqual( multipleStringValue, strings );

                    var newStringValue = section.Get<string>( "StringValue" );
                    Assert.AreEqual( stringValue, newStringValue );

                    var newExpandedStringValue = section.Get<string>( "ExpandedStringValue" );
                    Assert.AreNotEqual( expandedStringValue, newExpandedStringValue );
                    string realExpandedValue = expandedStringValue.Replace( "%PATH%",
                                                                            Environment.GetEnvironmentVariable( "PATH" ) );
                    Assert.AreEqual( realExpandedValue, newExpandedStringValue );

                    var data = section.Get<byte[]>( "BinaryValue" );
                    Assert.AreEqual( binaryValue, data );
                }
            }
            finally
            {
                DeleteKey( TestKeyName );
            }
        }
 public void CanReadRegistryGivenKeyName()
 {
     using (
             var source = new RegistryConfigurationSource( string.Format( "{0}\\{1}", LocalMachineRoot, KeyName ) )
             )
     {
     }
 }
 public void CanReadRegistryGivenKey()
 {
     using ( RegistryKey key =
             Registry.LocalMachine.OpenSubKey( KeyName ) )
     {
         using ( var source = new RegistryConfigurationSource( key ) )
         {
         }
     }
 }
        public void CanLoadMultiLevelKeys()
        {
            try
            {
                using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) )
                {
                    source.Sections[SectionName].Set( "key", "value" );
                    source.Add( new ConfigurationSection( "NewSettings" ) );
                    source.Sections["NewSettings"].Set( "count", 5 );
                    source.Add( new ConfigurationSection( "NewSettings\\Legacy" ) );
                    source.Sections["NewSettings\\Legacy"].Set( "count", 15 );
                    source.Save();
                }
                using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) )
                {
                    Assert.AreEqual( 3, source.Sections.Count );

                    Assert.AreEqual( "NewSettings\\Legacy", source.Sections.ToList()[0].Value.Name );
                    Assert.AreEqual( 15, source.Sections["NewSettings\\Legacy"].Get<int>( "count" ) );

                    Assert.AreEqual( "NewSettings", source.Sections.ToList()[1].Value.Name );
                    Assert.AreEqual( 5, source.Sections["NewSettings"].Get<int>( "count" ) );

                    Assert.AreEqual( SectionName, source.Sections.ToList()[2].Value.Name );
                    Assert.AreEqual( "value", source.Sections[SectionName].Get<string>( "key" ) );
                }
            }
            finally
            {
                DeleteKey( TestKeyName );
            }
        }