public void TestEditorScenario(string path, string controllerExpected, bool editor = false, bool typespecified = false, bool modeView = false, bool jsonRequest = false) { var routeContext = new RouteContext(new MockHttpContext("http://www.test.com/header2/" + path + (typespecified ? "?$type=LyniconANC.Test.Models.HeaderContent2" : "") + (modeView ? "?$mode=view" : ""))); var rd = new RouteData(); rd.Values.Add("_0", path); rd.Values.Add("controller", "Header2"); rd.Values.Add("action", "Index"); routeContext.RouteData = rd; if (jsonRequest) { routeContext.HttpContext.Request.Headers.Add("Accept", new StringValues("application/json")); } var router = new DataFetchingRouter <HeaderContent2>(new MockRouter(), writePermission: (editor ? new ContentPermission((roles, data) => true) : null)); router.RouteAsync(routeContext).Wait(); if (controllerExpected == null) { Assert.Null(routeContext.Handler); } else { Assert.NotNull(routeContext.Handler); Assert.Equal(controllerExpected, routeContext.RouteData.Values["controller"]); } }
public static void AddTestDataRoute <T>(this RouteCollection routes, string name, string template, object defaults) where T : class, new() { IOptions <RouteOptions> routeOpts = Options.Create <RouteOptions>(new RouteOptions()); var constraintResolver = new DefaultInlineConstraintResolver(routeOpts); var dataFetchingRouter = new DataFetchingRouter <T>(new MockRouter()); var dataRoute = new DataRoute( dataFetchingRouter, name, template, new RouteValueDictionary(defaults), new RouteValueDictionary(null), new RouteValueDictionary(null), constraintResolver); routes.Add(dataRoute); }
public static void AddTestDataRoute <T>(this RouteCollection routes, string name, string template, object defaults, ContentPermission writePermission = null, DiversionStrategy divertOverride = null) where T : class, new() { IOptions <RouteOptions> routeOpts = Options.Create <RouteOptions>(new RouteOptions()); var constraintResolver = new DefaultInlineConstraintResolver(routeOpts); var dataFetchingRouter = new DataFetchingRouter <T>(new MockRouter(), false, writePermission, divertOverride); var dataRoute = new DataRoute( dataFetchingRouter, name, template, new RouteValueDictionary(defaults), new RouteValueDictionary(null), new RouteValueDictionary(null), constraintResolver); routes.Add(dataRoute); }