当前位置: 首页>>代码示例>>C#>>正文


C# UmbracoContext.Initialize方法代码示例

本文整理汇总了C#中Umbraco.Web.UmbracoContext.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# UmbracoContext.Initialize方法的具体用法?C# UmbracoContext.Initialize怎么用?C# UmbracoContext.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Umbraco.Web.UmbracoContext的用法示例。


在下文中一共展示了UmbracoContext.Initialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetUmbracoRouteValues_Returns_Default

        public void GetUmbracoRouteValues_Returns_Default()
        {
            var router = new UmbracoRouter(Mock.Of<IRouter>());
            var httpCtxAccessor = new Mock<IHttpContextAccessor>();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(context => context.Request).Returns(Mock.Of<HttpRequest>());
            httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
            var umbCtx = new UmbracoContext(httpCtxAccessor.Object);            
            var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty<IUrlProvider>());
            var routingCtx = new RoutingContext(Enumerable.Empty<IContentFinder>(), Mock.Of<ILastChanceContentFinder>(), urlProvider);
            var pcr = new PublishedContentRequest(routingCtx, Mock.Of<ITemplateService>(), Mock.Of<ILoggerFactory>(), httpCtxAccessor.Object)
            {
                PublishedContent = new PublishedContent()
            };
            umbCtx.Initialize(pcr);
            var actionDescriptors = new Mock<IActionDescriptorsCollectionProvider>();
            actionDescriptors.Setup(provider => provider.ActionDescriptors).Returns(new ActionDescriptorsCollection(new List<ActionDescriptor>(), 0));

            var result = router.GetUmbracoRouteValues(umbCtx, new UmbracoControllerTypeCollection(actionDescriptors.Object));

            Assert.Equal("Umbraco", result.ControllerName);
            Assert.Equal("Index", result.ActionName);
        }
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:23,代码来源:UmbracoRouterTests.cs

示例2: GetUmbracoRouteValues_Find_Custom_Controller

        public void GetUmbracoRouteValues_Find_Custom_Controller()
        {
            var router = new UmbracoRouter(Mock.Of<IRouter>());
            var httpCtxAccessor = new Mock<IHttpContextAccessor>();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(context => context.Request).Returns(Mock.Of<HttpRequest>());
            httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
            var umbCtx = new UmbracoContext(httpCtxAccessor.Object);
            var urlProvider = new UrlProvider(umbCtx, Enumerable.Empty<IUrlProvider>());
            var routingCtx = new RoutingContext(Enumerable.Empty<IContentFinder>(), Mock.Of<ILastChanceContentFinder>(), urlProvider);
            var templateService = new Mock<ITemplateService>();
            templateService.Setup(service => service.GetTemplate("Hello")).Returns(Mock.Of<ITemplate>(template => template.Alias == "Hello"));
            var pcr = new PublishedContentRequest(routingCtx, templateService.Object, Mock.Of<ILoggerFactory>(), httpCtxAccessor.Object)
            {
                PublishedContent = new PublishedContent()
                {
                    ContentType = "Custom"
                }
            };
            pcr.TrySetTemplate("Hello");
            umbCtx.Initialize(pcr);
            var actionDescriptors = new Mock<IActionDescriptorsCollectionProvider>();
            actionDescriptors.Setup(provider => provider.ActionDescriptors).Returns(new ActionDescriptorsCollection(
                new List<ActionDescriptor>()
                {
                    new ControllerActionDescriptor()
                    {
                        Name = "Hello",
                        ControllerName = "Custom",
                        ControllerTypeInfo = typeof(UmbracoController).GetTypeInfo()
                    }
                }, 0));

            var result = router.GetUmbracoRouteValues(umbCtx, new UmbracoControllerTypeCollection(actionDescriptors.Object));

            Assert.Equal("Custom", result.ControllerName);
            Assert.Equal("Hello", result.ActionName);
        }
开发者ID:vnbaaij,项目名称:Umbraco9,代码行数:38,代码来源:UmbracoRouterTests.cs


注:本文中的Umbraco.Web.UmbracoContext.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。