Esempio n. 1
0
        private async Task AssertCall(bool isGet, string path, string query, string body, string expectedResult)
        {
            var ctrlDiscoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RestfulController));
            var ctrls          = ctrlDiscoverer.GetControllers(null);

            var pathResolver = new PathResolver(ctrls);
            var httpCtx      = new Fakes.FakeHttpContext();

            if (isGet)
            {
                (httpCtx.Request as Fakes.FakeHttpRequest).WithPath(path);
            }
            else
            {
                (httpCtx.Request as Fakes.FakeHttpRequest).Method = "POST";
                (httpCtx.Request as Fakes.FakeHttpRequest).WithPath(path);
                (httpCtx.Request as Fakes.FakeHttpRequest).WriteBody(body);
            }
            foreach (var q in query.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                var parts = q.Split(":".ToCharArray());
                (httpCtx.Request as Fakes.FakeHttpRequest).AddQuery(parts[0], parts[1]);
            }

            var action        = pathResolver.ResolveAction(httpCtx.Request);
            var actionInvoker = new ActionInvoker(new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object), new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object), new JsonSerializer());
            await actionInvoker.Invoke(httpCtx, action);

            string result = httpCtx.Response.ReadBody();

            Assert.Equal(expectedResult, result);
        }
        private void AssertParameterOfTypeIsSupported <T>()
        {
            Type type;
            Type nullableArg;
            bool isNullable = false;

            if (typeof(T).GetTypeInfo().IsNullable(out nullableArg))
            {
                type       = nullableArg;
                isNullable = true;
            }
            else
            {
                type = typeof(T);
            }

            string actionName = "Action_" + type.Name + (isNullable ? "_Nullable" : "");

            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RouteSupportedParametersController));
            var ctrl       = discoverer.GetControllers(null).Single();
            var action     = ctrl.Actions.Single(x => x.Name == actionName.ToLower());

            var errors = new ParametersValidator().GetParametersErrors(action);

            Assert.Equal(isNullable, errors.Any());
        }
        public void ParameterDiscoverer_ParameterWithDefaultValue_CanBeDiscovered()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.ParametersController));
            var controller = discoverer.GetControllers(null).Single();
            var action     = controller.Actions.Single(x => x.Name == "toupper");

            Assert.True(action.Parameters.Single().HasDefaultValue);
            Assert.Equal("abc", action.Parameters.Single().DefaultValue);
        }
Esempio n. 4
0
        private void AssertErrorMessage(string errorMsg)
        {
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.Two), typeof(Controllers.TwoController));
            var ctrls      = discoverer.GetControllers(null);
            var validator  = GetCtrlValidator();
            var errors     = validator.GetValidationErrors(ctrls).ToArray();

            Assert.True(errors.Any(x => x.Contains(errorMsg)));
        }
Esempio n. 5
0
        public void Validators_GenericArrayAndListParameters_AreAcceptable()
        {
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrls      = discoverer.GetControllers(null);
            var validator  = GetCtrlValidator();
            var errors     = validator.GetValidationErrors(ctrls).ToArray();

            Assert.Empty(errors);
        }
Esempio n. 6
0
        public void Controller_NotRegisteredUser_ReturnsNullForUser()
        {
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.ComplexRootController));
            var ctrlCtx    = discoverer.GetControllers(null).Single();
            var builder    = new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object);
            var ctrl       = builder.Build(ctrlCtx, new Fakes.FakeHttpContext());

            Assert.Null(ctrl.User);
        }
Esempio n. 7
0
        public void Validators_GenericArrayAndListWithComplexParameters_AreNotAcceptable()
        {
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.InvalidCollectionsController));
            var ctrls      = discoverer.GetControllers(null);
            var validator  = GetCtrlValidator();
            var errors     = validator.GetValidationErrors(ctrls).ToArray();

            Assert.Equal(3, errors.Length);
            Assert.True(errors.Any(x => x.Contains("InvalidCollectionsGet1".ToLower())));
            Assert.True(errors.Any(x => x.Contains("InvalidCollectionsGet2".ToLower())));
            Assert.True(errors.Any(x => x.Contains("InvalidCollectionsGet3".ToLower())));
        }
Esempio n. 8
0
        private HttpResponse InvokeAndGetResponse()
        {
            var ctrl = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RawController))
                       .GetControllers(null)[0];
            var action          = ctrl.Actions[0];
            var serviceProvider = Fakes.FakeServiceProvider.GetServiceProvider();
            var ctrlBuilder     = new ControllerBuilder(serviceProvider);
            var actionInvoker   = new ActionInvoker(ctrlBuilder, new ModelBinderCollection(new JsonSerializer(), serviceProvider, new Fakes.FakeDefaultLiteApiOptionsRetriever()), new JsonSerializer());
            var httpCtx         = new Fakes.FakeHttpContext();

            actionInvoker.Invoke(httpCtx, action).Wait();
            return(httpCtx.Response);
        }
        private async Task AssertCanInvokeActionWithRouteParamOfType <T>(bool dateOnly = false)
        {
            Type type = typeof(T);

            object value = "";

            if (typeof(T) == typeof(DateTimeOffset))
            {
                value = "2017-10-28T09:51:17+07:00";
            }
            if (typeof(T) != typeof(string) && typeof(T) != typeof(DateTimeOffset))
            {
                value = Activator.CreateInstance(type);
            }
            if (typeof(T) == typeof(DateTime))
            {
                value = default(DateTime).ToString("yyyy-MM-dd HH:mm:ss");
                if (dateOnly)
                {
                    value = default(DateTime).ToString("yyyy-MM-dd");
                }
            }

            string actionName = "Action_" + type.Name;

            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RouteSupportedParametersController));
            var ctrl       = discoverer.GetControllers(null).Single();
            var action     = ctrl.Actions.Single(x => x.Name == actionName.ToLower());
            var serializer = new JsonSerializer();
            var invoker    = new ActionInvoker(new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object),
                                               new Services.ModelBinders.ModelBinderCollection(
                                                   serializer, Fakes.FakeServiceProvider.GetServiceProvider(), new Fakes.FakeDefaultLiteApiOptionsRetriever()), new JsonSerializer());
            var httpCtx = new Fakes.FakeHttpContext();

            httpCtx.SetActionContext(action);
            httpCtx.Request.Path = "/api/RouteSupportedParameters/" + actionName + "/" + value;
            await invoker.Invoke(httpCtx, action);

            string jsonResult = httpCtx.Response.ReadBody();
            object result     = serializer.Deserialize(jsonResult, type);

            if (typeof(T) == typeof(DateTime))
            {
                value = default(DateTime);
            }
            if (typeof(T) == typeof(DateTimeOffset))
            {
                value = DateTimeOffset.Parse(value as string);
            }
            Assert.Equal(value, result);
        }
Esempio n. 10
0
        public async Task CanInvokeFileUpload()
        {
            var httpCtx = GetHttpCtx();

            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.FileUploadController));
            var ctrlCtx    = discoverer.GetControllers(null).Single();
            var builder    = new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object);
            var invoker    = new ActionInvoker(builder, new Services.ModelBinders.ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object), new JsonSerializer());
            await invoker.Invoke(httpCtx, ctrlCtx.Actions.Single());

            string response = httpCtx.Response.ReadBody();

            Assert.Equal("2", response);
        }
Esempio n. 11
0
        private async Task AssertDownloadAction(string actionName)
        {
            var httpCtx    = new Fakes.FakeHttpContext();
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.FileDownloadController));
            var ctrlCtx    = discoverer.GetControllers(null).Single();
            var builder    = new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object);
            var invoker    = new ActionInvoker(builder, new Services.ModelBinders.ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object), new JsonSerializer());
            var action     = ctrlCtx.Actions.First(x => x.Name == actionName);
            await invoker.Invoke(httpCtx, action);

            string response = httpCtx.Response.ReadBody();

            Assert.Equal(actionName, response);
        }
Esempio n. 12
0
        public void ModelBinder_IEnumerableOfChars_CanParse()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single(x => x.Name == "get5");
            var mb      = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);
            var request = Fakes.FakeHttpRequest.WithGetMethod()
                          .AddQuery("data", "a", "b", "c", "d", "e");

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(1, parameters.Length);
            var collectionFromParams = (IEnumerable <char>)parameters[0];

            Assert.Equal(new[] { 'a', 'b', 'c', 'd', 'e' }.AsEnumerable(), collectionFromParams);
        }
Esempio n. 13
0
        public void ParameterDiscoverer_ExplicitParameterFromRoute_CanBeDiscovered()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RouteParamsController));
            var controller = discoverer.GetControllers(null).Single();
            var action     = controller.Actions.Single(x => x.Name == "plus2");

            Assert.Equal(3, action.Parameters.Length);
            var a = action.Parameters.First(x => x.Name == "a");
            var b = action.Parameters.First(x => x.Name == "b");
            var c = action.Parameters.First(x => x.Name == "c");

            Assert.Equal(ParameterSources.RouteSegment, a.ParameterSource);
            Assert.Equal(ParameterSources.RouteSegment, b.ParameterSource);
            Assert.Equal(ParameterSources.Query, c.ParameterSource);
        }
Esempio n. 14
0
        public void ModelBinder_ArrayOfStrings_CanParse()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single(x => x.Name == "get1");
            var mb      = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);
            var request = Fakes.FakeHttpRequest.WithGetMethod()
                          .AddQuery("data", "1", "1", "2", "5678", "abcd");

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(1, parameters.Length);
            var arrayFromParams = (string[])parameters[0];

            Assert.Equal(new[] { "1", "1", "2", "5678", "abcd" }, arrayFromParams);
        }
Esempio n. 15
0
        private void AssertCanParseSimpleParam <T>()
        {
            Type type;
            Type nullableArg;
            bool isNullable = false;

            if (typeof(T).GetTypeInfo().IsNullable(out nullableArg))
            {
                type       = nullableArg;
                isNullable = true;
            }
            else
            {
                type = typeof(T);
            }

            object value = "";

            if (typeof(T) == typeof(TestEnum))
            {
                value = TestEnum.TestValueTest;
            }
            else if (typeof(T) != typeof(string))
            {
                value = Activator.CreateInstance(type);
            }

            string      actionName = "Action_" + type.Name + (isNullable ? "_Nullable" : "");
            string      url        = "/ParameterParsing/" + actionName;
            HttpContext ctx        = new Fakes.FakeHttpContext();

            ctx.SetLiteApiOptions(LiteApiOptions.Default);
            var request = ctx.Request as Fakes.FakeHttpRequest;

            request.Path = url;
            request.AddQuery("p", value.ToString());
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.ParameterParsingController));
            var ctrl       = discoverer.GetControllers(null).Single();
            var action     = ctrl.Actions.Single(x => x.Name == actionName.ToLower());

            ctx.SetActionContext(action);

            ModelBinderCollection mb = new ModelBinderCollection(new JsonSerializer(), Fakes.FakeServiceProvider.GetServiceProvider(), new Fakes.FakeDefaultLiteApiOptionsRetriever());

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(value, parameters.Single());
        }
Esempio n. 16
0
        public async Task Action_WithRouteParametersWithCapitalLetters_CanBeInvoked()
        {
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RouteParamsController));
            var ctrl       = discoverer.GetControllers(null).Single();
            var action     = ctrl.Actions.Single(x => x.Name == "plus3");
            var serializer = new JsonSerializer();
            var invoker    = new ActionInvoker(new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object), new Services.ModelBinders.ModelBinderCollection(serializer, new Moq.Mock <IServiceProvider>().Object), new JsonSerializer());
            var httpCtx    = new Fakes.FakeHttpContext();

            httpCtx.Request.Path = "/api/v2/route/2/Plus3/4";
            await invoker.Invoke(httpCtx, action);

            string jsonResult = httpCtx.Response.ReadBody();
            object result     = serializer.Deserialize(jsonResult, typeof(int));

            Assert.Equal(6, result);
        }
Esempio n. 17
0
        private async Task AssertResponseHttpStatusCode(Contracts.Models.SupportedHttpMethods actionMethod, int expectedCode)
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.DifferentHttpMethodsController));
            var            controller        = discoverer.GetControllers(null).Single();
            IActionInvoker invoker           = new ActionInvoker(
                new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object),
                new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object)
                , new JsonSerializer()
                );
            var ctx = new Fakes.FakeHttpContext();

            ctx.Request.Method = actionMethod.ToString().ToLower();
            (ctx.Request as Fakes.FakeHttpRequest).AddQuery("a", "2").AddQuery("b", "3").AddQuery("c", "4").AddQuery("d", "5");
            await invoker.Invoke(ctx, controller.Actions.First(x => x.HttpMethod == actionMethod), null);

            Assert.Equal(expectedCode, ctx.Response.StatusCode);
        }
Esempio n. 18
0
        private async Task AssertResponseBody(Contracts.Models.SupportedHttpMethods actionMethod, string expectedResult)
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.DifferentHttpMethodsController));
            var            controller        = discoverer.GetControllers(null).Single();
            IActionInvoker invoker           = new ActionInvoker(
                new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object),
                new ModelBinderCollection(new JsonSerializer(), Fakes.FakeServiceProvider.GetServiceProvider(), new Fakes.FakeDefaultLiteApiOptionsRetriever())
                , new JsonSerializer());
            var ctx = new Fakes.FakeHttpContext();

            (ctx.Request as Fakes.FakeHttpRequest).AddQuery("a", "2").AddQuery("b", "3").AddQuery("c", "4").AddQuery("d", "5");
            await invoker.Invoke(ctx, controller.Actions.First(x => x.HttpMethod == actionMethod), null);

            string body = ctx.Response.ReadBody();

            Assert.Equal(expectedResult, body);
        }
Esempio n. 19
0
        private async Task AssertNotSetResponseCode(ClaimsPrincipal user, int expectedStatusCode)
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.SecureController2));
            var            controller        = discoverer.GetControllers(null).Single();
            IActionInvoker invoker           = new ActionInvoker(
                new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object),
                new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object)
                , new JsonSerializer());
            var httpCtx = new Fakes.FakeHttpContext();

            httpCtx.User = user;
            var action = controller.Actions.First(x => x.Name == "get14");
            await invoker.Invoke(httpCtx, action, null);

            int statusCode = httpCtx.Response.StatusCode;

            Assert.Equal(expectedStatusCode, statusCode);
        }
Esempio n. 20
0
        public void ModelBinder_ListOfNullableIntegers_CanParse()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single(x => x.Name == "get3");
            var mb      = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);
            var request = Fakes.FakeHttpRequest.WithGetMethod()
                          .AddQuery("data", "1", "", "1", "2", "5678");

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(1, parameters.Length);
            var listFromParams = (List <int?>)parameters[0];

            Assert.Equal(new List <int?>()
            {
                1, null, 1, 2, 5678
            }, listFromParams);
        }
Esempio n. 21
0
        public async Task CanGetParameterFromService()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.ServiceProvidedParameterController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single();
            var mb      = new ModelBinderCollection(new JsonSerializer(), GetServiceProvider(), new Fakes.FakeDefaultLiteApiOptionsRetriever());
            var httpCtx = new Fakes.FakeHttpContext();

            (httpCtx.Request as Fakes.FakeHttpRequest).AddQuery("i", "1");
            object[] parameters = mb.GetParameterValues(httpCtx.Request, action);
            Assert.Equal(2, parameters.Length);
            Assert.True(typeof(Controllers.IIncrementService).IsAssignableFrom(parameters[1].GetType()));

            ActionInvoker invoker = new ActionInvoker(new ControllerBuilder(GetServiceProvider()), mb, new JsonSerializer());
            await invoker.Invoke(httpCtx, action);

            var result = httpCtx.Response.ReadBody();

            Assert.Equal("2", result);
        }
Esempio n. 22
0
        public void ModelBinder_Dictionary_CanParse()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single(x => x.Name == "get6");
            var mb      = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);
            var request = Fakes.FakeHttpRequest.WithGetMethod()
                          .AddQuery("data.1", "a")
                          .AddQuery("data.2", "b")
                          .AddQuery("data.3", "c")
                          .AddQuery("data.4", "d");

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(1, parameters.Length);
            var collectionFromParams = (IDictionary <int, string>)parameters[0];
            var expected             = new Dictionary <int, string>
            {
                { 1, "a" }, { 2, "b" }, { 3, "c" }, { 4, "d" }
            } as IDictionary <int, string>;

            Assert.Equal(expected, collectionFromParams);
        }
Esempio n. 23
0
        public async Task ActionInvoker_MethodWithDefaultParam_CanBeInvoked()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.ParametersController));
            var            controller        = discoverer.GetControllers(null).Single();
            IActionInvoker invoker           = new ActionInvoker(
                new ControllerBuilder((new Moq.Mock <IServiceProvider>()).Object),
                new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object)
                , new JsonSerializer());
            var ctx = new Fakes.FakeHttpContext();
            await invoker.Invoke(ctx, controller.Actions.First(x => x.Name == "toupper"), null);

            string body = ctx.Response.ReadBody();

            Assert.Equal("\"ABC\"", body);

            ctx = new Fakes.FakeHttpContext();
            (ctx.Request as Fakes.FakeHttpRequest).AddQuery("a", "zxc");
            await invoker.Invoke(ctx, controller.Actions.First(x => x.Name == "toupper"), null);

            body = ctx.Response.ReadBody();
            Assert.Equal("\"ZXC\"", body);
        }
Esempio n. 24
0
        public void ModelBinder_ListOfNullableGuids_CanParse()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single(x => x.Name == "get4");
            var mb      = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);
            var request = Fakes.FakeHttpRequest.WithGetMethod()
                          .AddQuery("data", "b5477041395b47e8ad52605a42462936", "", "{aa2ec3ca-c3e7-4695-be0c-0c33e527515b}", "d29f0102-2c99-4033-ad65-672f6db25a23");

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(1, parameters.Length);
            var listFromParams = (List <Guid?>)parameters[0];
            var expected       = new List <Guid?>()
            {
                Guid.Parse("b5477041395b47e8ad52605a42462936"),
                null,
                Guid.Parse("{aa2ec3ca-c3e7-4695-be0c-0c33e527515b}"),
                Guid.Parse("d29f0102-2c99-4033-ad65-672f6db25a23")
            };

            Assert.Equal(expected, listFromParams);
        }
Esempio n. 25
0
        public void ModelBinder_ComplexFromBodyParameter_CanParse()
        {
            IControllerDiscoverer discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionController));
            var ctrl    = discoverer.GetControllers(null).Single();
            var action  = ctrl.Actions.Single(x => x.Name == "post7");
            var mb      = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);
            var request = Fakes.FakeHttpRequest.WithPostMethod()
                          .WriteBody(@"
[
    { ""Item1"": 0, ""Item2"": ""0"" },
    { ""Item1"": 1, ""Item2"": ""2"" },
    { ""Item1"": 3, ""Item2"": ""44"" },
]
");

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(1, parameters.Length);
            var collectionFromParams = (IEnumerable <Tuple <int, string> >)parameters[0];

            Tuple <int, string>[] expected = { Tuple.Create(0, "0"), Tuple.Create(1, "2"), Tuple.Create(3, "44") };
            Assert.Equal(expected, collectionFromParams);
        }
Esempio n. 26
0
        private void AssertCanParseSimpleParam <T>()
        {
            Type type;
            Type nullableArg;
            bool isNullable = false;

            if (typeof(T).GetTypeInfo().IsNullable(out nullableArg))
            {
                type       = nullableArg;
                isNullable = true;
            }
            else
            {
                type = typeof(T);
            }

            object value = "";

            if (typeof(T) != typeof(string))
            {
                value = Activator.CreateInstance(type);
            }

            string actionName = "Action_" + type.Name + (isNullable ? "_Nullable" : "");
            string url        = "/ParameterParsing/" + actionName;
            var    request    = Fakes.FakeHttpRequest.WithGetMethod();

            request.Path = url;
            request.AddQuery("p", value.ToString());
            var discoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.ParameterParsingController));
            var ctrl       = discoverer.GetControllers(null).Single();
            var action     = ctrl.Actions.Single(x => x.Name == actionName.ToLower());

            ModelBinderCollection mb = new ModelBinderCollection(new JsonSerializer(), new Moq.Mock <IServiceProvider>().Object);

            object[] parameters = mb.GetParameterValues(request, action);
            Assert.Equal(value, parameters.Single());
        }
        private ActionContext GetActionContext(string name)
        {
            var ctrlDiscoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.CollectionsQueryModelBinderController));

            return(ctrlDiscoverer.GetControllers(null).Single().Actions.First(x => x.Name.ToLower() == name.ToLower()));
        }
        private ActionContext GetActionContext()
        {
            var ctrlDiscoverer = new Fakes.FakeLimitedControllerDiscoverer(typeof(Controllers.RouteParamsController));

            return(ctrlDiscoverer.GetControllers(null).Single().Actions.First());
        }