/// <summary> /// Checks if the URL will be ignored in the RouteTable /// </summary> /// <param name="url"></param> /// <returns></returns> /// <remarks> /// MVCContrib has a similar one but is faulty: /// http://mvccontrib.codeplex.com/workitem/7173 /// </remarks> public static bool ShouldIgnoreRoute(this string url) { var http = new FakeHttpContextFactory(url); var r = RouteTable.Routes.GetRouteData(http.HttpContext); if (r == null) return false; return (r.RouteHandler is StopRoutingHandler); }
/// <summary> /// Checks if the URL will be ignored in the RouteTable /// </summary> /// <param name="url"></param> /// <returns></returns> /// <remarks> /// MVCContrib has a similar one but is faulty: /// http://mvccontrib.codeplex.com/workitem/7173 /// </remarks> public static bool ShouldIgnoreRoute(this string url) { var http = new FakeHttpContextFactory(url); var r = RouteTable.Routes.GetRouteData(http.HttpContext); if (r == null) { return(false); } return(r.RouteHandler is StopRoutingHandler); }
/// <summary> /// Return the route data for the url based on a mocked context /// </summary> /// <param name="routes"></param> /// <param name="requestUrl"></param> /// <returns></returns> public static RouteData GetDataForRoute(this RouteCollection routes, string requestUrl) { var context = new FakeHttpContextFactory(requestUrl); return(routes.GetDataForRoute(context.HttpContext)); }
protected Umbraco.Cms.Web.Context.IBackOfficeRequestContext GetBackOfficeRequestContext(Uri uri) { var httpContext = new FakeHttpContextFactory(uri).HttpContext; return new FakeBackOfficeRequestContext(UmbracoApplicationContext, new DefaultRoutingEngine(UmbracoApplicationContext, httpContext)); }
public override void SetUp() { var ctx = new FakeHttpContextFactory("/"); CacheProvider = new PerHttpRequestCacheProvider(ctx.HttpContext); }
public void BackOfficeRouting_Ensure_Plugin_Tree_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentTree = new Stubs.Trees.ContentTreeController(new FakeBackOfficeRequestContext()); var contentControllerName = UmbracoController.GetControllerName(contentTree.GetType()); var contentControllerId = UmbracoController.GetControllerId<TreeAttribute>(contentTree.GetType()); var mediaTree = new Stubs.Trees.MediaTreeController(new FakeBackOfficeRequestContext()); var mediaTreeControllerName = UmbracoController.GetControllerName(mediaTree.GetType()); var mediaTreeControllerId = UmbracoController.GetControllerId<TreeAttribute>(mediaTree.GetType()); const string action = "Index"; var defaultId = HiveId.Empty; const int customId = 123; const string area = "TestPackage"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = defaultId, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var mediaTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, mediaTreeControllerName, new RouteValueDictionary(new { area, id = defaultId, treeId = mediaTreeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentTreeCustomUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = customId, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var mediaTreeCustomUrl = UrlHelper.GenerateUrl(null, action, mediaTreeControllerName, new RouteValueDictionary(new { area, id = customId, treeId = mediaTreeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Trees/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentTreeDefaultUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Trees/{0}/{1}", mediaTreeControllerId.ToString("N"), mediaTreeControllerName), mediaTreeDefaultUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Trees/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, action, customId), contentTreeCustomUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Trees/{0}/{1}/{2}/{3}", mediaTreeControllerId.ToString("N"), mediaTreeControllerName, action, customId), mediaTreeCustomUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}", contentControllerName), contentTreeDefaultUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}", mediaTreeControllerName), mediaTreeDefaultUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}/{1}/{2}", contentControllerName, action, customId), contentTreeCustomUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}/{1}/{2}", mediaTreeControllerName, action, customId), mediaTreeCustomUrl); }
public void BackOfficeRouting_Ensure_Default_Tree_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentTree = new ContentTreeController(new FakeBackOfficeRequestContext()); var contentControllerName = UmbracoController.GetControllerName(contentTree.GetType()); var contentControllerId = UmbracoController.GetControllerId<TreeAttribute>(contentTree.GetType()); var dataTypeTree = new DataTypeTreeController(new FakeBackOfficeRequestContext()); var dataTypeControllerName = UmbracoController.GetControllerName(dataTypeTree.GetType()); var dataTypeControllerId = UmbracoController.GetControllerId<TreeAttribute>(dataTypeTree.GetType()); const string action = "Index"; var customId = HiveId.ConvertIntToGuid(123); const string area = "Umbraco"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = HiveId.Empty, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeTreeDefaultUrl = UrlHelper.GenerateUrl(null, action, dataTypeControllerName, new RouteValueDictionary(new { area, id = HiveId.Empty, treeId = dataTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentTreeCustomUrl = UrlHelper.GenerateUrl(null, action, contentControllerName, new RouteValueDictionary(new { area, id = customId, treeId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeTreeCustomUrl = UrlHelper.GenerateUrl(null, action, dataTypeControllerName, new RouteValueDictionary(new { area, id = customId, treeId = dataTypeControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert Assert.AreEqual(string.Format("/Umbraco/Trees/{0}", contentControllerName), contentTreeDefaultUrl); Assert.AreEqual(string.Format("/Umbraco/Trees/{0}", dataTypeControllerName), dataTypeTreeDefaultUrl); Assert.AreEqual(string.Format("/Umbraco/Trees/{0}/{1}/{2}", contentControllerName, action, HttpUtility.UrlEncode(customId.ToString())), contentTreeCustomUrl); Assert.AreEqual(string.Format("/Umbraco/Trees/{0}/{1}/{2}", dataTypeControllerName, action, HttpUtility.UrlEncode(customId.ToString())), dataTypeTreeCustomUrl); }
public void BackOfficeRouting_Ensure_Plugin_Editor_Url_Structures() { //Arrange var context = new FakeHttpContextFactory("~/empty", new RouteData()); var contentEditor = new Stubs.Editors.ContentEditorController(new FakeBackOfficeRequestContext()); var contentControllerName = UmbracoController.GetControllerName(contentEditor.GetType()); var contentControllerId = UmbracoController.GetControllerId<EditorAttribute>(contentEditor.GetType()); var mediaEditorController = new Stubs.Editors.MediaEditorController(new FakeBackOfficeRequestContext()); var mediaControllerName = UmbracoController.GetControllerName(mediaEditorController.GetType()); var mediaControllerId = UmbracoController.GetControllerId<EditorAttribute>(mediaEditorController.GetType()); const string customAction = "Index"; const string defaultAction = "Dashboard"; const int id = -1; const string area = "TestPackage"; //Act //ensure the area is passed in because we're matchin a URL in an area, otherwise it will not work var contentEditorDefaultUrl = UrlHelper.GenerateUrl(null, defaultAction, contentControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeEditorDefaulturl = UrlHelper.GenerateUrl(null, defaultAction, mediaControllerName, new RouteValueDictionary(new { area, id = UrlParameter.Optional, editorId = mediaControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var contentEditorCustomUrl = UrlHelper.GenerateUrl(null, customAction, contentControllerName, new RouteValueDictionary(new { area, id, editorId = contentControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); var dataTypeEditorCustomurl = UrlHelper.GenerateUrl(null, customAction, mediaControllerName, new RouteValueDictionary(new { area, id, editorId = mediaControllerId.ToString("N") }), RouteTable.Routes, context.RequestContext, true); //Assert //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentEditorDefaultUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}", mediaControllerId.ToString("N"), mediaControllerName), dataTypeEditorDefaulturl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, customAction, id), contentEditorCustomUrl); //Assert.AreEqual(string.Format("/Umbraco/TestPackage/Editors/{0}/{1}/{2}/{3}", mediaControllerId.ToString("N"), mediaControllerName, customAction, id), dataTypeEditorCustomurl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}", contentControllerName), contentEditorDefaultUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}", mediaControllerName), dataTypeEditorDefaulturl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl); Assert.AreEqual(string.Format("/Umbraco/TestPackage/{0}/{1}/{2}", mediaControllerName, customAction, id), dataTypeEditorCustomurl); }
public void FrontEndRouting_Umbraco_Route_User_Defined_Controller_Action() { var http = new FakeHttpContextFactory("~/home-page"); var content = new Content(new HiveId(Guid.NewGuid()), new List<TypedAttribute>()); content.CurrentTemplate = new Template(new HiveId(new Uri("storage://templates"), "", new HiveIdValue("home-page.cshtml"))); content.ContentType = new EntitySchema("customUmbraco"); RenderModelFactory.AddMatchingUrlForContent("/home-page", content); var data = RouteTable.Routes.GetDataForRoute(http.HttpContext); Assert.AreEqual(typeof(RenderRouteHandler), data.RouteHandler.GetType()); var handler = (RenderRouteHandler)data.RouteHandler; handler.GetHandlerForRoute(http.RequestContext, RenderModelFactory.Create(http.HttpContext, http.HttpContext.Request.RawUrl)); Assert.AreEqual("CustomUmbraco", data.Values["controller"].ToString()); Assert.AreEqual("HomePage", data.Values["action"].ToString()); }
private UrlHelper CreateHelper() { var http = new FakeHttpContextFactory("~/test"); var url = new UrlHelper(http.RequestContext); return url; }
/// <summary> /// Return the route data for the url based on a mocked context /// </summary> /// <param name="routes"></param> /// <param name="requestUrl"></param> /// <returns></returns> public static RouteData GetDataForRoute(this RouteCollection routes, string requestUrl) { var context = new FakeHttpContextFactory(requestUrl); return routes.GetDataForRoute(context.HttpContext); }
private HiveId ExecuteBinding(IValueProvider form, RouteData routeData, out ModelBindingContext bindingContext, out ControllerContext controllerContext) { var modelBinder = new HiveIdModelBinder(); var httpContextFactory = new FakeHttpContextFactory("~/Umbraco/Editors/ContentEditor/Edit/1", routeData); var fakeFrameworkContext = new FakeFrameworkContext(); var hive = FakeHiveCmsManager.New(fakeFrameworkContext); var appContext = new FakeUmbracoApplicationContext(hive); var resolverContext = new MockedMapResolverContext(fakeFrameworkContext, hive, new MockedPropertyEditorFactory(appContext), new MockedParameterEditorFactory()); var webmModelMapper = new CmsModelMapper(resolverContext); fakeFrameworkContext.SetTypeMappers(new FakeTypeMapperCollection(new AbstractMappingEngine[] { webmModelMapper, new FrameworkModelMapper(fakeFrameworkContext) })); var umbracoApplicationContext = new FakeUmbracoApplicationContext(hive); controllerContext = new ControllerContext( httpContextFactory.RequestContext, new ContentEditorController(new FakeBackOfficeRequestContext(umbracoApplicationContext))); //put both the form and route values in the value provider var routeDataValueProvider = new RouteDataValueProvider(controllerContext); var values = new ValueProviderCollection(new List<IValueProvider>() { form, routeDataValueProvider }); bindingContext = GetBindingContext(new HiveId(1), values); //do the binding! var model = modelBinder.BindModel(controllerContext, bindingContext); //assert! Assert.That(model, Is.InstanceOf<HiveId>(), "Model isn't a HiveId"); var boundModel = (HiveId)model; return boundModel; }