コード例 #1
0
        public void Get()
        {
            ISettings settings = new InMemorySettings();

            Assert.That(settings.HasKey("int"), Is.EqualTo(false));
            Assert.That(settings.GetInt("int"), Is.EqualTo(0));
            Assert.That(settings.GetInt("int", 42), Is.EqualTo(42));
            Assert.That(settings.GetBool("bool"), Is.EqualTo(false));
            Assert.That(settings.GetBool("bool", true), Is.EqualTo(true));
            Assert.That(settings.GetFloat("float"), Is.EqualTo(0.0f));
            Assert.That(settings.GetFloat("float", 3.14f), Is.EqualTo(3.14f));
            Assert.That(settings.GetString("string"), Is.EqualTo(""));
            Assert.That(settings.GetString("string", "nada"), Is.EqualTo("nada"));
            Assert.That(settings.Keys, Is.EqualTo(new List <string>()));
        }
コード例 #2
0
        /// <summary>
        /// Test Set*() methods by fetching stored results.
        /// </summary>
        public void Set()
        {
            ISettings settings = new InMemorySettings();

            Assert.That(settings.HasKey("an_int"), Is.EqualTo(false));
            Assert.That(settings.GetInt("an_int"), Is.EqualTo(0));
            settings.SetInt("an_int", 42);
            Assert.That(settings.HasKey("an_int"), Is.EqualTo(true));
            Assert.That(settings.GetInt("an_int"), Is.EqualTo(42));
            Assert.That(settings.GetInt("an_int", 21), Is.EqualTo(42));

            Assert.That(settings.HasKey("a_bool"), Is.EqualTo(false));
            Assert.That(settings.GetBool("a_bool"), Is.EqualTo(false));
            settings.SetBool("a_bool", true);
            Assert.That(settings.HasKey("a_bool"), Is.EqualTo(true));
            Assert.That(settings.GetBool("a_bool"), Is.EqualTo(true));
            Assert.That(settings.GetBool("a_bool", false), Is.EqualTo(true));

            Assert.That(settings.HasKey("a_float"), Is.EqualTo(false));
            Assert.That(settings.GetFloat("a_float"), Is.EqualTo(0.0f));
            settings.SetFloat("a_float", 3.14f);
            Assert.That(settings.HasKey("a_float"), Is.EqualTo(true));
            Assert.That(settings.GetFloat("a_float"), Is.EqualTo(3.14f));
            Assert.That(settings.GetFloat("a_float", 0.707f), Is.EqualTo(3.14f));

            Assert.That(settings.HasKey("a_string"), Is.EqualTo(false));
            Assert.That(settings.GetString("a_string"), Is.EqualTo(""));
            settings.SetString("a_string", "nada");
            Assert.That(settings.HasKey("a_string"), Is.EqualTo(true));
            Assert.That(settings.GetString("a_string"), Is.EqualTo("nada"));
            Assert.That(settings.GetString("a_string", "casa"), Is.EqualTo("nada"));

            Assert.That(new HashSet <string>(settings.Keys),
                        Is.EqualTo(new HashSet <string> {
                "an_int", "a_bool", "a_float", "a_string"
            }));
        }