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 = RebelController.GetControllerName(contentEditor.GetType()); var contentControllerId = RebelController.GetControllerId <EditorAttribute>(contentEditor.GetType()); var mediaEditorController = new Stubs.Editors.MediaEditorController(new FakeBackOfficeRequestContext()); var mediaControllerName = RebelController.GetControllerName(mediaEditorController.GetType()); var mediaControllerId = RebelController.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("/Rebel/TestPackage/Editors/{0}/{1}", contentControllerId.ToString("N"), contentControllerName), contentEditorDefaultUrl); //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}", mediaControllerId.ToString("N"), mediaControllerName), dataTypeEditorDefaulturl); //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}/{2}/{3}", contentControllerId.ToString("N"), contentControllerName, customAction, id), contentEditorCustomUrl); //Assert.AreEqual(string.Format("/Rebel/TestPackage/Editors/{0}/{1}/{2}/{3}", mediaControllerId.ToString("N"), mediaControllerName, customAction, id), dataTypeEditorCustomurl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", contentControllerName), contentEditorDefaultUrl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}", mediaControllerName), dataTypeEditorDefaulturl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", contentControllerName, customAction, id), contentEditorCustomUrl); Assert.AreEqual(string.Format("/Rebel/TestPackage/{0}/{1}/{2}", mediaControllerName, customAction, id), dataTypeEditorCustomurl); }
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); }