public void RuntimeState_All_Routes(RuntimeLevel level)
        {
            PreviewRoutes routes    = GetRoutes(level);
            var           endpoints = new TestRouteBuilder();

            routes.CreateRoutes(endpoints);

            Assert.AreEqual(2, endpoints.DataSources.Count);
            EndpointDataSource route = endpoints.DataSources.First();

            Assert.AreEqual(2, route.Endpoints.Count);

            var endpoint0 = (RouteEndpoint)route.Endpoints[0];

            Assert.AreEqual($"{routes.GetPreviewHubRoute()}/negotiate", endpoint0.RoutePattern.RawText);
            var endpoint1 = (RouteEndpoint)route.Endpoints[1];

            Assert.AreEqual($"{routes.GetPreviewHubRoute()}", endpoint1.RoutePattern.RawText);

            var endpoint3             = (RouteEndpoint)endpoints.DataSources.Last().Endpoints[0];
            var previewControllerName = ControllerExtensions.GetControllerName <PreviewController>();

            Assert.AreEqual($"umbraco/{previewControllerName.ToLowerInvariant()}/{{action}}/{{id?}}", endpoint3.RoutePattern.RawText);
            Assert.AreEqual(Constants.Web.Mvc.BackOfficeArea, endpoint3.RoutePattern.Defaults["area"]);
            Assert.AreEqual("Index", endpoint3.RoutePattern.Defaults[ActionToken]);
            Assert.AreEqual(previewControllerName, endpoint3.RoutePattern.Defaults[ControllerToken]);
            Assert.AreEqual(endpoint3.RoutePattern.Defaults["area"], typeof(PreviewController).GetCustomAttribute <AreaAttribute>(false).RouteValue);
        }
Esempio n. 2
0
        public static IUmbracoEndpointBuilderContext UseUmbracoPreviewEndpoints(this IUmbracoEndpointBuilderContext app)
        {
            PreviewRoutes previewRoutes = app.ApplicationServices.GetRequiredService <PreviewRoutes>();

            previewRoutes.CreateRoutes(app.EndpointRouteBuilder);

            return(app);
        }
        public void RuntimeState_No_Routes(RuntimeLevel level)
        {
            PreviewRoutes routes    = GetRoutes(level);
            var           endpoints = new TestRouteBuilder();

            routes.CreateRoutes(endpoints);

            Assert.AreEqual(0, endpoints.DataSources.Count);
        }
Esempio n. 4
0
    private PreviewRoutes GetRoutes(RuntimeLevel level)
    {
        var globalSettings = new GlobalSettings();
        var routes         = new PreviewRoutes(
            Options.Create(globalSettings),
            Mock.Of <IHostingEnvironment>(x =>
                                          x.ToAbsolute(It.IsAny <string>()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty),
            Mock.Of <IRuntimeState>(x => x.Level == level));

        return(routes);
    }
        public BackOfficeServerVariables(
            LinkGenerator linkGenerator,
            IRuntimeState runtimeState,
            UmbracoFeatures features,
            IOptionsMonitor <GlobalSettings> globalSettings,
            IUmbracoVersion umbracoVersion,
            IOptionsMonitor <ContentSettings> contentSettings,
            IHttpContextAccessor httpContextAccessor,
            TreeCollection treeCollection,
            IHostingEnvironment hostingEnvironment,
            IOptionsMonitor <RuntimeSettings> runtimeSettings,
            IOptionsMonitor <SecuritySettings> securitySettings,
            IRuntimeMinifier runtimeMinifier,
            IBackOfficeExternalLoginProviders externalLogins,
            IImageUrlGenerator imageUrlGenerator,
            PreviewRoutes previewRoutes,
            IEmailSender emailSender,
            IOptionsMonitor <MemberPasswordConfigurationSettings> memberPasswordConfigurationSettings,
            IOptionsMonitor <DataTypesSettings> dataTypesSettings)
        {
            _linkGenerator       = linkGenerator;
            _runtimeState        = runtimeState;
            _features            = features;
            _globalSettings      = globalSettings.CurrentValue;
            _umbracoVersion      = umbracoVersion;
            _contentSettings     = contentSettings.CurrentValue ?? throw new ArgumentNullException(nameof(contentSettings));
            _httpContextAccessor = httpContextAccessor;
            _treeCollection      = treeCollection ?? throw new ArgumentNullException(nameof(treeCollection));
            _hostingEnvironment  = hostingEnvironment;
            _runtimeSettings     = runtimeSettings.CurrentValue;
            _securitySettings    = securitySettings.CurrentValue;
            _runtimeMinifier     = runtimeMinifier;
            _externalLogins      = externalLogins;
            _imageUrlGenerator   = imageUrlGenerator;
            _previewRoutes       = previewRoutes;
            _emailSender         = emailSender;
            _memberPasswordConfigurationSettings = memberPasswordConfigurationSettings.CurrentValue;
            _dataTypesSettings = dataTypesSettings.CurrentValue;

            globalSettings.OnChange(x => _globalSettings       = x);
            contentSettings.OnChange(x => _contentSettings     = x);
            runtimeSettings.OnChange(x => _runtimeSettings     = x);
            securitySettings.OnChange(x => _securitySettings   = x);
            dataTypesSettings.OnChange(x => _dataTypesSettings = x);
            memberPasswordConfigurationSettings.OnChange(x => _memberPasswordConfigurationSettings = x);
        }
 public BackOfficeServerVariables(
     LinkGenerator linkGenerator,
     IRuntimeState runtimeState,
     UmbracoFeatures features,
     IOptionsMonitor <GlobalSettings> globalSettings,
     IUmbracoVersion umbracoVersion,
     IOptionsMonitor <ContentSettings> contentSettings,
     IHttpContextAccessor httpContextAccessor,
     TreeCollection treeCollection,
     IHostingEnvironment hostingEnvironment,
     IOptionsMonitor <RuntimeSettings> runtimeSettings,
     IOptionsMonitor <SecuritySettings> securitySettings,
     IRuntimeMinifier runtimeMinifier,
     IBackOfficeExternalLoginProviders externalLogins,
     IImageUrlGenerator imageUrlGenerator,
     PreviewRoutes previewRoutes,
     IEmailSender emailSender,
     IOptionsMonitor <MemberPasswordConfigurationSettings> memberPasswordConfigurationSettings)
     : this(
         linkGenerator,
         runtimeState,
         features,
         globalSettings,
         umbracoVersion,
         contentSettings,
         httpContextAccessor,
         treeCollection,
         hostingEnvironment,
         runtimeSettings,
         securitySettings,
         runtimeMinifier,
         externalLogins,
         imageUrlGenerator,
         previewRoutes,
         emailSender,
         memberPasswordConfigurationSettings,
         StaticServiceProvider.Instance.GetRequiredService <IOptionsMonitor <DataTypesSettings> >())
 {
 }