public void CanBindCompleteTestObject()
        {
            var data = new Dictionary <string, string>()
            {
                { "intvalue", "1" },
                { "stringvalue", "bar" },
                { "datetimevalue", "2014-01-01" }
            };

            var route   = new RouteInvocation(null, null, data);
            var request = new Mock <IRequest>();

            request.SetupGet(x => x.Query).Returns(new Dictionary <string, string[]>());

            var method = this.GetType().GetMethod("testBindingMethod",
                                                  BindingFlags.NonPublic | BindingFlags.Instance);

            var result = binder.GetArguments(route, request.Object, method);
            var obj    = result.Single() as TestObject;

            Assert.IsNotNull(obj);
            Assert.AreEqual(1, obj.IntValue);
            Assert.AreEqual("bar", obj.StringValue);
            Assert.AreEqual(new DateTime(2014, 1, 1), obj.DateTimeValue);
        }
示例#2
0
        public void CanBindRouteData()
        {
            var data = new Dictionary <string, string>()
            {
                { "one", "foo" },
                { "two", "bar" }
            };

            var route   = new RouteInvocation(null, null, data);
            var request = new Mock <IRequest>();

            request.SetupGet(x => x.Query).Returns(new Dictionary <string, string[]>());

            var method = this.GetType().GetMethod("methodWithOptionalParameters",
                                                  BindingFlags.NonPublic | BindingFlags.Instance);

            var result = binder.GetArguments(route, request.Object, method);

            CollectionAssert.AreEqual(new object[] { "foo", "bar", "baz" }, result);
        }