public void can_get_bool_from_hashtable()
        {
            var table = new Hashtable { { "app id", "true" } };

            var value = table.GetValueOrDefault<bool>("app id");

            Expect(value, Is.True);
        }
        public void get_string_from_hashtable_when_default_is_provided()
        {
            var table = new Hashtable { { "app id", "abc123" } };

            var value = table.GetValueOrDefault("app id", "abracadabra");

            Expect(value, Is.EqualTo("abc123"));
        }
        public void can_get_default_string_from_hashtable()
        {
            var table = new Hashtable { { "app id", "abc123" } };

            var value = table.GetValueOrDefault("cat id", "Frank");

            Expect(value, Is.EqualTo("Frank"));
        }
        public void get_null_string_from_hashtable_for_missing_value()
        {
            var table = new Hashtable { { "app id", "abc123" } };

            var value = table.GetValueOrDefault<string>("cat id");

            Expect(value, Is.Null);
        }
        public void can_get_default_bool_from_hashtable()
        {
            var value = true;
            var table = new Hashtable { { "app id", "abc123" } };

            value = table.GetValueOrDefault("Allow Windows Live Writer", value);

            Expect(value, Is.True);
        }
        public void get_bool_from_hashtable_when_default_is_provided()
        {
            var table = new Hashtable { { "app id", "true" } };

            var value = table.GetValueOrDefault("app id", false);

            Expect(value, Is.True);
        }
        public void can_get_empty_string_rather_than_default()
        {
            var dictionary = new Hashtable { { "question", string.Empty } };

            var value = dictionary.GetValueOrDefault("question", "yes");

            Expect(value, Is.Empty);
        }
        public void can_get_null_value_rather_than_default()
        {
            var dictionary = new Hashtable { { "question", null } };

            var value = dictionary.GetValueOrDefault("question", "yes");

            Expect(value, Is.Null);
        }
        public void can_get_timespan_with_custom_converter()
        {
            var collection = new Hashtable { { "length", "1:10:10" } };

            var value = collection.GetValueOrDefault("length", TimeSpan.Parse);

            Expect(value, Is.EqualTo(TimeSpan.FromSeconds(4210)));
        }
        public void get_bool_with_custom_converter_from_hashtable()
        {
            var table = new Hashtable { { "allow", "on" } };

            var value = table.GetValueOrDefault(
                "allow",
                v =>
                {
                    bool allowed;
                    if (!bool.TryParse(v, out allowed))
                    {
                        allowed = v.Equals("on", StringComparison.Ordinal);
                    }

                    return allowed;
                });

            Expect(value, Is.True);
        }
        public void get_false_from_hashtable_for_missing_value()
        {
            var table = new Hashtable { { "app id", "abc123" } };

            var value = table.GetValueOrDefault<bool>("Allow Windows Live Writer");

            Expect(value, Is.False);
        }