Esempio n. 1
0
        [Test]         // #373
        public void object_to_kv_ignores_props_not_publicly_readable()
        {
            var kv = new ToKvMe {
                PrivateRead2 = "foo",
                WriteOnly    = "a,b"
            }.ToKeyValuePairs();

            AssertKV(kv, ("Read1", "a"), ("Read2", "b"));
        }
Esempio n. 2
0
        public void can_parse_dictionary_to_kv()
        {
            var kv = new Dictionary <string, object> {
                { "one", 1 },
                { "two", "foo" },
                { "three", null }
            }.ToKeyValuePairs();

            AssertKV(kv, ("one", 1), ("two", "foo"), ("three", null));
        }
Esempio n. 3
0
        public void can_parse_object_to_kv()
        {
            var kv = new {
                one   = 1,
                two   = "foo",
                three = (string)null
            }.ToKeyValuePairs();

            AssertKV(kv, ("one", 1), ("two", "foo"), ("three", null));
        }
Esempio n. 4
0
        public void can_parse_collection_of_kvp_to_kv()
        {
            var kv = new[] {
                new KeyValuePair <object, object>("one", 1),
                new KeyValuePair <object, object>("two", "foo"),
                new KeyValuePair <object, object>("three", null),
                new KeyValuePair <object, object>(null, "four"),
            }.ToKeyValuePairs();

            AssertKV(kv, ("one", 1), ("two", "foo"), ("three", null));
        }
Esempio n. 5
0
        public void can_parse_collection_of_conventional_objects_to_kv()
        {
            // convention is to accept collection of any arbitrary type that contains
            // a property called Key or Name and a property called Value
            var kv = new object[] {
                new { Key = "one", Value = 1 },
                new { key = "two", value = "foo" },                 // lower-case should work too
                new { Key = (string)null, Value = 3 },              // null keys should get skipped
                new { Name = "three", Value = (string)null },
                new { name = "four", value = "bar" }                // lower-case should work too
            }.ToKeyValuePairs().ToList();

            AssertKV(kv, ("one", 1), ("two", "foo"), ("three", null), ("four", "bar"));
        }
Esempio n. 6
0
        public void can_parse_string_to_kv()
        {
            var kv = "one=1&two=foo&three".ToKeyValuePairs();

            AssertKV(kv, ("one", "1"), ("two", "foo"), ("three", null));
        }