コード例 #1
0
        public void TryGetProperty_should_return_false_on_KeyNotFoundException()
        {
            var    pp = PropertyProvider.FromValue(new A());
            object dummy;

            Assert.False(pp.TryGetProperty("S", out dummy));
        }
コード例 #2
0
        public void FromValue_should_return_self_if_already_property_provider()
        {
            var existing = new Properties();
            var pp       = PropertyProvider.FromValue(existing);

            Assert.Same(existing, pp);
        }
コード例 #3
0
        public void Format_parse_and_render_string_format()
        {
            var pp = PropertyProvider.FromValue(new {
                planet = "Phazon",
            });

            Assert.Equal("Hello, Phazon", PropertyProvider.Format("Hello, ${planet}", pp));
        }
コード例 #4
0
        public void GetPropertyType_checks_each()
        {
            var composite = PropertyProvider.Compose(
                PropertyProvider.FromValue(new { a = 1, b = 2.0 }),
                PropertyProvider.FromValue(new { c = "1", d = 2.0m })
                );

            Assert.Equal(typeof(string), composite.GetPropertyType("c"));
        }
コード例 #5
0
        public void Format_should_fill_nominal()
        {
            var f  = PropertyProviderFormat.Parse("Hello, ${planet}");
            var pp = PropertyProvider.FromValue(new {
                planet = "Phazon",
            });

            Assert.Equal("Hello, Phazon", f.Format(pp));
        }
コード例 #6
0
        public void Format_should_invoke_delegates()
        {
            var           f     = PropertyProviderFormat.Parse("Hello, ${planet}");
            Func <string> thunk = () => "Phazon";
            var           pp    = PropertyProvider.FromValue(new {
                planet = thunk,
            });

            Assert.Equal("Hello, Phazon", f.Format(pp));
        }
コード例 #7
0
        public void FromValue_property_provider_should_obtain_values()
        {
            var pp = PropertyProvider.FromValue(new {
                planet = "Terra",
            });
            object home;

            Assert.True(pp.TryGetProperty("Planet", typeof(string), out home));
            Assert.Equal("Terra", home);
        }
コード例 #8
0
        public void TryGetProperty_should_surface_certain_apparent_exceptions()
        {
            var    pp = PropertyProvider.FromValue(new A());
            object dummy;

            // Throws on exceptions which aren't ArgumentException-derived
            Assert.Throws <TargetInvocationException>(() => pp.TryGetProperty("U", out dummy));

            Assert.False(pp.TryGetProperty("T", out dummy));
        }
コード例 #9
0
        public void Format_should_invoke_delegates_with_arg()
        {
            var f = PropertyProviderFormat.Parse("Hello, ${Planet}");
            Func <string, string> thunk2 = k => (k + " Phazon");
            var pp = PropertyProvider.FromValue(new {
                planet = thunk2,
            });

            Assert.Equal("Hello, Planet Phazon", f.Format(pp));
        }
コード例 #10
0
        public void TryGetProperty_checks_each()
        {
            var composite = PropertyProvider.Compose(
                PropertyProvider.FromValue(new { a = "1", b = "2" }),
                PropertyProvider.FromValue(new { c = "1", d = "2" })
                );

            object result;

            Assert.True(composite.TryGetProperty("c", out result));
            Assert.Equal("1", result);
        }
コード例 #11
0
        protected override int MatchCriteriaCore(object criteria)
        {
            if (criteria == null)
            {
                return(0);
            }

            int score = 0;
            IPropertyProvider source = PropertyProvider.FromValue(criteria);

            score += this.EnumerateExtensions().Contains(source.GetString("Extension")) ? 1 : 0;
            return(score);
        }
コード例 #12
0
        protected override int MatchCriteriaCore(object criteria)
        {
            if (criteria == null)
            {
                return(0);
            }

            int result = 0;
            var pp     = PropertyProvider.FromValue(criteria);

            result += EnumerateExtensions().Contains(pp.GetString("Extension")) ? 1 : 0;
            return(result);
        }
コード例 #13
0
        public void GetProperty_should_use_indexer_nominal()
        {
            var pp = PropertyProvider.FromValue(new A());

            Assert.Equal("U", pp.GetProperty("R"));
        }
コード例 #14
0
        public void TryGetProperty_should_return_false_on_null()
        {
            var pp = PropertyProvider.FromValue(new A());

            Assert.Null(pp.GetProperty("ZZZ"));
        }
コード例 #15
0
        public void FromValue_null_should_return_null_instance()
        {
            var pp = PropertyProvider.FromValue(null);

            Assert.Same(PropertyProvider.Null, pp);
        }
コード例 #16
0
        public void GetBoolean_will_throw_on_problem_parsing()
        {
            var pp = PropertyProvider.FromValue(new { a = "nope" });

            Assert.Throws <FormatException>(() => pp.GetBoolean("a"));
        }
コード例 #17
0
        public void GetBoolean_will_convert_from_text(string text, bool expected)
        {
            var pp = PropertyProvider.FromValue(new { a = text });

            Assert.Equal(expected, pp.GetBoolean("a"));
        }