本文整理匯總了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);
}
示例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);
}