/// <summary> /// Initializes a new instance of the <see cref="TaxonomyUrlParamsMapper" /> class. /// </summary> /// <param name="controller">The controller.</param> /// <param name="taxonUrlEvaluator">The taxon URL evaluator.</param> /// <param name="actionName">Name of the action.</param> public TaxonomyUrlParamsMapper(ControllerBase controller, TaxonUrlMapper taxonUrlEvaluator, string actionName = TaxonomyUrlParamsMapper.DefaultActionName) : base(controller) { this.actionName = actionName; this.taxonUrlEvaluator = taxonUrlEvaluator; this.actionMethod = controller.GetType().GetMethod(this.actionName, BindingFlags.Instance | BindingFlags.Public); }
public void Return_False_When_Params_Are_Empty_Test() { var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter()); ITaxon taxon; int pageIndex; bool hasMatch = taxonUrlMapper.TryMatch(new string[1], out taxon, out pageIndex); Assert.IsFalse(hasMatch); }
public void Return_False_When_Params_Has_Less_Then_Tree_Items() { var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter()); ITaxon taxon; int pageIndex; var urlParams = new[] { "-in-tags", "tag" }; bool hasMatch = taxonUrlMapper.TryMatch(urlParams, out taxon, out pageIndex); Assert.IsFalse(hasMatch); }
public void Return_False_With_Valid_HierarchicalTaxon_With_Deep_Hierarchy_PageIndex() { ITaxon taxon; int pageIndex; string validTaxonUrl = "-in-category/category/cat1/cat11/cat22/cat33/cat44"; string requestedUrl = "-in-category/category/cat1/cat11/cat22/cat33/cat44/2"; var urlParams = requestedUrl.Split('/'); var tagTaxon = new HierarchicalTaxon(); var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url == validTaxonUrl ? tagTaxon : null)); bool hasMatch = taxonUrlMapper.TryMatch(urlParams, out taxon, out pageIndex); Assert.IsFalse(hasMatch); }
public void Return_False_With_Valid_Taxon_With_Page() { ITaxon taxon; int pageIndex; string validUrlPattern = "-in-tags/tag/tag1"; string requestedUrl = "-in-tags/tag/tag1/page"; var urlParams = requestedUrl.Split('/'); var tagTaxon = new FlatTaxon(); var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url.Contains(validUrlPattern) ? tagTaxon : null)); bool hasMatch = taxonUrlMapper.TryMatch(urlParams, out taxon, out pageIndex); Assert.IsFalse(hasMatch); Assert.IsTrue(pageIndex == 0); }
public void Return_True_With_Valid_Taxon_And_PageIndex_Equals_To_3() { ITaxon taxon; int pageIndex; string urlWithTaxon = "-in-tags/tag/tag1"; string urlPattern = "-in-tags/tag/tag1/3"; var urlParams = urlPattern.Split('/'); var tagTaxon = new FlatTaxon(); var taxonUrlMapper = new TaxonUrlMapper(new MockedTaxonUrlEvaluatorAdapter(url => url.Contains(urlWithTaxon) ? tagTaxon : null)); bool hasMatch = taxonUrlMapper.TryMatch(urlParams, out taxon, out pageIndex); Assert.IsTrue(hasMatch); Assert.IsTrue(pageIndex == 3); }
/// <summary> /// Initializes a new instance of the <see cref="TaxonomyUrlParamsMapper" /> class. /// </summary> /// <param name="controller">The controller.</param> /// <param name="taxonUrlEvaluator">The taxon URL evaluator.</param> /// <param name="actionName">Name of the action.</param> public TaxonomyUrlParamsMapper(ControllerBase controller, TaxonUrlMapper taxonUrlEvaluator, string actionName = TaxonomyUrlParamsMapper.DefaultActionName) : base(controller) { this.actionName = actionName; this.taxonUrlEvaluator = taxonUrlEvaluator; this.actionMethod = controller.GetType().GetMethod(this.actionName, BindingFlags.Instance | BindingFlags.Public); }