public void RuntimeState_No_Routes(RuntimeLevel level) { BackOfficeAreaRoutes routes = GetBackOfficeAreaRoutes(level); var endpoints = new TestRouteBuilder(); routes.CreateRoutes(endpoints); Assert.AreEqual(0, endpoints.DataSources.Count); }
private BackOfficeAreaRoutes GetBackOfficeAreaRoutes(RuntimeLevel level) { var globalSettings = new GlobalSettings(); var routes = new BackOfficeAreaRoutes( Options.Create(globalSettings), Mock.Of <IHostingEnvironment>(x => x.ToAbsolute(It.IsAny <string>()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty), Mock.Of <IRuntimeState>(x => x.Level == level), new UmbracoApiControllerTypeCollection(() => new[] { typeof(Testing1Controller) })); return(routes); }
public static IUmbracoEndpointBuilderContext UseBackOfficeEndpoints(this IUmbracoEndpointBuilderContext app) { // NOTE: This method will have been called after UseRouting, UseAuthentication, UseAuthorization if (app == null) { throw new ArgumentNullException(nameof(app)); } if (!app.RuntimeState.UmbracoCanBoot()) { return(app); } BackOfficeAreaRoutes backOfficeRoutes = app.ApplicationServices.GetRequiredService <BackOfficeAreaRoutes>(); backOfficeRoutes.CreateRoutes(app.EndpointRouteBuilder); app.UseUmbracoRuntimeMinificationEndpoints(); app.UseUmbracoPreviewEndpoints(); return(app); }
public void RuntimeState_All_Routes(RuntimeLevel level) { BackOfficeAreaRoutes routes = GetBackOfficeAreaRoutes(level); var endpoints = new TestRouteBuilder(); routes.CreateRoutes(endpoints); Assert.AreEqual(1, endpoints.DataSources.Count); EndpointDataSource route = endpoints.DataSources.First(); Assert.AreEqual(3, route.Endpoints.Count); AssertMinimalBackOfficeRoutes(route); var endpoint4 = (RouteEndpoint)route.Endpoints[2]; string apiControllerName = ControllerExtensions.GetControllerName <Testing1Controller>(); Assert.AreEqual($"umbraco/backoffice/api/{apiControllerName.ToLowerInvariant()}/{{action}}/{{id?}}", endpoint4.RoutePattern.RawText); Assert.IsFalse(endpoint4.RoutePattern.Defaults.ContainsKey(AreaToken)); Assert.IsFalse(endpoint4.RoutePattern.Defaults.ContainsKey(ActionToken)); Assert.AreEqual(apiControllerName, endpoint4.RoutePattern.Defaults[ControllerToken]); }