SetOption() публичный Метод

Sets an option identified by a key.
is invalid. is invalid.
public SetOption ( string key, string value ) : void
key string The key of the option to set.
value string A string representation of the option.
Результат void
Пример #1
0
        public void TestGetSetValue()
        {
            var config = new Config();

            Assert.Throws <KeyNotFoundException>(() => config.SetOption("Test", "Test"));

            Assert.IsFalse(config.HelpWithTesting);
            Assert.AreEqual("False", config.GetOption("help_with_testing"));
            config.SetOption("help_with_testing", "True");
            Assert.Throws <FormatException>(() => config.SetOption("help_with_testing", "Test"));
            Assert.IsTrue(config.HelpWithTesting);
            Assert.AreEqual("True", config.GetOption("help_with_testing"));

            config.SetOption("freshness", "10");
            Assert.AreEqual(TimeSpan.FromSeconds(10), config.Freshness);
            Assert.AreEqual("10", config.GetOption("freshness"));
        }
Пример #2
0
        public void TestGetSetValue()
        {
            var config = new Config();

            config.Invoking(x => x.SetOption("Test", "Test")).ShouldThrow <KeyNotFoundException>();

            config.HelpWithTesting.Should().BeFalse();
            config.GetOption("help_with_testing").Should().Be("False");
            config.SetOption("help_with_testing", "True");
            config.Invoking(x => x.SetOption("help_with_testing", "Test")).ShouldThrow <FormatException>();
            config.HelpWithTesting.Should().BeTrue();
            config.GetOption("help_with_testing").Should().Be("True");

            config.SetOption("freshness", "10");
            config.Freshness.Should().Be(TimeSpan.FromSeconds(10));
            config.GetOption("freshness").Should().Be("10");
        }
Пример #3
0
        /// <summary>
        /// Creates a deep copy of this <see cref="Config"/> instance.
        /// </summary>
        /// <returns>The new copy of the <see cref="Config"/>.</returns>
        public Config Clone()
        {
            var newConfig = new Config();

            foreach (var property in _metaData)
            {
                newConfig.SetOption(property.Key, GetOption(property.Key));
            }
            return(newConfig);
        }
Пример #4
0
 /// <summary>
 /// Creates a deep copy of this <see cref="Config"/> instance.
 /// </summary>
 /// <returns>The new copy of the <see cref="Config"/>.</returns>
 public Config Clone()
 {
     var newConfig = new Config();
     foreach (var property in _metaData)
         newConfig.SetOption(property.Key, GetOption(property.Key));
     return newConfig;
 }
Пример #5
0
        public void TestGetSetValue()
        {
            var config = new Config();
            Assert.Throws<KeyNotFoundException>(() => config.SetOption("Test", "Test"));

            Assert.IsFalse(config.HelpWithTesting);
            Assert.AreEqual("False", config.GetOption("help_with_testing"));
            config.SetOption("help_with_testing", "True");
            Assert.Throws<FormatException>(() => config.SetOption("help_with_testing", "Test"));
            Assert.IsTrue(config.HelpWithTesting);
            Assert.AreEqual("True", config.GetOption("help_with_testing"));

            config.SetOption("freshness", "10");
            Assert.AreEqual(TimeSpan.FromSeconds(10), config.Freshness);
            Assert.AreEqual("10", config.GetOption("freshness"));
        }
Пример #6
0
        public void TestGetSetValue()
        {
            var config = new Config();
            config.Invoking(x => x.SetOption("Test", "Test")).ShouldThrow<KeyNotFoundException>();

            config.HelpWithTesting.Should().BeFalse();
            config.GetOption("help_with_testing").Should().Be("False");
            config.SetOption("help_with_testing", "True");
            config.Invoking(x => x.SetOption("help_with_testing", "Test")).ShouldThrow<FormatException>();
            config.HelpWithTesting.Should().BeTrue();
            config.GetOption("help_with_testing").Should().Be("True");

            config.SetOption("freshness", "10");
            config.Freshness.Should().Be(TimeSpan.FromSeconds(10));
            config.GetOption("freshness").Should().Be("10");
        }