Пример #1
0
        private IUrlParamsMapper GetInferredTaxonFilterQueryParamsMapper(ControllerBase controller, string actionName)
        {
            IUrlParamsMapper result = null;

            var actionDescriptor = new ReflectedControllerDescriptor(controller.GetType()).FindAction(controller.ControllerContext, actionName);

            if (actionDescriptor == null || actionDescriptor.GetParameters().Length == 0)
            {
                return(null);
            }

            var queryParams = controller.ControllerContext.RequestContext.HttpContext.Request.QueryString;

            if (actionDescriptor.GetParameters()[0].ParameterType == typeof(ITaxon) && queryParams.Count == 3)
            {
                if (queryParams.Keys.Contains("taxonomy"))
                {
                    result = new TaxonomyUrlParamsMapper(controller, new TaxonUrlMapper(new TaxonUrlEvaluatorAdapter()));
                }
            }

            return(result);
        }
Пример #2
0
        public void Taxonomy_UrlParams_Mapper_Test_With_PageIndex_With_Incorrect_Route_Data()
        {
            string urlPattern = "-in-tags/tag/tag1/3";

            string requestRouteData = "-in-tags/tag/tag1/asdasd";

            var urlParams = requestRouteData.Split('/');

            var controller = new TestableController();
            controller.ControllerContext = new ControllerContext();

            var tagTaxon = new FlatTaxon();

            var taxonomyUrlParamsMapper = new TaxonomyUrlParamsMapper(
                                          controller,
                                          new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url.Contains(urlPattern) ? tagTaxon : null)));

            taxonomyUrlParamsMapper.ResolveUrlParams(urlParams, controller.ControllerContext.RequestContext);

            Assert.IsFalse(controller.ControllerContext.RequestContext.RouteData.Values["action"] == "ListByTaxon");
        }
Пример #3
0
        public void Taxonomy_UrlParams_Mapper_Test_With_PageIndex()
        {
            string urlPattern = "-in-tags/tag/tag1/3";

            var urlParams = urlPattern.Split('/');

            var controller = new TestableController();
            controller.ControllerContext = new ControllerContext();

            var tagTaxon = new FlatTaxon();

            var taxonomyUrlParamsMapper = new TaxonomyUrlParamsMapper(
                                          controller,
                                          new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url.Contains(urlPattern) ? tagTaxon : null)));

            taxonomyUrlParamsMapper.ResolveUrlParams(urlParams, controller.ControllerContext.RequestContext);

            Assert.IsTrue(controller.ControllerContext.RequestContext.RouteData.Values["action"] == "ListByTaxon");
            Assert.IsTrue(controller.ControllerContext.RequestContext.RouteData.Values["taxon"] == tagTaxon);
            Assert.IsTrue(((int)controller.ControllerContext.RequestContext.RouteData.Values["page"]) == 3);
        }