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(); } var root = TestKeyName; Assert.True(KeyExists(root)); Assert.False(KeyExists(string.Format("{0}\\{1}", root, SectionName))); Assert.True(KeyExists(root + "\\NewSettings")); Assert.True(KeyExists(root + "\\NewSettings\\Legacy")); } finally { DeleteKey(TestKeyName); } }
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.Equal(3, source.Sections.Count); Assert.Equal("NewSettings\\Legacy", source.Sections.ToList()[0].Value.Name); Assert.Equal(15, source.Sections["NewSettings\\Legacy"].Get <int>("count")); Assert.Equal("NewSettings", source.Sections.ToList()[1].Value.Name); Assert.Equal(5, source.Sections["NewSettings"].Get <int>("count")); Assert.Equal(SectionName, source.Sections.ToList()[2].Value.Name); Assert.Equal("value", source.Sections[SectionName].Get <string>("key")); } } finally { DeleteKey(TestKeyName); } }
public void CanWriteRegistryValueKinds() { try { CreateRegistryValueKindSamples(TestKey, SectionName); using (var source = new RegistryConfigurationSource(FullTestKeyName(TestKeyName))) { var 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))) { var section = source.Sections[SectionName]; var quadWord = section.Get <long>("QuadWordValue"); Assert.Equal(13, quadWord); var dWord = section.Get <int>("DWordValue"); Assert.Equal(13, dWord); var strings = section.Get <string[]>("MultipleStringValue"); Assert.Equal(new[] { 13.ToString(), 13.ToString() }, strings); var newStringValue = section.Get <string>("StringValue"); Assert.Equal(13.ToString(), newStringValue); var newExpandedStringValue = section.Get <string>("ExpandedStringValue"); Assert.NotEqual(expandedStringValue, newExpandedStringValue); var realExpandedValue = "13 %PATH%".Replace("%PATH%", Environment.GetEnvironmentVariable("PATH")); Assert.Equal(realExpandedValue, newExpandedStringValue); var data = section.Get <byte[]>("BinaryValue"); Assert.Equal(new byte[] { 13, 13 }, data); } } finally { DeleteKey(TestKeyName); } }
public void CanAddNewKeys() { 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.Save(); } var root = TestKeyName; Assert.True( KeyExists( root ) ); Assert.False( KeyExists( string.Format( "{0}\\{1}", root, SectionName ) ) ); Assert.True( KeyExists( root + "\\NewSettings" ) ); } finally { DeleteKey( TestKeyName ); } }
public void CanLoadKeys() { 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.Save(); } using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) ) { Assert.Equal( 2, source.Sections.Count ); Assert.Equal( "NewSettings", source.Sections.ToList()[0].Value.Name ); Assert.Equal( 5, source.Sections["NewSettings"].Get<int>( "count" ) ); Assert.Equal( SectionName, source.Sections.ToList()[1].Value.Name ); Assert.Equal( "value", source.Sections[SectionName].Get<string>( "key" ) ); } } finally { DeleteKey( TestKeyName ); } }
public void CanWriteRegistryValueKinds() { try { CreateRegistryValueKindSamples( TestKey, SectionName ); using ( var source = new RegistryConfigurationSource( FullTestKeyName( TestKeyName ) ) ) { var 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 ) ) ) { var section = source.Sections[SectionName]; var quadWord = section.Get<long>( "QuadWordValue" ); Assert.Equal( 13, quadWord ); var dWord = section.Get<int>( "DWordValue" ); Assert.Equal( 13, dWord ); var strings = section.Get<string[]>( "MultipleStringValue" ); Assert.Equal( new[] {13.ToString(), 13.ToString()}, strings ); var newStringValue = section.Get<string>( "StringValue" ); Assert.Equal( 13.ToString(), newStringValue ); var newExpandedStringValue = section.Get<string>( "ExpandedStringValue" ); Assert.NotEqual( expandedStringValue, newExpandedStringValue ); var realExpandedValue = "13 %PATH%".Replace( "%PATH%", Environment.GetEnvironmentVariable( "PATH" ) ); Assert.Equal( realExpandedValue, newExpandedStringValue ); var data = section.Get<byte[]>( "BinaryValue" ); Assert.Equal( new byte[] {13, 13}, data ); } } finally { DeleteKey( TestKeyName ); } }