コード例 #1
0
        public void String()
        {
            var provider = new ValueProvider() { Parameters = { new Parameter("age", "Why do you need to know???") } };
            var context = new ModelBinderContext(typeof(string), "age", "", provider);

            var binder = new PrimitiveModelBinder();
            var actual = (string)binder.Bind(context);

            Assert.Equal("Why do you need to know???", actual);
        }
コード例 #2
0
        public void Int()
        {
            var provider = new ValueProvider() { Parameters = { new Parameter("age", "3")}};
            var context = new ModelBinderContext(typeof(int), "age", "", provider);

            var binder = new PrimitiveModelBinder();
            var actual = (int)binder.Bind(context);

            Assert.Equal(3, actual);
        }
コード例 #3
0
        public void Double()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(1033);
            var provider = new ValueProvider() { Parameters = { new Parameter("age", "3.5") } };
            var context = new ModelBinderContext(typeof(double), "age", "", provider);

            var binder = new PrimitiveModelBinder();
            var actual = (double)binder.Bind(context);

            Assert.Equal(3.5, actual);
        }